Skip to content

Commit

Permalink
use defaultSauceOptions method to make more obvious what is being used
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Nov 14, 2023
1 parent 965765f commit c4f4aff
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,10 @@ public void startFirefoxSession(TestInfo testInfo) {
}

public void startSession(TestInfo testInfo, Capabilities options) {
startSession(testInfo, options, new HashMap<>());
startSession(options, defaultSauceOptions(testInfo));
}

protected void startSession(
TestInfo testInfo, Capabilities options, Map<String, Object> sauceOptions) {
this.testInfo = testInfo;

sauceOptions.put("username", System.getenv("SAUCE_USERNAME"));
sauceOptions.put("accessKey", System.getenv("SAUCE_ACCESS_KEY"));
sauceOptions.put("name", testInfo.getDisplayName());
sauceOptions.put("build", System.getProperty("build.name"));
sauceOptions.put("seleniumVersion", "4.15.0");
sauceOptions.put("screeenResolution", "1920x1200");
protected void startSession(Capabilities options, Map<String, Object> sauceOptions) {
((MutableCapabilities) options).setCapability("sauce:options", sauceOptions);
if (options.getPlatformName() == null) {
((AbstractDriverOptions<AbstractDriverOptions>) options).setPlatformName("Windows 11");
Expand All @@ -70,6 +61,18 @@ protected void startSession(
this.id = ((RemoteWebDriver) driver).getSessionId();
}

protected Map<String, Object> defaultSauceOptions(TestInfo testInfo) {
this.testInfo = testInfo;

Map<String, Object> options = new HashMap<>();
options.put("username", System.getenv("SAUCE_USERNAME"));
options.put("accessKey", System.getenv("SAUCE_ACCESS_KEY"));
options.put("name", testInfo.getDisplayName());
options.put("build", System.getProperty("build.name"));
options.put("seleniumVersion", "4.15.0");
return options;
}

public class SauceTestWatcher implements TestWatcher {
@Override
public void testSuccessful(ExtensionContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public void setup(TestInfo testInfo) {
options.setPlatformName("Windows 10");
options.setBrowserVersion("117");

Map<String, Object> sauceOptions = new HashMap<>();
Map<String, Object> sauceOptions = defaultSauceOptions(testInfo);
sauceOptions.put("capturePerformance", true);
sauceOptions.put("extendedDebugging", true);

startSession(testInfo, options, sauceOptions);
startSession(options, sauceOptions);
}

@DisplayName("Ensure all metrics within historical limits")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ public class DevToolsTest extends TestBase {

@BeforeEach
public void setup(TestInfo testInfo) {
Map<String, Object> sauceOptions = new HashMap<>();
Map<String, Object> sauceOptions = defaultSauceOptions(testInfo);
sauceOptions.put("devtools", true);
startSession(testInfo, new ChromeOptions(), sauceOptions);
startSession(new ChromeOptions(), sauceOptions);

wait = new WebDriverWait(driver, Duration.ofSeconds(10));
driver = new Augmenter().augment(driver);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
import org.junit.jupiter.api.TestInfo;
import org.openqa.selenium.ie.InternetExplorerOptions;

import java.util.Map;

public class EdgeIE extends TestBase {
@BeforeEach
public void createSauceOptions(TestInfo testInfo) {
@BeforeEach
public void createSauceOptions(TestInfo testInfo) {
InternetExplorerOptions options = new InternetExplorerOptions();
options.attachToEdgeChrome();
options.setCapability("browserName", "microsoftedge");
startSession(testInfo, options);
}
Map<String, Object> sauceOptions = defaultSauceOptions(testInfo);

startSession(options, sauceOptions);
}

@Test
public void ieMode() {
driver.get("https://www.saucedemo.com");
}
@Test
public void ieMode() {
driver.get("https://www.saucedemo.com");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
import org.openqa.selenium.firefox.HasContext;
import org.openqa.selenium.remote.Augmenter;

import java.util.Map;

public class FirefoxContextTest extends TestBase {

@BeforeEach
public void setup(TestInfo testInfo) {
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.addPreference("intl.accept_languages", "de-DE");
startSession(testInfo, firefoxOptions);
Map<String, Object> sauceOptions = defaultSauceOptions(testInfo);

startSession(firefoxOptions, sauceOptions);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.saucedemo.selenium.TestBase;
import java.util.Collections;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -17,8 +18,9 @@ public void createSauceOptions(TestInfo testInfo) {
EdgeOptions options = new EdgeOptions();
options.setExperimentalOption(
"excludeSwitches", Collections.singletonList("disable-popup-blocking"));
Map<String, Object> sauceOptions = defaultSauceOptions(testInfo);

startSession(testInfo, options);
startSession(options, sauceOptions);
}

@Test
Expand Down

0 comments on commit c4f4aff

Please sign in to comment.