Skip to content

Commit c11639b

Browse files
committed
Init code
1 parent bf2cd58 commit c11639b

File tree

9 files changed

+1225
-1
lines changed

9 files changed

+1225
-1
lines changed

testcontainers-java-selenium-demo/pom.xml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,57 @@
2424
<mainClass>software.xdev.Application</mainClass>
2525
</properties>
2626

27+
<dependencyManagement>
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.seleniumhq.selenium</groupId>
31+
<artifactId>selenium-dependencies-bom</artifactId>
32+
<version>4.19.1</version>
33+
<type>pom</type>
34+
<scope>import</scope>
35+
</dependency>
36+
</dependencies>
37+
</dependencyManagement>
38+
2739
<dependencies>
2840
<dependency>
2941
<groupId>software.xdev</groupId>
3042
<artifactId>testcontainers-java-selenium</artifactId>
3143
<version>${project.version}</version>
3244
</dependency>
45+
46+
<dependency>
47+
<groupId>org.slf4j</groupId>
48+
<artifactId>slf4j-simple</artifactId>
49+
<version>2.0.13</version>
50+
</dependency>
51+
52+
<dependency>
53+
<groupId>org.seleniumhq.selenium</groupId>
54+
<artifactId>selenium-remote-driver</artifactId>
55+
<!-- Tracing is not needed -->
56+
<exclusions>
57+
<exclusion>
58+
<groupId>io.opentelemetry</groupId>
59+
<artifactId>*</artifactId>
60+
</exclusion>
61+
</exclusions>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>org.seleniumhq.selenium</groupId>
66+
<artifactId>selenium-support</artifactId>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>org.seleniumhq.selenium</groupId>
71+
<artifactId>selenium-firefox-driver</artifactId>
72+
</dependency>
73+
74+
<dependency>
75+
<groupId>org.seleniumhq.selenium</groupId>
76+
<artifactId>selenium-chrome-driver</artifactId>
77+
</dependency>
3378
</dependencies>
3479

3580
<build>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package software.xdev;
2+
3+
import java.io.IOException;
4+
import java.io.UncheckedIOException;
5+
import java.nio.file.Path;
6+
import java.util.List;
7+
import java.util.Optional;
8+
9+
import org.openqa.selenium.By;
10+
import org.openqa.selenium.Capabilities;
11+
import org.openqa.selenium.chrome.ChromeOptions;
12+
import org.openqa.selenium.firefox.FirefoxOptions;
13+
import org.openqa.selenium.remote.RemoteWebDriver;
14+
import org.testcontainers.lifecycle.TestDescription;
15+
16+
import software.xdev.testcontainers.selenium.containers.browser.BrowserWebDriverContainer;
17+
import software.xdev.testcontainers.selenium.containers.browser.CapabilitiesBrowserWebDriverContainer;
18+
19+
20+
public final class Application
21+
{
22+
@SuppressWarnings("resource") // It's getting closed...
23+
public static void main(final String[] args)
24+
{
25+
final Path recordingDir = Path.of("target/records");
26+
// noinspection ResultOfMethodCallIgnored
27+
recordingDir.toFile().mkdirs();
28+
29+
for(final Capabilities capabilities : List.of(new ChromeOptions(), new FirefoxOptions()))
30+
{
31+
try(final var browserContainer = new CapabilitiesBrowserWebDriverContainer<>(capabilities)
32+
.withRecordingMode(BrowserWebDriverContainer.RecordingMode.RECORD_ALL)
33+
.withRecordingDirectory(recordingDir))
34+
{
35+
browserContainer.start();
36+
final RemoteWebDriver remoteWebDriver =
37+
new RemoteWebDriver(browserContainer.getSeleniumAddressURI().toURL(), capabilities, false);
38+
39+
remoteWebDriver.manage().window().maximize();
40+
41+
remoteWebDriver.get(capabilities instanceof FirefoxOptions ? "about:support" : "chrome://version");
42+
Thread.sleep(1000); // Simulate Test work
43+
remoteWebDriver.findElements(By.tagName("body"));
44+
45+
remoteWebDriver.quit();
46+
47+
// Wait a moment until everything is safe on tape
48+
Thread.sleep(100);
49+
50+
browserContainer.afterTest(new TestDescription()
51+
{
52+
@Override
53+
public String getTestId()
54+
{
55+
return "demo-" + capabilities.getBrowserName();
56+
}
57+
58+
@Override
59+
public String getFilesystemFriendlyName()
60+
{
61+
return "demo-" + capabilities.getBrowserName();
62+
}
63+
}, Optional.empty());
64+
}
65+
catch(final InterruptedException ite)
66+
{
67+
Thread.currentThread().interrupt();
68+
}
69+
catch(final IOException ioe)
70+
{
71+
throw new UncheckedIOException(ioe);
72+
}
73+
}
74+
}
75+
76+
private Application()
77+
{
78+
}
79+
}

