-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
BaseWebDriverContainerTest.java
58 lines (47 loc) · 2.11 KB
/
BaseWebDriverContainerTest.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
package org.testcontainers.junit;
import org.junit.ClassRule;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testcontainers.containers.BrowserWebDriverContainer;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
import org.testcontainers.utility.DockerImageName;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.assertThat;
/**
*
*/
public class BaseWebDriverContainerTest {
@ClassRule
public static Network NETWORK = Network.newNetwork();
@ClassRule
public static GenericContainer<?> HELLO_WORLD = new GenericContainer<>(
DockerImageName.parse("testcontainers/helloworld:1.1.0")
)
.withNetwork(NETWORK)
.withNetworkAliases("helloworld")
.withExposedPorts(8080, 8081)
.waitingFor(new HttpWaitStrategy());
protected static void doSimpleExplore(BrowserWebDriverContainer<?> rule) {
RemoteWebDriver driver = setupDriverFromRule(rule);
System.out.println("Selenium remote URL is: " + rule.getSeleniumAddress());
System.out.println("VNC URL is: " + rule.getVncAddress());
driver.get("http://helloworld:8080");
WebElement title = driver.findElement(By.tagName("h1"));
assertThat(title.getText().trim())
.as("the index page contains the title 'Hello world'")
.isEqualTo("Hello world");
}
protected void assertBrowserNameIs(BrowserWebDriverContainer<?> rule, String expectedName) {
RemoteWebDriver driver = setupDriverFromRule(rule);
String actual = driver.getCapabilities().getBrowserName();
assertThat(actual).as(String.format("actual browser name is %s", actual)).isEqualTo(expectedName);
}
private static RemoteWebDriver setupDriverFromRule(BrowserWebDriverContainer<?> rule) {
RemoteWebDriver driver = rule.getWebDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
return driver;
}
}