Skip to content

Commit f85c1de

Browse files
authored
Update examples test Chrome/Edge run on Ubuntu 24.04 hosted runners (SeleniumHQ#2139)
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent b3e0528 commit f85c1de

17 files changed

+130
-76
lines changed

examples/java/src/test/java/dev/selenium/BaseTest.java

+13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.openqa.selenium.WebElement;
1717
import org.openqa.selenium.chrome.ChromeDriver;
1818
import org.openqa.selenium.chrome.ChromeOptions;
19+
import org.openqa.selenium.edge.EdgeOptions;
1920
import org.openqa.selenium.firefox.FirefoxDriver;
2021
import org.openqa.selenium.firefox.FirefoxOptions;
2122
import org.openqa.selenium.grid.Main;
@@ -57,6 +58,18 @@ protected ChromeDriver startChromeDriver(ChromeOptions options) {
5758
return (ChromeDriver) driver;
5859
}
5960

61+
protected static ChromeOptions getDefaultChromeOptions() {
62+
ChromeOptions options = new ChromeOptions();
63+
options.addArguments("--no-sandbox");
64+
return options;
65+
}
66+
67+
protected static EdgeOptions getDefaultEdgeOptions() {
68+
EdgeOptions options = new EdgeOptions();
69+
options.addArguments("--no-sandbox");
70+
return options;
71+
}
72+
6073
protected File getTempDirectory(String prefix) {
6174
File tempDirectory = null;
6275
try {

examples/java/src/test/java/dev/selenium/bidi/cdp/CdpApiTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class CdpApiTest extends BaseTest {
2626

2727
@BeforeEach
2828
public void createSession() {
29-
ChromeOptions options = new ChromeOptions();
29+
ChromeOptions options = getDefaultChromeOptions();
3030
options.setBrowserVersion("131");
3131
driver = new ChromeDriver(options);
3232
wait = new WebDriverWait(driver, Duration.ofSeconds(10));

examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ public void clearProperties() {
3434

3535
@Test
3636
public void basicOptions() {
37-
ChromeOptions options = new ChromeOptions();
37+
ChromeOptions options = getDefaultChromeOptions();
3838
driver = new ChromeDriver(options);
3939
}
4040

4141
@Test
4242
public void arguments() {
43-
ChromeOptions options = new ChromeOptions();
43+
ChromeOptions options = getDefaultChromeOptions();
4444

4545
options.addArguments("--start-maximized");
4646

@@ -49,7 +49,7 @@ public void arguments() {
4949

5050
@Test
5151
public void setBrowserLocation() {
52-
ChromeOptions options = new ChromeOptions();
52+
ChromeOptions options = getDefaultChromeOptions();
5353

5454
options.setBinary(getChromeLocation());
5555

@@ -58,7 +58,7 @@ public void setBrowserLocation() {
5858

5959
@Test
6060
public void extensionOptions() {
61-
ChromeOptions options = new ChromeOptions();
61+
ChromeOptions options = getDefaultChromeOptions();
6262
Path path = Paths.get("src/test/resources/extensions/webextensions-selenium-example.crx");
6363
File extensionFilePath = new File(path.toUri());
6464

@@ -73,7 +73,7 @@ public void extensionOptions() {
7373

7474
@Test
7575
public void excludeSwitches() {
76-
ChromeOptions options = new ChromeOptions();
76+
ChromeOptions options = getDefaultChromeOptions();
7777

7878
options.setExperimentalOption("excludeSwitches", List.of("disable-popup-blocking"));
7979

@@ -82,7 +82,7 @@ public void excludeSwitches() {
8282

8383
@Test
8484
public void loggingPreferences() {
85-
ChromeOptions options = new ChromeOptions();
85+
ChromeOptions options = getDefaultChromeOptions();
8686
LoggingPreferences logPrefs = new LoggingPreferences();
8787
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
8888
options.setCapability(ChromeOptions.LOGGING_PREFS, logPrefs);
@@ -175,7 +175,7 @@ public void disableBuildChecks() throws IOException {
175175
}
176176

177177
private File getChromeLocation() {
178-
ChromeOptions options = new ChromeOptions();
178+
ChromeOptions options = getDefaultChromeOptions();
179179
options.setBrowserVersion("stable");
180180
DriverFinder finder = new DriverFinder(ChromeDriverService.createDefaultService(), options);
181181
return new File(finder.getBrowserPath());

examples/java/src/test/java/dev/selenium/browsers/EdgeTest.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ public void clearProperties() {
3535

3636
@Test
3737
public void basicOptions() {
38-
EdgeOptions options = new EdgeOptions();
38+
EdgeOptions options = getDefaultEdgeOptions();
3939
driver = new EdgeDriver(options);
4040
}
4141

4242
@Test
4343
public void arguments() {
44-
EdgeOptions options = new EdgeOptions();
44+
EdgeOptions options = getDefaultEdgeOptions();
4545

4646
options.addArguments("--start-maximized");
4747

@@ -50,7 +50,7 @@ public void arguments() {
5050

5151
@Test
5252
public void setBrowserLocation() {
53-
EdgeOptions options = new EdgeOptions();
53+
EdgeOptions options = getDefaultEdgeOptions();
5454

5555
options.setBinary(getEdgeLocation());
5656

@@ -59,7 +59,7 @@ public void setBrowserLocation() {
5959

6060
@Test
6161
public void extensionOptions() {
62-
EdgeOptions options = new EdgeOptions();
62+
EdgeOptions options = getDefaultEdgeOptions();
6363
Path path = Paths.get("src/test/resources/extensions/webextensions-selenium-example.crx");
6464
File extensionFilePath = new File(path.toUri());
6565

@@ -74,7 +74,7 @@ public void extensionOptions() {
7474

7575
@Test
7676
public void excludeSwitches() {
77-
EdgeOptions options = new EdgeOptions();
77+
EdgeOptions options = getDefaultEdgeOptions();
7878

7979
options.setExperimentalOption("excludeSwitches", List.of("disable-popup-blocking"));
8080

@@ -83,7 +83,7 @@ public void excludeSwitches() {
8383

8484
@Test
8585
public void loggingPreferences() {
86-
EdgeOptions options = new EdgeOptions();
86+
EdgeOptions options = getDefaultEdgeOptions();
8787
LoggingPreferences logPrefs = new LoggingPreferences();
8888
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
8989
options.setCapability(EdgeOptions.LOGGING_PREFS, logPrefs);
@@ -170,7 +170,7 @@ public void disableBuildChecks() throws IOException {
170170
}
171171

172172
private File getEdgeLocation() {
173-
EdgeOptions options = new EdgeOptions();
173+
EdgeOptions options = getDefaultEdgeOptions();
174174
options.setBrowserVersion("stable");
175175
DriverFinder finder = new DriverFinder(EdgeDriverService.createDefaultService(), options);
176176
return new File(finder.getBrowserPath());

examples/java/src/test/java/dev/selenium/drivers/HttpClientTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void remoteWebDriverWithClientConfig() throws Exception {
4141
.readTimeout(Duration.ofSeconds(3600))
4242
.authenticateAs(new UsernameAndPassword("admin", "myStrongPassword"))
4343
.version(HTTP_1_1.toString());
44-
ChromeOptions options = new ChromeOptions();
44+
ChromeOptions options = getDefaultChromeOptions();
4545
options.setEnableDownloads(true);
4646
driver = RemoteWebDriver.builder()
4747
.oneOf(options)
@@ -60,7 +60,7 @@ public void remoteWebDriverIgnoreSSL() throws Exception {
6060
.readTimeout(Duration.ofSeconds(3600))
6161
.authenticateAs(new UsernameAndPassword("admin", "myStrongPassword"))
6262
.version(HTTP_1_1.toString());
63-
ChromeOptions options = new ChromeOptions();
63+
ChromeOptions options = getDefaultChromeOptions();
6464
options.setEnableDownloads(true);
6565
driver = RemoteWebDriver.builder()
6666
.oneOf(options)
@@ -78,7 +78,7 @@ public void remoteWebDriverWithEmbedAuthUrl() throws Exception {
7878
.connectionTimeout(Duration.ofSeconds(300))
7979
.readTimeout(Duration.ofSeconds(3600))
8080
.version(HTTP_1_1.toString());
81-
ChromeOptions options = new ChromeOptions();
81+
ChromeOptions options = getDefaultChromeOptions();
8282
options.setEnableDownloads(true);
8383
driver = RemoteWebDriver.builder()
8484
.oneOf(options)

examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class OptionsTest extends BaseTest {
1818

1919
@Test
2020
public void setPageLoadStrategyNormal() {
21-
ChromeOptions chromeOptions = new ChromeOptions();
21+
ChromeOptions chromeOptions = getDefaultChromeOptions();
2222
chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
2323
WebDriver driver = new ChromeDriver(chromeOptions);
2424
try {
@@ -31,7 +31,7 @@ public void setPageLoadStrategyNormal() {
3131

3232
@Test
3333
public void setPageLoadStrategyEager() {
34-
ChromeOptions chromeOptions = new ChromeOptions();
34+
ChromeOptions chromeOptions = getDefaultChromeOptions();
3535
chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
3636
WebDriver driver = new ChromeDriver(chromeOptions);
3737
try {
@@ -44,7 +44,7 @@ public void setPageLoadStrategyEager() {
4444

4545
@Test
4646
public void setPageLoadStrategyNone() {
47-
ChromeOptions chromeOptions = new ChromeOptions();
47+
ChromeOptions chromeOptions = getDefaultChromeOptions();
4848
chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
4949
WebDriver driver = new ChromeDriver(chromeOptions);
5050
try {
@@ -57,7 +57,7 @@ public void setPageLoadStrategyNone() {
5757

5858
@Test
5959
public void setAcceptInsecureCerts() {
60-
ChromeOptions chromeOptions = new ChromeOptions();
60+
ChromeOptions chromeOptions = getDefaultChromeOptions();
6161
chromeOptions.setAcceptInsecureCerts(true);
6262
WebDriver driver = new ChromeDriver(chromeOptions);
6363
try {
@@ -70,30 +70,30 @@ public void setAcceptInsecureCerts() {
7070

7171
@Test
7272
public void getBrowserName() {
73-
ChromeOptions chromeOptions = new ChromeOptions();
73+
ChromeOptions chromeOptions = getDefaultChromeOptions();
7474
String name = chromeOptions.getBrowserName();
7575
Assertions.assertFalse(name.isEmpty(), "Browser name should not be empty");
7676
}
7777

7878
@Test
7979
public void setBrowserVersion() {
80-
ChromeOptions chromeOptions = new ChromeOptions();
80+
ChromeOptions chromeOptions = getDefaultChromeOptions();
8181
String version = "latest";
8282
chromeOptions.setBrowserVersion(version);
8383
Assertions.assertEquals(version, chromeOptions.getBrowserVersion());
8484
}
8585

8686
@Test
8787
public void setPlatformName() {
88-
ChromeOptions chromeOptions = new ChromeOptions();
88+
ChromeOptions chromeOptions = getDefaultChromeOptions();
8989
String platform = "OS X 10.6";
9090
chromeOptions.setPlatformName(platform);
9191
Assertions.assertEquals(platform, chromeOptions.getPlatformName().toString());
9292
}
9393

9494
@Test
9595
public void setScriptTimeout() {
96-
ChromeOptions chromeOptions = new ChromeOptions();
96+
ChromeOptions chromeOptions = getDefaultChromeOptions();
9797
Duration duration = Duration.of(5, ChronoUnit.SECONDS);
9898
chromeOptions.setScriptTimeout(duration);
9999

@@ -108,7 +108,7 @@ public void setScriptTimeout() {
108108

109109
@Test
110110
public void setPageLoadTimeout() {
111-
ChromeOptions chromeOptions = new ChromeOptions();
111+
ChromeOptions chromeOptions = getDefaultChromeOptions();
112112
Duration duration = Duration.of(5, ChronoUnit.SECONDS);
113113
chromeOptions.setPageLoadTimeout(duration);
114114

@@ -123,7 +123,7 @@ public void setPageLoadTimeout() {
123123

124124
@Test
125125
public void setImplicitWaitTimeout() {
126-
ChromeOptions chromeOptions = new ChromeOptions();
126+
ChromeOptions chromeOptions = getDefaultChromeOptions();
127127
Duration duration = Duration.of(5, ChronoUnit.SECONDS);
128128
chromeOptions.setImplicitWaitTimeout(duration);
129129

@@ -138,7 +138,7 @@ public void setImplicitWaitTimeout() {
138138

139139
@Test
140140
public void setUnhandledPromptBehaviour() {
141-
ChromeOptions chromeOptions = new ChromeOptions();
141+
ChromeOptions chromeOptions = getDefaultChromeOptions();
142142
chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);
143143
//verify the capability object is not null
144144
Object capabilityObject = chromeOptions.getCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR);
@@ -148,7 +148,7 @@ public void setUnhandledPromptBehaviour() {
148148

149149
@Test
150150
public void setWindowRect() {
151-
ChromeOptions chromeOptions = new ChromeOptions();
151+
ChromeOptions chromeOptions = getDefaultChromeOptions();
152152
chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT, true);
153153
//verify the capability object is not null
154154
Object capabilityObject = chromeOptions.getCapability(CapabilityType.SET_WINDOW_RECT);
@@ -160,7 +160,7 @@ public void setWindowRect() {
160160

161161
@Test
162162
public void setStrictFileInteractability() {
163-
ChromeOptions chromeOptions = new ChromeOptions();
163+
ChromeOptions chromeOptions = getDefaultChromeOptions();
164164
chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY, true);
165165
//verify the capability object is not null
166166
Object capabilityObject = chromeOptions.getCapability(CapabilityType.STRICT_FILE_INTERACTABILITY);

examples/java/src/test/java/dev/selenium/drivers/RemoteWebDriverTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ public void startGrid() {
3535

3636
@Test
3737
public void runRemote() {
38-
ChromeOptions options = new ChromeOptions();
38+
ChromeOptions options = getDefaultChromeOptions();
3939
driver = new RemoteWebDriver(gridUrl, options);
4040
}
4141

4242
@Test
4343
public void uploads() {
44-
ChromeOptions options = new ChromeOptions();
44+
ChromeOptions options = getDefaultChromeOptions();
4545
driver = new RemoteWebDriver(gridUrl, options);
4646
driver.get("https://the-internet.herokuapp.com/upload");
4747
File uploadFile = new File("src/test/resources/selenium-snapshot.png");
@@ -57,7 +57,7 @@ public void uploads() {
5757

5858
@Test
5959
public void downloads() throws IOException {
60-
ChromeOptions options = new ChromeOptions();
60+
ChromeOptions options = getDefaultChromeOptions();
6161
options.setEnableDownloads(true);
6262
driver = new RemoteWebDriver(gridUrl, options);
6363

@@ -92,7 +92,7 @@ public void downloads() throws IOException {
9292

9393
@Test
9494
public void augment() {
95-
ChromeOptions options = new ChromeOptions();
95+
ChromeOptions options = getDefaultChromeOptions();
9696
driver = new RemoteWebDriver(gridUrl, options);
9797

9898
driver = new Augmenter().augment(driver);
@@ -105,7 +105,7 @@ public void remoteWebDriverBuilder() {
105105
driver =
106106
RemoteWebDriver.builder()
107107
.address(gridUrl)
108-
.oneOf(new ChromeOptions())
108+
.oneOf(getDefaultChromeOptions())
109109
.setCapability("ext:options", Map.of("key", "value"))
110110
.config(ClientConfig.defaultConfig())
111111
.build();

examples/java/src/test/java/dev/selenium/drivers/ServiceTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void defaultService() {
1919
@Test
2020
public void setDriverLocation() {
2121
setBinaryPaths();
22-
ChromeOptions options = new ChromeOptions();
22+
ChromeOptions options = getDefaultChromeOptions();
2323
options.setBinary(browserPath);
2424

2525
ChromeDriverService service =
@@ -36,7 +36,7 @@ public void setPort() {
3636
}
3737

3838
private void setBinaryPaths() {
39-
ChromeOptions options = new ChromeOptions();
39+
ChromeOptions options = getDefaultChromeOptions();
4040
options.setBrowserVersion("stable");
4141
DriverFinder finder = new DriverFinder(ChromeDriverService.createDefaultService(), options);
4242
driverPath = new File(finder.getDriverPath());

examples/java/src/test/java/dev/selenium/interactions/AlertsTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
import dev.selenium.BaseTest;
1819
import org.junit.jupiter.api.Test;
1920
import org.openqa.selenium.*;
2021
import org.openqa.selenium.chrome.ChromeDriver;
@@ -26,12 +27,12 @@
2627

2728
import static org.junit.jupiter.api.Assertions.assertEquals;
2829

29-
public class AlertsTest {
30+
public class AlertsTest extends BaseTest {
3031

3132
@Test
3233
public void testForAlerts() throws Exception {
3334

34-
ChromeOptions chromeOptions = new ChromeOptions();
35+
ChromeOptions chromeOptions = getDefaultChromeOptions();
3536
chromeOptions.addArguments("disable-search-engine-choice-screen");
3637
WebDriver driver = new ChromeDriver(chromeOptions);
3738

examples/java/src/test/java/dev/selenium/interactions/PrintsPageTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class PrintsPageTest extends BaseTest{
1616

1717
@BeforeEach
1818
public void setup() {
19-
ChromeOptions options = new ChromeOptions();
19+
ChromeOptions options = getDefaultChromeOptions();
2020
options.setCapability("webSocketUrl", true);
2121
driver = new ChromeDriver(options);
2222
}

0 commit comments

Comments
 (0)