-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathExampleTest.java
62 lines (51 loc) · 1.94 KB
/
ExampleTest.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
58
59
60
61
62
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.io.File;
import static java.util.concurrent.TimeUnit.SECONDS;
import static junit.framework.TestCase.assertEquals;
public class ExampleTest {
private WebDriver webDriver;
private SeleniumSslProxy proxy;
@Before
public void setup() {
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
File clientSslCertificate = new File(classLoader.getResource("certificates/some-certificate.pfx").getFile());
String certificatePassword = "superSecret";
this.proxy = new SeleniumSslProxy(clientSslCertificate, certificatePassword);
this.proxy.start();
this.webDriver = setupChromeDriver(this.proxy, false);
}
@Test
public void pageTitleIsFoo() {
// given
String url = "http://myurl.lol"; // NOTE: do not use https here!
// when
this.webDriver.get(url);
this.webDriver.manage().timeouts().implicitlyWait(5, SECONDS);
// then
WebElement title = this.webDriver.findElement(By.className("title"));
assertEquals("Foo", title.getText());
}
@After
public void teardown() {
this.webDriver.quit();
this.proxy.stop();
}
private WebDriver setupChromeDriver(Proxy proxy, boolean headless) {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("useAutomationExtension", false); // to prevent error popup
chromeOptions.addArguments("start-maximized");
chromeOptions.setHeadless(headless);
if (proxy != null) {
chromeOptions.setProxy(proxy);
}
return new ChromeDriver(chromeOptions);
}
}