testcontainers-java-selenium/pom.xml

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<connection>scm:git:https://github.com/xdev-software/testcontainers-java-selenium.git</connection>
1919
</scm>
2020

21-
<inceptionYear>2023</inceptionYear>
21+
<inceptionYear>2024</inceptionYear>
2222

2323
<organization>
2424
<name>XDEV Software</name>
@@ -47,6 +47,9 @@
4747

4848
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4949
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
50+
51+
<!-- by default run no tests as Docker is required -->
52+
<skipTests>true</skipTests>
5053
</properties>
5154

5255
<repositories>
@@ -84,6 +87,73 @@
8487
</repository>
8588
</distributionManagement>
8689

90+
<dependencies>
91+
<dependency>
92+
<groupId>org.testcontainers</groupId>
93+
<artifactId>testcontainers</artifactId>
94+
<version>1.19.7</version>
95+
</dependency>
96+
<!-- Testcontainers is using outdated v1 -->
97+
<dependency>
98+
<groupId>org.slf4j</groupId>
99+
<artifactId>slf4j-api</artifactId>
100+
<version>2.0.13</version>
101+
</dependency>
102+
103+
<!-- Selenium API is optional -->
104+
<dependency>
105+
<groupId>org.seleniumhq.selenium</groupId>
106+
<artifactId>selenium-api</artifactId>
107+
<version>4.19.1</version>
108+
<scope>provided</scope>
109+
</dependency>
110+
111+
<!-- Tests -->
112+
<dependency>
113+
<groupId>org.junit.jupiter</groupId>
114+
<artifactId>junit-jupiter</artifactId>
115+
<version>5.10.2</version>
116+
<scope>test</scope>
117+
</dependency>
118+
<dependency>
119+
<groupId>org.slf4j</groupId>
120+
<artifactId>slf4j-simple</artifactId>
121+
<version>2.0.13</version>
122+
<scope>test</scope>
123+
</dependency>
124+
<dependency>
125+
<groupId>org.seleniumhq.selenium</groupId>
126+
<artifactId>selenium-remote-driver</artifactId>
127+
<version>4.19.1</version>
128+
<scope>test</scope>
129+
<!-- Tracing is not needed -->
130+
<exclusions>
131+
<exclusion>
132+
<groupId>io.opentelemetry</groupId>
133+
<artifactId>*</artifactId>
134+
</exclusion>
135+
</exclusions>
136+
</dependency>
137+
<dependency>
138+
<groupId>org.seleniumhq.selenium</groupId>
139+
<artifactId>selenium-support</artifactId>
140+
<version>4.19.1</version>
141+
<scope>test</scope>
142+
</dependency>
143+
<dependency>
144+
<groupId>org.seleniumhq.selenium</groupId>
145+
<artifactId>selenium-firefox-driver</artifactId>
146+
<version>4.19.1</version>
147+
<scope>test</scope>
148+
</dependency>
149+
<dependency>
150+
<groupId>org.seleniumhq.selenium</groupId>
151+
<artifactId>selenium-chrome-driver</artifactId>
152+
<version>4.19.1</version>
153+
<scope>test</scope>
154+
</dependency>
155+
</dependencies>
156+
87157
<build>
88158
<pluginManagement>
89159
<plugins>
@@ -172,9 +242,24 @@
172242
</execution>
173243
</executions>
174244
</plugin>
245+
246+
<plugin>
247+
<groupId>org.apache.maven.plugins</groupId>
248+
<artifactId>maven-surefire-plugin</artifactId>
249+
<version>3.2.5</version>
250+
<configuration>
251+
<skipTests>${skipTests}</skipTests>
252+
</configuration>
253+
</plugin>
175254
</plugins>
176255
</build>
177256
<profiles>
257+
<profile>
258+
<id>run-integration-tests</id>
259+
<properties>
260+
<skipTests>false</skipTests>
261+
</properties>
262+
</profile>
178263
<profile>
179264
<id>ossrh</id>
180265
<build>

0 commit comments

Comments
 (0)