use of com.saucelabs.saucerest.SauceREST in project activityinfo by bedatadriven.
the class SauceReporter method finished.
@Override
public void finished(Scenario scenario) {
String sessionId = session.getSessionId().toString();
try {
SauceREST sauceClient = sauce.getRestClient();
Map<String, Object> updates = new HashMap<>();
updates.put("passed", !scenario.isFailed());
updates.put("name", scenario.getName());
Utils.addBuildNumberToUpdate(updates);
sauceClient.updateJobInfo(sessionId, updates);
String jobName = System.getenv("JOB_NAME");
if (jobName != null) {
scenario.write(String.format("SauceOnDemandSessionID=%s job-name=%s\n", sessionId, jobName));
}
} catch (Exception e) {
System.out.println("Failed to update sauce job status: " + e.getMessage());
}
// Add URL of Job to Cucumber output
scenario.write(String.format("<a href=\"https://saucelabs.com/tests/%s\">Sauce Job Page</a>\n", sessionId));
}
use of com.saucelabs.saucerest.SauceREST in project divolte-collector by divolte.
the class SeleniumTestBase method setupSauceLabs.
private void setupSauceLabs() throws MalformedURLException {
final String sauceUserName = Optional.ofNullable(System.getenv(SAUCE_USER_NAME_ENV_VAR)).orElseThrow(() -> new RuntimeException("When using 'sauce' as Selenium driver, please set the SauceLabs username " + "in the " + SAUCE_USER_NAME_ENV_VAR + " env var."));
final String sauceApiKey = Optional.ofNullable(System.getenv(SAUCE_API_KEY_ENV_VAR)).orElseThrow(() -> new RuntimeException("When using 'sauce' as Selenium driver, please set the SauceLabs username " + "in the " + SAUCE_API_KEY_ENV_VAR + " env var."));
final String sauceHost = Optional.ofNullable(System.getenv(SAUCE_HOST_ENV_VAR)).orElse("localhost");
final int saucePort = Optional.ofNullable(System.getenv(SAUCE_PORT_ENV_VAR)).map(Ints::tryParse).orElse(4445);
final DesiredCapabilities caps = capabilities.get();
// Note: getMethodName() is misleading. It's really the formatted name from the @Parameters annotation.
caps.setCapability("name", String.format("%s: %s", getClass().getSimpleName(), testName.getMethodName()));
caps.setCapability("public", "team");
caps.setCapability("videoUploadOnPass", false);
final RemoteWebDriver remoteDriver = new RemoteWebDriver(new URL(String.format("http://%s:%s@%s:%d/wd/hub", sauceUserName, sauceApiKey, sauceHost, saucePort)), caps);
final String sauceJobId = remoteDriver.getSessionId().toString();
final SauceREST sauce = new SauceREST(sauceUserName, sauceApiKey);
driver = remoteDriver;
testResultHook = Optional.of(result -> {
switch(result) {
case Passed:
sauce.jobPassed(sauceJobId);
break;
case Skipped:
sauce.deleteJob(sauceJobId);
break;
case Failed:
sauce.jobFailed(sauceJobId);
}
});
}
Aggregations