Skip to content

Commit

Permalink
Fixed Saucelabs and Lambdatest plugins to work correctly with W3C opt…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
wakaleo committed Dec 22, 2023
1 parent 045d971 commit ea11906
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 57 deletions.
8 changes: 0 additions & 8 deletions .circleci/config.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ public MutableCapabilities apply(EnvironmentVariables environmentVariables,
newOptions.put("name", testName);
newOptions.put("build", BuildName.from(environmentVariables));

capabilities.setCapability("name", testName);
capabilities.setCapability("build", BuildName.from(environmentVariables));
capabilities.setCapability("projectName", SERENITY_PROJECT_NAME.from(environmentVariables,"Serenity BDD Test Suite"));

// Add tags
newOptions.put("tags", CapabilityTags.tagsFrom(testOutcome, environmentVariables));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,57 +25,46 @@ public class AfterASauceLabsScenario implements AfterAWebdriverScenario {

@Override
public void apply(EnvironmentVariables environmentVariables, TestOutcome testOutcome, WebDriver driver) {
if ((driver == null) || !RemoteDriver.isARemoteDriver(driver)) {
return;
}
if (!SauceLabsConfiguration.isActiveFor(environmentVariables)) {
return;
}

String sessionId = null;
if (RemoteDriver.of(driver).getSessionId() != null) {
sessionId = RemoteDriver.of(driver).getSessionId().toString();
}
String userName = SauceLabsCredentials.from(environmentVariables).getUser();
String key = SauceLabsCredentials.from(environmentVariables).getAccessKey();

if (userName == null || key == null) {
LOGGER.warn("Incomplete SauceLabs configuration" + System.lineSeparator()
+ "SauceLabs integration needs the following system properties to work:" + System.lineSeparator()
+ " - saucelabs.username - Your SauceLabs account name" + System.lineSeparator()
+ " - saucelabs.accessKey - Your SauceLabs Access Key" + System.lineSeparator()
+ "You can find both of these here: https://app.saucelabs.com/user-settings"
);
} else {
// ((JavascriptExecutor) driver).executeScript("sauce:job-build=" + BuildName.from(environmentVariables));
// ((JavascriptExecutor)driver).executeScript("sauce:job-tags=" + CapabilityTags.tagsFrom(testOutcome, environmentVariables));
//
// String result = (testOutcome.isSuccess()) ? "passed" : "failed";
// ((JavascriptExecutor)driver).executeScript("sauce:job-result=" + result);
if (SauceLabsConfiguration.isDriverEnabled(driver) && this.isActivated(environmentVariables)) {
String sessionId = null;
if (RemoteDriver.of(driver).getSessionId() != null) {
sessionId = RemoteDriver.of(driver).getSessionId().toString();
}
String userName = SauceLabsCredentials.from(environmentVariables).getUser();
String key = SauceLabsCredentials.from(environmentVariables).getAccessKey();

SauceLabsTestSession sauceLabsTestSession = new SauceLabsTestSession(userName, key, sessionId);
if (userName == null || key == null) {
LOGGER.warn("Incomplete SauceLabs configuration" + System.lineSeparator()
+ "SauceLabs integration needs the following system properties to work:" + System.lineSeparator()
+ " - saucelabs.username - Your SauceLabs account name" + System.lineSeparator()
+ " - saucelabs.accessKey - Your SauceLabs Access Key" + System.lineSeparator()
+ "You can find both of these here: https://app.saucelabs.com/user-settings"
);
} else {
SauceLabsTestSession sauceLabsTestSession = new SauceLabsTestSession(userName, key, sessionId);

String publicUrl = sauceLabsTestSession.getTestLink();
testOutcome.setLink(new ExternalLink(publicUrl, "SauceLabs"));
String publicUrl = sauceLabsTestSession.getTestLink();
testOutcome.setLink(new ExternalLink(publicUrl, "SauceLabs"));

String result = (testOutcome.isSuccess()) ? "passed" : "failed";
String tags = Arrays.toString(CapabilityTags.tagsFrom(testOutcome, environmentVariables));
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
String jobUrl = "https://saucelabs.com/rest/v1/" + userName + "/jobs/" + sessionId;
HttpPut putRequest = new HttpPut(jobUrl);
putRequest.setHeader("Content-Type", "application/json");
putRequest.setHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString((userName + ":" + key).getBytes()));
String result = (testOutcome.isSuccess()) ? "passed" : "failed";
String tags = Arrays.toString(CapabilityTags.tagsFrom(testOutcome, environmentVariables));
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
String jobUrl = "https://saucelabs.com/rest/v1/" + userName + "/jobs/" + sessionId;
HttpPut putRequest = new HttpPut(jobUrl);
putRequest.setHeader("Content-Type", "application/json");
putRequest.setHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString((userName + ":" + key).getBytes()));

JsonObject json = new JsonObject();
json.addProperty("build", BuildName.from(environmentVariables));
json.addProperty("tags", tags);
json.addProperty("passed", result.equals("passed"));
JsonObject json = new JsonObject();
json.addProperty("build", BuildName.from(environmentVariables));
json.addProperty("tags", tags);
json.addProperty("passed", result.equals("passed"));

putRequest.setEntity(new StringEntity(json.toString()));
putRequest.setEntity(new StringEntity(json.toString()));

httpClient.execute(putRequest);
} catch (Exception e) {
// Handle exception
httpClient.execute(putRequest);
} catch (Exception e) {
// Handle exception
}
}
}
}
Expand Down

0 comments on commit ea11906

Please sign in to comment.