Skip to content

Added new attributes for automation_session object and updated endpoint #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/main/java/com/browserstack/automate/Automate.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ Session updateSessionStatus(String sessionId,

String getSessionVideo(String sessionId) throws SessionNotFound, AutomateException;

String getSessionConsoleLogs(String sessionId) throws SessionNotFound, AutomateException;

String getSessionConsoleLogs(Session session) throws AutomateException;

String getSessionHARLogs(String sessionId) throws SessionNotFound, AutomateException;

String getSessionHARLogs(Session session) throws AutomateException;

String getSessionAppiumLogs(String sessionId) throws SessionNotFound, AutomateException;

String getSessionAppiumLogs(Session session) throws AutomateException;

boolean deleteSession(String sessionId) throws SessionNotFound, AutomateException;

String recycleKey() throws AutomateException;
Expand Down
113 changes: 112 additions & 1 deletion src/main/java/com/browserstack/automate/AutomateClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
public final class AutomateClient extends BrowserStackClient implements Automate {

private static final String BASE_URL = "https://www.browserstack.com/automate";
private static final String BASE_URL = "https://api.browserstack.com/automate";
private static final String CACHE_KEY_BROWSERS = "browsers";

/**
Expand Down Expand Up @@ -434,6 +434,117 @@ public final String getSessionVideo(final String sessionId)
return getSession(sessionId).getVideoUrl();
}

/**
* Fetches the console logs for a session.
*
* @param sessionId ID that uniquely identifies a session.
* @return Console logs for the session.
* @throws SessionNotFound
* @throws AutomateException
*/
public final String getSessionConsoleLogs(final String sessionId) throws SessionNotFound, AutomateException {
return getSessionConsoleLogs(getSession(sessionId));
}

/**
* Fetches the console logs for a session.
*
* @param session {@link Session} for which to retrieve logs.
* @return Console logs for the session.
* @throws AutomateException
*/
public final String getSessionConsoleLogs(final Session session) throws AutomateException {
if (session == null) {
throw new AutomateException("Invalid session", 400);
}

if (session.getBrowser_console_logs_url() == null) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also check whether it is a zero length string or not.

throw new AutomateException("Session logs not found", 404);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error message should be "Session console logs not found."

}

try {
BrowserStackRequest request = newRequest(Method.GET, session.getBrowser_console_logs_url(), false);
request.getHttpRequest().getHeaders().setAccept("*/*");
return request.asString();
} catch (BrowserStackException e) {
throw new AutomateException(e);
}
}

/**
* Fetches the HAR logs for a session.
*
* @param sessionId ID that uniquely identifies a session.
* @return HAR logs for the session.
* @throws SessionNotFound
* @throws AutomateException
*/
public final String getSessionHARLogs(final String sessionId) throws SessionNotFound, AutomateException {
return getSessionHARLogs(getSession(sessionId));
}

/**
* Fetches the HAR logs for a session.
*
* @param session {@link Session} for which to retrieve logs.
* @return HAR logs for the session.
* @throws AutomateException
*/
public final String getSessionHARLogs(final Session session) throws AutomateException {
if (session == null) {
throw new AutomateException("Invalid session", 400);
}

if (session.getHar_logs_url() == null) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add check for zero length string too.
Also this check is not needed, since you are doing it already in Session.java

throw new AutomateException("Session logs not found", 404);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error message should be "Session HAR logs not found."

}

try {
BrowserStackRequest request = newRequest(Method.GET, session.getHar_logs_url(), false);
request.getHttpRequest().getHeaders().setAccept("*/*");
return request.asString();
} catch (BrowserStackException e) {
throw new AutomateException(e);
}
}

/**
* Fetches the Appium logs for a session.
*
* @param sessionId ID that uniquely identifies a session.
* @return Appium logs for the session.
* @throws SessionNotFound
* @throws AutomateException
*/
public final String getSessionAppiumLogs(final String sessionId) throws SessionNotFound, AutomateException {
return getSessionAppiumLogs(getSession(sessionId));
}

/**
* Fetches the Appium logs for a session.
*
* @param session {@link Session} for which to retrieve logs.
* @return Appium logs for the session.
* @throws AutomateException
*/
public final String getSessionAppiumLogs(final Session session) throws AutomateException {
if (session == null) {
throw new AutomateException("Invalid session", 400);
}

if (session.getAppium_logs_url() == null) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add check for zero length string too.

throw new AutomateException("Session logs not found", 404);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error message should be "Session appium logs not found."

}

try {
BrowserStackRequest request = newRequest(Method.GET, session.getAppium_logs_url(), false);
request.getHttpRequest().getHeaders().setAccept("*/*");
return request.asString();
} catch (BrowserStackException e) {
throw new AutomateException(e);
}
}

