/** * Marks a Sauce Job as 'passed'. * * @param jobId the Sauce Job Id, typically equal to the Selenium/WebDriver sessionId */ public void jobPassed(String jobId) { Map<String, Object> updates = new HashMap<>(); updates.put("passed", true); updateJobInfo(jobId, updates); }
/** * @param sessionIdProvider Id provider for the current web driver session * @param username Sauce user name * @param accessKey Sauce access key * @param verboseMode Enables verbose mode */ public SauceOnDemandTestWatcher(SauceOnDemandSessionIdProvider sessionIdProvider, final String username, final String accessKey, boolean verboseMode) { this.sessionIdProvider = sessionIdProvider; sauceREST = new SauceREST(username, accessKey); this.verboseMode = verboseMode; }
private void printPublicJobLink(String sessionId) { if (verboseMode) { String authLink = this.sauceREST.getPublicJobLink(sessionId); // String authLink = "test"; System.out.println("Job link: " + authLink); } }
/** * Downloads the HAR file for a Sauce Job to the filesystem. The file will be stored in * a directory specified by the <code>location</code> field. * * This will only work for jobs which support Extended Debugging, which were * started with the 'extendedDebugging' capability set to true. * * @param jobId the Sauce Job Id, typically equal to the Selenium/WebDriver sessionId * @param location represents the base directory where the HAR file should be downloaded to */ public void downloadHAR(String jobId, String location) { URL restEndpoint = this.buildEDSURL(jobId + "/network.har"); saveFile(jobId, location, restEndpoint); }
/** * Invokes the Sauce REST API to delete a tunnel. * * @param tunnelId Identifier of the tunnel to delete */ public void deleteTunnel(String tunnelId) { HttpURLConnection connection = null; try { URL restEndpoint = this.buildURL("v1/" + username + "/tunnels/" + tunnelId); connection = openConnection(restEndpoint); connection.setRequestProperty("User-Agent", this.getUserAgent()); connection.setDoOutput(true); connection.setRequestMethod("DELETE"); addAuthenticationProperty(connection); connection.getOutputStream().write("".getBytes()); } catch (IOException e) { logger.log(Level.WARNING, "Error stopping Sauce Job", e); } closeInputStream(connection); }
@Override public void close() { if(!failed) { String sessionId = remoteWebDriver.getSessionId().toString(); Map<String, Object> updates = new HashMap<String, Object>(); updates.put("passed", true); Utils.addBuildNumberToUpdate(updates); this.sauceREST.updateJobInfo(sessionId, updates); String authLink = this.sauceREST.getPublicJobLink(sessionId); System.out.println("Job link: " + authLink); } } }
/** * Returns the result of a HTTP get to the value of the <code>restEndpoint</code> parameter, * as a BufferedInputStream suitable for consumption or saving to file. * * @param jobId the Sauce Job id * @param restEndpoint the URL to perform a HTTP GET * @throws IOException when something goes wrong fetching the data */ // TODO: Asset fetching can fail just after a test finishes. Allow for configurable retries. private BufferedInputStream downloadFileData(String jobId, URL restEndpoint) throws IOException{ logger.log(Level.FINE, "Downloading asset " + restEndpoint.toString() + " For Job " + jobId); logger.log(Level.FINEST, "Opening connection for Job " + jobId); HttpURLConnection connection = openConnection(restEndpoint); connection.setRequestProperty("User-Agent", this.getUserAgent()); connection.setDoOutput(true); connection.setRequestMethod("GET"); addAuthenticationProperty(connection); logger.log(Level.FINEST, "Obtaining input stream for request issued for Job " + jobId); InputStream stream = connection.getInputStream(); BufferedInputStream in = new BufferedInputStream(stream); return in; }
/** * Uploads a file to Sauce storage. * * @param file the file to upload * @param fileName name of the file in sauce storage * -param overwrite set to true * @return the md5 hash returned by sauce of the file * @throws IOException can be thrown when server returns an error (tcp or http status not in the 200 range) */ public String uploadFile(File file, String fileName) throws IOException { return uploadFile(file, fileName, true); }
/** * Invokes the Sauce REST API to stop a running job. * * @param jobId the Sauce Job id */ public void stopJob(String jobId) { HttpURLConnection postBack = null; try { URL restEndpoint = this.buildURL("v1/" + username + "/jobs/" + jobId + "/stop"); postBack = openConnection(restEndpoint); postBack.setRequestProperty("User-Agent", this.getUserAgent()); postBack.setDoOutput(true); postBack.setRequestMethod("PUT"); addAuthenticationProperty(postBack); postBack.getOutputStream().write("".getBytes()); } catch (IOException e) { logger.log(Level.WARNING, "Error stopping Sauce Job", e); } closeInputStream(postBack); }
/** * Invoked if the unit test either throws an error or fails. Invokes the Sauce REST API to mark the Sauce Job * as 'failed'. * * @param e not used * @param description not used */ protected void failed(Throwable e, Description description) { if (sessionIdProvider != null && sessionIdProvider.getSessionId() != null) { printSessionId(description); Map<String, Object> updates = new HashMap<String, Object>(); updates.put("passed", false); Utils.addBuildNumberToUpdate(updates); sauceREST.updateJobInfo(sessionIdProvider.getSessionId(), updates); if (verboseMode) { // get, and print to StdOut, the link to the job String authLink = sauceREST.getPublicJobLink(sessionIdProvider.getSessionId()); System.out.println("Job link: " + authLink); } } }
/** * Returns the result of a HTTP get to the value of the <code>restEndpoint</code> parameter, * as a BufferedInputStream suitable for consumption or saving to file. * * @param jobId the Sauce Job id * @param restEndpoint the URL to perform a HTTP GET * @throws IOException when something goes wrong fetching the data */ // TODO: Asset fetching can fail just after a test finishes. Allow for configurable retries. private BufferedInputStream downloadFileData(String jobId, URL restEndpoint) throws IOException{ logger.log(Level.FINE, "Downloading asset " + restEndpoint.toString() + " For Job " + jobId); logger.log(Level.FINEST, "Opening connection for Job " + jobId); HttpURLConnection connection = openConnection(restEndpoint); connection.setRequestProperty("User-Agent", this.getUserAgent()); connection.setDoOutput(true); connection.setRequestMethod("GET"); addAuthenticationProperty(connection); logger.log(Level.FINEST, "Obtaining input stream for request issued for Job " + jobId); InputStream stream = connection.getInputStream(); BufferedInputStream in = new BufferedInputStream(stream); return in; }
/** * Uploads a file to Sauce storage. * * @param file the file to upload * @param fileName name of the file in sauce storage * -param overwrite set to true * @return the md5 hash returned by sauce of the file * @throws IOException can be thrown when server returns an error (tcp or http status not in the 200 range) */ public String uploadFile(File file, String fileName) throws IOException { return uploadFile(file, fileName, true); }
/** * Downloads the HAR file for a Sauce Job to the filesystem. The file will be stored in * a directory specified by the <code>location</code> field. * * This will only work for jobs which support Extended Debugging, which were * started with the 'extendedDebugging' capability set to true. * * @param jobId the Sauce Job Id, typically equal to the Selenium/WebDriver sessionId * @param location represents the base directory where the HAR file should be downloaded to */ public void downloadHAR(String jobId, String location) { URL restEndpoint = this.buildEDSURL(jobId + "/network.har"); saveFile(jobId, location, restEndpoint); }
/** * Invokes the Sauce REST API to delete a completed job from Sauce. * * @param jobId the Sauce Job id */ public void deleteJob(String jobId) { HttpURLConnection postBack = null; try { URL restEndpoint = this.buildURL("v1/" + username + "/jobs/" + jobId); postBack = openConnection(restEndpoint); postBack.setRequestProperty("User-Agent", this.getUserAgent()); postBack.setDoOutput(true); postBack.setRequestMethod("DELETE"); addAuthenticationProperty(postBack); postBack.getOutputStream().write("".getBytes()); } catch (IOException e) { logger.log(Level.WARNING, "Error stopping Sauce Job", e); } closeInputStream(postBack); }
/** * Marks a Sauce Job as 'failed'. * * @param jobId the Sauce Job Id, typically equal to the Selenium/WebDriver sessionId */ public void jobFailed(String jobId) { Map<String, Object> updates = new HashMap<>(); updates.put("passed", false); updateJobInfo(jobId, updates); }
/** * Invoked if the unit test either throws an error or fails. Invokes the Sauce REST API to mark the Sauce Job * as 'failed'. * * @param e not used * @param description not used */ protected void failed(Throwable e, Description description) { if (sessionIdProvider != null && sessionIdProvider.getSessionId() != null) { printSessionId(description); Map<String, Object> updates = new HashMap<String, Object>(); updates.put("passed", false); Utils.addBuildNumberToUpdate(updates); sauceREST.updateJobInfo(sessionIdProvider.getSessionId(), updates); if (verboseMode) { // get, and print to StdOut, the link to the job String authLink = sauceREST.getPublicJobLink(sessionIdProvider.getSessionId()); System.out.println("Job link: " + authLink); } } }
/** * @param sessionIdProvider Id provider for the current web driver session * @param username Sauce user name * @param accessKey Sauce access key * @param verboseMode Enables verbose mode */ public SauceOnDemandTestWatcher(SauceOnDemandSessionIdProvider sessionIdProvider, final String username, final String accessKey, boolean verboseMode) { this.sessionIdProvider = sessionIdProvider; sauceREST = new SauceREST(username, accessKey); this.verboseMode = verboseMode; }
try { HttpURLConnection connection = openConnection(restEndpoint); connection.setRequestProperty("User-Agent", this.getUserAgent()); addAuthenticationProperty(connection);
public static void uploadFile(File file) throws IOException { client.uploadFile(file); }
private void printPublicJobLink(String sessionId) { if (verboseMode) { String authLink = this.sauceREST.getPublicJobLink(sessionId); // String authLink = "test"; System.out.println("Job link: " + authLink); } }