-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApplication.java
79 lines (66 loc) · 2.28 KB
/
Application.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package software.xdev;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testcontainers.lifecycle.TestDescription;
import software.xdev.testcontainers.selenium.containers.browser.BrowserWebDriverContainer;
import software.xdev.testcontainers.selenium.containers.browser.CapabilitiesBrowserWebDriverContainer;
public final class Application
{
@SuppressWarnings("resource") // It's getting closed...
public static void main(final String[] args)
{
final Path recordingDir = Path.of("target/records");
// noinspection ResultOfMethodCallIgnored
recordingDir.toFile().mkdirs();
for(final Capabilities capabilities : List.of(new ChromeOptions(), new FirefoxOptions()))
{
try(final var browserContainer = new CapabilitiesBrowserWebDriverContainer<>(capabilities)
.withRecordingMode(BrowserWebDriverContainer.RecordingMode.RECORD_ALL)
.withRecordingDirectory(recordingDir))
{
browserContainer.start();
final RemoteWebDriver remoteWebDriver =
new RemoteWebDriver(browserContainer.getSeleniumAddressURI().toURL(), capabilities, false);
remoteWebDriver.manage().window().maximize();
remoteWebDriver.get(capabilities instanceof FirefoxOptions ? "about:support" : "chrome://version");
Thread.sleep(1000); // Simulate Test work
remoteWebDriver.findElements(By.tagName("body"));
remoteWebDriver.quit();
// Wait a moment until everything is safe on tape
Thread.sleep(100);
browserContainer.afterTest(new TestDescription()
{
@Override
public String getTestId()
{
return "demo-" + capabilities.getBrowserName();
}
@Override
public String getFilesystemFriendlyName()
{
return "demo-" + capabilities.getBrowserName();
}
}, Optional.empty());
}
catch(final InterruptedException ite)
{
Thread.currentThread().interrupt();
}
catch(final IOException ioe)
{
throw new UncheckedIOException(ioe);
}
}
}
private Application()
{
}
}