Skip to content

Update examples test Chrome/Edge run on Ubuntu 24.04 hosted runners #2139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/java/src/test/java/dev/selenium/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.grid.Main;
Expand Down Expand Up @@ -57,6 +58,18 @@ protected ChromeDriver startChromeDriver(ChromeOptions options) {
return (ChromeDriver) driver;
}

protected static ChromeOptions getDefaultChromeOptions() {
ChromeOptions options = new ChromeOptions();
options.addArguments("--no-sandbox");
return options;
}

protected static EdgeOptions getDefaultEdgeOptions() {
EdgeOptions options = new EdgeOptions();
options.addArguments("--no-sandbox");
return options;
}

protected File getTempDirectory(String prefix) {
File tempDirectory = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class CdpApiTest extends BaseTest {

@BeforeEach
public void createSession() {
ChromeOptions options = new ChromeOptions();
ChromeOptions options = getDefaultChromeOptions();
options.setBrowserVersion("131");
driver = new ChromeDriver(options);
wait = new WebDriverWait(driver, Duration.ofSeconds(10));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public void clearProperties() {

@Test
public void basicOptions() {
ChromeOptions options = new ChromeOptions();
ChromeOptions options = getDefaultChromeOptions();
driver = new ChromeDriver(options);
}

@Test
public void arguments() {
ChromeOptions options = new ChromeOptions();
ChromeOptions options = getDefaultChromeOptions();

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

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

@Test
public void setBrowserLocation() {
ChromeOptions options = new ChromeOptions();
ChromeOptions options = getDefaultChromeOptions();

options.setBinary(getChromeLocation());

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

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

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

@Test
public void excludeSwitches() {
ChromeOptions options = new ChromeOptions();
ChromeOptions options = getDefaultChromeOptions();

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

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

@Test
public void loggingPreferences() {
ChromeOptions options = new ChromeOptions();
ChromeOptions options = getDefaultChromeOptions();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
options.setCapability(ChromeOptions.LOGGING_PREFS, logPrefs);
Expand Down Expand Up @@ -175,7 +175,7 @@ public void disableBuildChecks() throws IOException {
}

private File getChromeLocation() {
ChromeOptions options = new ChromeOptions();
ChromeOptions options = getDefaultChromeOptions();
options.setBrowserVersion("stable");
DriverFinder finder = new DriverFinder(ChromeDriverService.createDefaultService(), options);
return new File(finder.getBrowserPath());
Expand Down
14 changes: 7 additions & 7 deletions examples/java/src/test/java/dev/selenium/browsers/EdgeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public void clearProperties() {

@Test
public void basicOptions() {
EdgeOptions options = new EdgeOptions();
EdgeOptions options = getDefaultEdgeOptions();
driver = new EdgeDriver(options);
}

@Test
public void arguments() {
EdgeOptions options = new EdgeOptions();
EdgeOptions options = getDefaultEdgeOptions();

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

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

@Test
public void setBrowserLocation() {
EdgeOptions options = new EdgeOptions();
EdgeOptions options = getDefaultEdgeOptions();

options.setBinary(getEdgeLocation());

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

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

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

@Test
public void excludeSwitches() {
EdgeOptions options = new EdgeOptions();
EdgeOptions options = getDefaultEdgeOptions();

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

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

@Test
public void loggingPreferences() {
EdgeOptions options = new EdgeOptions();
EdgeOptions options = getDefaultEdgeOptions();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
options.setCapability(EdgeOptions.LOGGING_PREFS, logPrefs);
Expand Down Expand Up @@ -170,7 +170,7 @@ public void disableBuildChecks() throws IOException {
}

private File getEdgeLocation() {
EdgeOptions options = new EdgeOptions();
EdgeOptions options = getDefaultEdgeOptions();
options.setBrowserVersion("stable");
DriverFinder finder = new DriverFinder(EdgeDriverService.createDefaultService(), options);
return new File(finder.getBrowserPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void remoteWebDriverWithClientConfig() throws Exception {
.readTimeout(Duration.ofSeconds(3600))
.authenticateAs(new UsernameAndPassword("admin", "myStrongPassword"))
.version(HTTP_1_1.toString());
ChromeOptions options = new ChromeOptions();
ChromeOptions options = getDefaultChromeOptions();
options.setEnableDownloads(true);
driver = RemoteWebDriver.builder()
.oneOf(options)
Expand All @@ -60,7 +60,7 @@ public void remoteWebDriverIgnoreSSL() throws Exception {
.readTimeout(Duration.ofSeconds(3600))
.authenticateAs(new UsernameAndPassword("admin", "myStrongPassword"))
.version(HTTP_1_1.toString());
ChromeOptions options = new ChromeOptions();
ChromeOptions options = getDefaultChromeOptions();
options.setEnableDownloads(true);
driver = RemoteWebDriver.builder()
.oneOf(options)
Expand All @@ -78,7 +78,7 @@ public void remoteWebDriverWithEmbedAuthUrl() throws Exception {
.connectionTimeout(Duration.ofSeconds(300))
.readTimeout(Duration.ofSeconds(3600))
.version(HTTP_1_1.toString());
ChromeOptions options = new ChromeOptions();
ChromeOptions options = getDefaultChromeOptions();
options.setEnableDownloads(true);
driver = RemoteWebDriver.builder()
.oneOf(options)
Expand Down
26 changes: 13 additions & 13 deletions examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class OptionsTest extends BaseTest {

@Test
public void setPageLoadStrategyNormal() {
ChromeOptions chromeOptions = new ChromeOptions();
ChromeOptions chromeOptions = getDefaultChromeOptions();
chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
WebDriver driver = new ChromeDriver(chromeOptions);
try {
Expand All @@ -31,7 +31,7 @@ public void setPageLoadStrategyNormal() {

@Test
public void setPageLoadStrategyEager() {
ChromeOptions chromeOptions = new ChromeOptions();
ChromeOptions chromeOptions = getDefaultChromeOptions();
chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
WebDriver driver = new ChromeDriver(chromeOptions);
try {
Expand All @@ -44,7 +44,7 @@ public void setPageLoadStrategyEager() {

@Test
public void setPageLoadStrategyNone() {
ChromeOptions chromeOptions = new ChromeOptions();
ChromeOptions chromeOptions = getDefaultChromeOptions();
chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
WebDriver driver = new ChromeDriver(chromeOptions);
try {
Expand All @@ -57,7 +57,7 @@ public void setPageLoadStrategyNone() {

@Test
public void setAcceptInsecureCerts() {
ChromeOptions chromeOptions = new ChromeOptions();
ChromeOptions chromeOptions = getDefaultChromeOptions();
chromeOptions.setAcceptInsecureCerts(true);
WebDriver driver = new ChromeDriver(chromeOptions);
try {
Expand All @@ -70,30 +70,30 @@ public void setAcceptInsecureCerts() {

@Test
public void getBrowserName() {
ChromeOptions chromeOptions = new ChromeOptions();
ChromeOptions chromeOptions = getDefaultChromeOptions();
String name = chromeOptions.getBrowserName();
Assertions.assertFalse(name.isEmpty(), "Browser name should not be empty");
}

@Test
public void setBrowserVersion() {
ChromeOptions chromeOptions = new ChromeOptions();
ChromeOptions chromeOptions = getDefaultChromeOptions();
String version = "latest";
chromeOptions.setBrowserVersion(version);
Assertions.assertEquals(version, chromeOptions.getBrowserVersion());
}

@Test
public void setPlatformName() {
ChromeOptions chromeOptions = new ChromeOptions();
ChromeOptions chromeOptions = getDefaultChromeOptions();
String platform = "OS X 10.6";
chromeOptions.setPlatformName(platform);
Assertions.assertEquals(platform, chromeOptions.getPlatformName().toString());
}

@Test
public void setScriptTimeout() {
ChromeOptions chromeOptions = new ChromeOptions();
ChromeOptions chromeOptions = getDefaultChromeOptions();
Duration duration = Duration.of(5, ChronoUnit.SECONDS);
chromeOptions.setScriptTimeout(duration);

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

@Test
public void setPageLoadTimeout() {
ChromeOptions chromeOptions = new ChromeOptions();
ChromeOptions chromeOptions = getDefaultChromeOptions();
Duration duration = Duration.of(5, ChronoUnit.SECONDS);
chromeOptions.setPageLoadTimeout(duration);

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

@Test
public void setImplicitWaitTimeout() {
ChromeOptions chromeOptions = new ChromeOptions();
ChromeOptions chromeOptions = getDefaultChromeOptions();
Duration duration = Duration.of(5, ChronoUnit.SECONDS);
chromeOptions.setImplicitWaitTimeout(duration);

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

@Test
public void setUnhandledPromptBehaviour() {
ChromeOptions chromeOptions = new ChromeOptions();
ChromeOptions chromeOptions = getDefaultChromeOptions();
chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);
//verify the capability object is not null
Object capabilityObject = chromeOptions.getCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR);
Expand All @@ -148,7 +148,7 @@ public void setUnhandledPromptBehaviour() {

@Test
public void setWindowRect() {
ChromeOptions chromeOptions = new ChromeOptions();
ChromeOptions chromeOptions = getDefaultChromeOptions();
chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT, true);
//verify the capability object is not null
Object capabilityObject = chromeOptions.getCapability(CapabilityType.SET_WINDOW_RECT);
Expand All @@ -160,7 +160,7 @@ public void setWindowRect() {

@Test
public void setStrictFileInteractability() {
ChromeOptions chromeOptions = new ChromeOptions();
ChromeOptions chromeOptions = getDefaultChromeOptions();
chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY, true);
//verify the capability object is not null
Object capabilityObject = chromeOptions.getCapability(CapabilityType.STRICT_FILE_INTERACTABILITY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public void startGrid() {

@Test
public void runRemote() {
ChromeOptions options = new ChromeOptions();
ChromeOptions options = getDefaultChromeOptions();
driver = new RemoteWebDriver(gridUrl, options);
}

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

@Test
public void downloads() throws IOException {
ChromeOptions options = new ChromeOptions();
ChromeOptions options = getDefaultChromeOptions();
options.setEnableDownloads(true);
driver = new RemoteWebDriver(gridUrl, options);

Expand Down Expand Up @@ -92,7 +92,7 @@ public void downloads() throws IOException {

@Test
public void augment() {
ChromeOptions options = new ChromeOptions();
ChromeOptions options = getDefaultChromeOptions();
driver = new RemoteWebDriver(gridUrl, options);

driver = new Augmenter().augment(driver);
Expand All @@ -105,7 +105,7 @@ public void remoteWebDriverBuilder() {
driver =
RemoteWebDriver.builder()
.address(gridUrl)
.oneOf(new ChromeOptions())
.oneOf(getDefaultChromeOptions())
.setCapability("ext:options", Map.of("key", "value"))
.config(ClientConfig.defaultConfig())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void defaultService() {
@Test
public void setDriverLocation() {
setBinaryPaths();
ChromeOptions options = new ChromeOptions();
ChromeOptions options = getDefaultChromeOptions();
options.setBinary(browserPath);

ChromeDriverService service =
Expand All @@ -36,7 +36,7 @@ public void setPort() {
}

private void setBinaryPaths() {
ChromeOptions options = new ChromeOptions();
ChromeOptions options = getDefaultChromeOptions();
options.setBrowserVersion("stable");
DriverFinder finder = new DriverFinder(ChromeDriverService.createDefaultService(), options);
driverPath = new File(finder.getDriverPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.

import dev.selenium.BaseTest;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
Expand All @@ -26,12 +27,12 @@

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

public class AlertsTest {
public class AlertsTest extends BaseTest {

@Test
public void testForAlerts() throws Exception {

ChromeOptions chromeOptions = new ChromeOptions();
ChromeOptions chromeOptions = getDefaultChromeOptions();
chromeOptions.addArguments("disable-search-engine-choice-screen");
WebDriver driver = new ChromeDriver(chromeOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class PrintsPageTest extends BaseTest{

@BeforeEach
public void setup() {
ChromeOptions options = new ChromeOptions();
ChromeOptions options = getDefaultChromeOptions();
options.setCapability("webSocketUrl", true);
driver = new ChromeDriver(options);
}
Expand Down
Loading
Loading