Skip to content

Commit fda0742

Browse files
committed
Test with Chrome
1 parent 3ef46ee commit fda0742

File tree

3 files changed

+32
-37
lines changed

3 files changed

+32
-37
lines changed

Jenkinsfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def axes = [
4242
jenkinsVersions: ['lts', 'latest'],
4343
platforms: ['linux'],
4444
jdks: [17, 21],
45-
browsers: ['firefox'],
45+
browsers: ['chrome'],
4646
]
4747

4848
stage('Record builds and sessions') {
@@ -55,7 +55,7 @@ stage('Record builds and sessions') {
5555
}
5656
axes['jenkinsVersions'].each { jenkinsVersion ->
5757
infra.withArtifactCachingProxy {
58-
sh "rm -rf target && DISPLAY=:0 ./src/main/resources/ath-container/run.sh firefox ${jenkinsVersion} -Dmaven.repo.local=${WORKSPACE_TMP}/m2repo -B clean process-test-resources"
58+
sh "rm -rf target && DISPLAY=:0 ./src/main/resources/ath-container/run.sh chrome ${jenkinsVersion} -Dmaven.repo.local=${WORKSPACE_TMP}/m2repo -B clean process-test-resources"
5959
}
6060
def coreCommit = sh(script: './core-commit.sh', returnStdout: true).trim()
6161
/*

docker-compose.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ services:
66
sh -c "mkdir -p /tmp/videos && chmod 0777 /tmp/videos"
77
volumes:
88
- shared_tmp:/tmp
9-
firefox:
10-
container_name: firefox
9+
chrome:
10+
container_name: chrome
1111
environment:
1212
- SE_JAVA_OPTS=-Xmx256m -XX:+HeapDumpOnOutOfMemoryError -XX:+TieredCompilation -XX:TieredStopAtLevel=1
13-
- SE_NODE_GRID_URL=http://firefox:4444 # Selenium needs to know where to advertise itself (e.g. BiDi)
13+
- SE_NODE_GRID_URL=http://chrome:4444 # Selenium needs to know where to advertise itself (e.g. BiDi)
1414
- SE_SCREEN_HEIGHT=1090
1515
- SE_SCREEN_WIDTH=1680
1616
extra_hosts:
1717
- host.docker.internal:host-gateway
18-
image: selenium/standalone-firefox:4.32.0@sha256:47d0b132a1ec4b976756349885a31bd484b4a40f9dd7839da270823d31d6cdcb
18+
image: selenium/standalone-chrome:4.32.0@sha256:c15582eeaf5158ca377cfad5dd286fb8e7a418a6309bdfc8a0bbda866b4dd465
1919
networks:
2020
- ath-network
2121
ports:
@@ -27,11 +27,11 @@ services:
2727
video:
2828
container_name: video
2929
depends_on:
30-
- firefox
30+
- chrome
3131
- init_video
3232
environment:
33-
- DISPLAY_CONTAINER_NAME=firefox
34-
- SE_NODE_GRID_URL=http://firefox:4444
33+
- DISPLAY_CONTAINER_NAME=chrome
34+
- SE_NODE_GRID_URL=http://chrome:4444
3535
- SE_NODE_PORT=4444
3636
- SE_VIDEO_FILE_NAME=auto
3737
- SE_VIDEO_FILE_NAME_SUFFIX=false
@@ -50,13 +50,13 @@ services:
5050
- jenkins/ath:latest
5151
container_name: mvn
5252
depends_on:
53-
- firefox
53+
- chrome
5454
- video
5555
environment:
56-
- DISPLAY=firefox:99.0
56+
- DISPLAY=chrome:99.0
5757
- DOCKER_FIXTURES_NETWORK=ath-network
5858
- JENKINS_LOCAL_HOSTNAME=mvn
59-
- REMOTE_WEBDRIVER_URL=http://firefox:4444/wd/hub
59+
- REMOTE_WEBDRIVER_URL=http://chrome:4444/wd/hub
6060
- SELENIUM_PROXY_HOSTNAME=mvn
6161
- SHARED_DOCKER_SERVICE=true
6262
- TESTCONTAINERS_HOST_OVERRIDE=host.docker.internal

src/main/java/org/jenkinsci/test/acceptance/FallbackConfig.java

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@
1212
import java.io.File;
1313
import java.io.IOException;
1414
import java.net.InetAddress;
15-
import java.net.MalformedURLException;
16-
import java.net.URL;
1715
import java.net.UnknownHostException;
1816
import java.nio.file.Files;
1917
import java.nio.file.Path;
2018
import java.nio.file.Paths;
2119
import java.nio.file.StandardCopyOption;
2220
import java.time.Duration;
23-
import java.util.HashMap;
2421
import java.util.Locale;
2522
import java.util.Map;
2623
import java.util.logging.Logger;
@@ -66,7 +63,6 @@
6663
import org.openqa.selenium.firefox.FirefoxDriver;
6764
import org.openqa.selenium.firefox.FirefoxOptions;
6865
import org.openqa.selenium.firefox.GeckoDriverService;
69-
import org.openqa.selenium.remote.Augmenter;
7066
import org.openqa.selenium.remote.CapabilityType;
7167
import org.openqa.selenium.remote.LocalFileDetector;
7268
import org.openqa.selenium.remote.RemoteWebDriver;
@@ -116,19 +112,10 @@ private WebDriver createWebDriver(TestCleaner cleaner, TestName testName) throws
116112
return createContainerWebDriver(
117113
cleaner, "selenium/standalone-firefox:4.32.0", buildFirefoxOptions(testName));
118114
case "chrome-container":
119-
return createContainerWebDriver(cleaner, "selenium/standalone-chrome:4.32.0", new ChromeOptions());
115+
return createContainerWebDriver(
116+
cleaner, "selenium/standalone-chrome:4.32.0", buildChromeOptions(testName));
120117
case "chrome":
121-
Map<String, String> prefs = new HashMap<>();
122-
prefs.put(LANGUAGE_SELECTOR, "en");
123-
ChromeOptions options = new ChromeOptions();
124-
options.setExperimentalOption("prefs", prefs);
125-
if (HarRecorder.isCaptureHarEnabled()) {
126-
options.setAcceptInsecureCerts(true);
127-
options.setProxy(createSeleniumProxy(testName.get()));
128-
}
129-
130-
setDriverPropertyIfMissing("chromedriver", ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY);
131-
return new ChromeDriver(options);
118+
return new ChromeDriver(buildChromeOptions(testName));
132119
case "safari":
133120
return new SafariDriver();
134121
case "saucelabs":
@@ -157,16 +144,16 @@ private WebDriver createWebDriver(TestCleaner cleaner, TestName testName) throws
157144
}
158145
}
159146

160-
private WebDriver buildRemoteWebDriver(Capabilities options) throws MalformedURLException {
147+
private WebDriver buildRemoteWebDriver(Capabilities options) {
161148
String u = System.getenv("REMOTE_WEBDRIVER_URL");
162149
if (StringUtils.isBlank(u)) {
163150
throw new Error("remote-webdriver type browsers require REMOTE_WEBDRIVER_URL to be set");
164151
}
165-
RemoteWebDriver driver = new RemoteWebDriver(
166-
new URL(u), // http://192.168.99.100:4444/wd/hub
167-
options);
168-
driver.setFileDetector(new LocalFileDetector());
169-
return new Augmenter().augment(driver);
152+
// http://192.168.99.100:4444/wd/hub
153+
WebDriver driver =
154+
RemoteWebDriver.builder().address(u).addAlternative(options).build();
155+
((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());
156+
return driver;
170157
}
171158

172159
private String getBrowser() {
@@ -202,9 +189,15 @@ private FirefoxOptions buildFirefoxOptions(TestName testName) throws IOException
202189

203190
private ChromeOptions buildChromeOptions(TestName testName) throws IOException {
204191
ChromeOptions chromeOptions = new ChromeOptions();
192+
chromeOptions.setExperimentalOption("prefs", Map.of(LANGUAGE_SELECTOR, "en"));
193+
chromeOptions.enableBiDi();
205194
if (HarRecorder.isCaptureHarEnabled()) {
206195
chromeOptions.setProxy(createSeleniumProxy(testName.get()));
207196
}
197+
setDriverPropertyIfMissing("chromedriver", ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY);
198+
chromeOptions.setCapability("se:name", testName.get());
199+
chromeOptions.setCapability(
200+
"se:recordVideo", TestRecorderRule.isRecorderEnabled() && System.getenv("VIDEO_FOLDER") != null);
208201
return chromeOptions;
209202
}
210203

@@ -266,10 +259,12 @@ public String toString() {
266259
Thread.sleep(3000); // Give the container and selenium some time to spawn
267260

268261
try {
269-
RemoteWebDriver remoteWebDriver =
270-
new RemoteWebDriver(new URL("http://127.0.0.1:" + controlPort + "/wd/hub"), capabilities);
262+
WebDriver driver = RemoteWebDriver.builder()
263+
.address("http://127.0.0.1:" + controlPort + "/wd/hub")
264+
.addAlternative(capabilities)
265+
.build();
271266
cleaner.addTask(cleanContainer);
272-
return new Augmenter().augment(remoteWebDriver);
267+
return driver;
273268
} catch (RuntimeException e) {
274269
cleanContainer.close();
275270
throw e;

0 commit comments

Comments
 (0)