/**
* Deletes the session identified by the supplied identifier.
*
Expand Down
84 changes: 84 additions & 0 deletions src/main/java/com/browserstack/automate/model/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ public class Session extends BrowserStackObject {
@JsonProperty("name")
private String name;

@JsonProperty("browser_console_logs_url")
private String browser_console_logs_url;

@JsonProperty("har_logs_url")
private String har_logs_url;

@JsonProperty("appium_logs_url")
private String appium_logs_url;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variables name should be in camel case.


@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();

Expand Down Expand Up @@ -100,6 +109,30 @@ public final String getLogs() throws AutomateException {
return ((AutomateClient) getClient()).getSessionLogs(this);
}

public final String getConsoleLogs() throws AutomateException {
if (browser_console_logs_url == null) {
throw new AutomateException("Session logs not found", 404);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change error message in accordance to method name and also check for zero length string.

}

return ((AutomateClient) getClient()).getSessionConsoleLogs(this);
}

public final String getHARLogs() throws AutomateException {
if (logUrl == null) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Check should be on harLogs variable.

throw new AutomateException("Session logs not found", 404);
}

return ((AutomateClient) getClient()).getSessionHARLogs(this);
}

public final String getAppiumLogs() throws AutomateException {
if (logUrl == null) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variable name is not correct and zero length string check needs to be performed also here,

throw new AutomateException("Session logs not found", 404);
}

return ((AutomateClient) getClient()).getSessionAppiumLogs(this);
}

/**
* @return The id
*/
Expand Down Expand Up @@ -356,6 +389,54 @@ private void setOs(String os) {
this.os = os;
}

/**
* @return The browser_console_logs_url
*/
@JsonProperty("browser_console_logs_url")
public String getBrowser_console_logs_url() {
Copy link

@raghuhit raghuhit Aug 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use camel case only in all function names.

return browser_console_logs_url;
}

/**
* @param browser_console_logs_url The browser_console_logs_url
*/
@JsonProperty("browser_console_logs_url")
private void setBrowser_console_logs_url(String browser_console_logs_url) {
this.browser_console_logs_url = browser_console_logs_url;
}

/**
* @return The har_logs_url
*/
@JsonProperty("har_logs_url")
public String getHar_logs_url() {
return har_logs_url;
}

/**
* @param har_logs_url The har_logs_url
*/
@JsonProperty("har_logs_url")
private void setHar_logs_url(String har_logs_url) {
this.har_logs_url = har_logs_url;
}

/**
* @return The appium_logs_url
*/
@JsonProperty("appium_logs_url")
public String getAppium_logs_url() {
return appium_logs_url;
}

/**
* @param appium_logs_url The appium_logs_url
*/
@JsonProperty("appium_logs_url")
private void setAppium_logs_url(String appium_logs_url) {
this.appium_logs_url = appium_logs_url;
}

@JsonAnyGetter
protected Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
Expand All @@ -381,6 +462,9 @@ private boolean copyFrom(Session s) {
setLogUrl(s.getLogUrl());
setStatus(s.getStatus());
setReason(s.getReason());
setBrowser_console_logs_url(s.getBrowser_console_logs_url());
setHar_logs_url(s.getHar_logs_url());
setAppium_logs_url(s.getAppium_logs_url());
this.additionalProperties = s.getAdditionalProperties();
return true;
}
Expand Down
66 changes: 66 additions & 0 deletions src/test/java/com/browserstack/automate/AutomateClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,72 @@ public void testGetSessionVideo() {
}
}

@Test
public void testGetSessionConsoleLogs() {
// TODO: Verify if logs are non-empty
// Cannot currently be tested during in-progress sessions
try {
String buildId = automateClient.getBuilds().get(0).getId();
List<Session> sessions = automateClient.getSessions(buildId);

String logs = sessions.get(0).getConsoleLogs();
assertTrue("Session Console Logs", logs != null);

logs = automateClient.getSessionConsoleLogs(sessions.get(0).getId());
assertTrue("Session Console Logs", logs != null);
} catch (BuildNotFound e) {
assertTrue(false);
} catch (SessionNotFound e) {
assertTrue(false);
} catch (AutomateException e) {
assertTrue(false);
}
}

@Test
public void testGetSessionHARLogs() {
// TODO: Verify if logs are non-empty
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test will fail sometimes. If the last run session haven't enabled network logs.

// Cannot currently be tested during in-progress sessions
try {
String buildId = automateClient.getBuilds().get(0).getId();
List<Session> sessions = automateClient.getSessions(buildId);

String logs = sessions.get(0).getHARLogs();
assertTrue("Session HAR Logs", logs != null);

logs = automateClient.getSessionHARLogs(sessions.get(0).getId());
assertTrue("Session HAR Logs", logs != null);
} catch (BuildNotFound e) {
assertTrue(false);
} catch (SessionNotFound e) {
assertTrue(false);
} catch (AutomateException e) {
assertTrue(false);
}
}

@Test
public void testGetSessionAppiumLogs() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test will fail in case the last session is run on desktop or appium logs capability was not passed in that.

// TODO: Verify if logs are non-empty
// Cannot currently be tested during in-progress sessions
try {
String buildId = automateClient.getBuilds().get(0).getId();
List<Session> sessions = automateClient.getSessions(buildId);

String logs = sessions.get(0).getAppiumLogs();
assertTrue("Session Appium Logs", logs != null);

logs = automateClient.getSessionAppiumLogs(sessions.get(0).getId());
assertTrue("Session Appium Logs", logs != null);
} catch (BuildNotFound e) {
assertTrue(false);
} catch (SessionNotFound e) {
assertTrue(false);
} catch (AutomateException e) {
assertTrue(false);
}
}

// @Test
public void testRecycleKey() {
try {
Expand Down