-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"; | ||
|
||
/** | ||
|
@@ -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) { | ||
throw new AutomateException("Session logs not found", 404); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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>(); | ||
|
||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
throw new AutomateException("Session logs not found", 404); | ||
} | ||
|
||
return ((AutomateClient) getClient()).getSessionHARLogs(this); | ||
} | ||
|
||
public final String getAppiumLogs() throws AutomateException { | ||
if (logUrl == null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
*/ | ||
|
@@ -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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -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; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
There was a problem hiding this comment.
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.