-
Notifications
You must be signed in to change notification settings - Fork 123
/
RemoteWebDriverBuilderTest.java
57 lines (48 loc) · 2.3 KB
/
RemoteWebDriverBuilderTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.saucedemo.selenium.se4newfeatures;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.HasFullPageScreenshot;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.http.ClientConfig;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
public class RemoteWebDriverBuilderTest {
/**
* RemoteWebDriver builder gives you a few great things off the bat:
* 1. Allows you to easily set Connection and Read Timeouts
* 2. Automatically applies augmentation for casting to valid interfaces
* 3. Keeps Browser Options and Sauce Options separate
* 4. Address values are Strings not URL, which is just easier
*/
@DisplayName("Use RemoteWebDriverBuilder class")
@Test
public void webDriverBuilder(TestInfo testInfo) {
FirefoxOptions browserOptions = new FirefoxOptions();
browserOptions.setPlatformName("Windows 10");
browserOptions.setBrowserVersion("latest");
browserOptions.setAcceptInsecureCerts(true);
browserOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.IGNORE);
Map<String, Object> sauceOptions = new HashMap<>();
sauceOptions.put("name", testInfo.getDisplayName());
sauceOptions.put("build", System.getenv("BUILD_NAME") + ": " + System.getenv("BUILD_NUMBER"));
sauceOptions.put("username", System.getenv("SAUCE_USERNAME"));
sauceOptions.put("accessKey", System.getenv("SAUCE_ACCESS_KEY"));
ClientConfig config = ClientConfig.defaultConfig()
.connectionTimeout(Duration.ofMinutes(5))
.readTimeout(Duration.ofMinutes(3));
WebDriver driver = RemoteWebDriver.builder()
.oneOf(browserOptions)
.setCapability("sauce:options", sauceOptions)
.address("https://ondemand.us-west-1.saucelabs.com/wd/hub")
.config(config)
.build();
((HasFullPageScreenshot) driver).getFullPageScreenshotAs(OutputType.FILE);
driver.quit();
}
}