Skip to content

Commit 293e6f2

Browse files
authored
Merge branch 'trunk' into trunk
2 parents 77579ce + e7f4460 commit 293e6f2

23 files changed

Lines changed: 237 additions & 231 deletions

File tree

.github/workflows/java-examples.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ on:
1515
paths:
1616
- 'examples/java/**'
1717

18+
concurrency:
19+
group: ${{ github.workflow }}-${{ github.ref }}
20+
cancel-in-progress: true
21+
1822
env:
1923
DISPLAY: :99
2024
GITHUB_TOKEN: ${{ secrets.SELENIUM_CI_TOKEN }}
@@ -56,7 +60,7 @@ jobs:
5660
- name: Import test cert Windows
5761
if: matrix.os == 'windows'
5862
run: keytool -import -noprompt -trustcacerts -alias SeleniumHQ -file examples/java/src/test/resources/tls.crt -keystore ${{ steps.java.outputs.path }}/lib/security/cacerts -storepass changeit
59-
- name: Run Tests Stable
63+
- name: Run Tests Stable (in Maven)
6064
if: matrix.release == 'stable'
6165
uses: nick-invision/[email protected]
6266
with:
@@ -65,6 +69,15 @@ jobs:
6569
command: |
6670
cd examples/java
6771
mvn -B test -D"jdk.internal.httpclient.disableHostnameVerification=true"
72+
- name: Run Tests Stable (in Gradle)
73+
if: matrix.release == 'stable'
74+
uses: nick-invision/[email protected]
75+
with:
76+
timeout_minutes: 40
77+
max_attempts: 3
78+
command: |
79+
cd examples/java
80+
./gradlew test --tests 'dev.selenium.*UsingSeleniumTest'
6881
- name: Run Tests Nightly Linux/macOS
6982
if: matrix.release == 'nightly' && matrix.os != 'windows'
7083
uses: nick-invision/[email protected]
@@ -105,3 +118,13 @@ jobs:
105118
cd examples/java
106119
mvn -B -U test "-Djdk.internal.httpclient.disableHostnameVerification=true" "-Dselenium.version=$new_version"
107120
}
121+
- name: Upload test report
122+
uses: actions/upload-artifact@v6
123+
if: failure()
124+
with:
125+
name: test-report-${{matrix.os}}-${{matrix.release}}
126+
retention-days: 14
127+
path: |
128+
examples/java/target/surefire-reports
129+
examples/java/build/reports
130+
examples/java/build/test-results

examples/java/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.gradle
2+
/build
3+
/out
4+
/target

examples/java/build.gradle

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ repositories {
99
mavenCentral()
1010
}
1111

12+
ext['seleniumVersion'] = System.getProperty('selenium.version', '4.40.0')
13+
1214
dependencies {
13-
testImplementation 'org.seleniumhq.selenium:selenium-java:4.38.0'
14-
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.13.4'
15+
testImplementation "org.seleniumhq.selenium:selenium-java:${seleniumVersion}"
16+
testImplementation "org.seleniumhq.selenium:selenium-grid:${seleniumVersion}"
17+
testImplementation platform("org.junit:junit-bom:6.0.2")
18+
testImplementation 'org.junit.jupiter:junit-jupiter-engine'
19+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
20+
testImplementation 'com.titusfortner:selenium-logger:2.4.0'
1521
}
1622

1723
test {

examples/java/pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<maven.compiler.source>17</maven.compiler.source>
1414
<maven.compiler.target>17</maven.compiler.target>
1515
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16-
<selenium.version>4.38.0</selenium.version>
16+
<selenium.version>4.40.0</selenium.version>
1717
</properties>
1818

1919
<repositories>
@@ -44,13 +44,14 @@
4444
<dependency>
4545
<groupId>org.junit.jupiter</groupId>
4646
<artifactId>junit-jupiter-engine</artifactId>
47-
<version>5.13.4</version>
47+
<version>6.0.2</version>
4848
<scope>test</scope>
4949
</dependency>
5050
<dependency>
5151
<groupId>com.titusfortner</groupId>
5252
<artifactId>selenium-logger</artifactId>
5353
<version>2.4.0</version>
54+
<scope>test</scope>
5455
</dependency>
5556
</dependencies>
5657

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class BaseTest {
3131
protected String username = "admin";
3232
protected String password = "myStrongPassword";
3333
protected String trustStorePassword = "seleniumkeystore";
34+
private final Path artifactsDir = Path.of("target", "surefire-reports");
3435

3536
public WebElement getLocatedElement(WebDriver driver, By by) {
3637
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
@@ -59,15 +60,16 @@ protected ChromeDriver startChromeDriver(ChromeOptions options) {
5960
}
6061

6162
protected static ChromeOptions getDefaultChromeOptions() {
62-
ChromeOptions options = new ChromeOptions();
63-
options.addArguments("--no-sandbox");
64-
return options;
63+
return new ChromeOptions().addArguments("--no-sandbox");
6564
}
6665

6766
protected static EdgeOptions getDefaultEdgeOptions() {
68-
EdgeOptions options = new EdgeOptions();
69-
options.addArguments("--no-sandbox");
70-
return options;
67+
return new EdgeOptions().addArguments("--no-sandbox");
68+
}
69+
70+
protected Path artifactsDir() throws IOException {
71+
Files.createDirectories(artifactsDir);
72+
return artifactsDir;
7173
}
7274

7375
protected File getTempDirectory(String prefix) {
@@ -156,7 +158,7 @@ protected void enableLogging() {
156158
}
157159

158160
@AfterEach
159-
public void quit() {
161+
public final void closeBrowser() {
160162
if (driver != null) {
161163
driver.quit();
162164
}

examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/user_context/SingleInstanceCookieParallelTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ void canHaveTheDefaultBackgroundColor() {
128128

129129
@AfterAll
130130
public static void cleanup() {
131-
driver.quit();
131+
if (driver != null) {
132+
driver.quit();
133+
driver = null;
134+
}
132135
}
133136
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ public void setNetworkConditions() {
218218
() -> Assertions.assertEquals(networkConditions.getUploadThroughput(), actualConditions.getUploadThroughput())
219219
);
220220
((EdgeDriver) driver).deleteNetworkConditions();
221-
driver.quit();
222221
}
223222

224223
@Test

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@
1818
import org.openqa.selenium.firefox.*;
1919
import org.openqa.selenium.remote.service.DriverFinder;
2020

21-
22-
23-
24-
2521
public class FirefoxTest extends BaseTest {
2622
private FirefoxDriver driver;
2723

2824
@AfterEach
2925
public void clearProperties() {
3026
System.clearProperty(GeckoDriverService.GECKO_DRIVER_LOG_PROPERTY);
31-
System.clearProperty(GeckoDriverService.GECKO_DRIVER_LOG_LEVEL_PROPERTY);driver.quit();
27+
System.clearProperty(GeckoDriverService.GECKO_DRIVER_LOG_LEVEL_PROPERTY);
28+
if (driver != null) {
29+
driver.quit();
30+
}
3231
}
3332

3433
@Test
@@ -186,24 +185,20 @@ public void fullPageScreenshot() throws Exception {
186185
// Verify the screenshot file exists
187186
Assertions.assertTrue(targetFile.exists(), "The full page screenshot file should exist");
188187
Files.deleteIfExists(targetFile.toPath());
189-
190-
driver.quit();
191188
}
192189

193190
@Test
194191
public void setContext() {
195192
driver = startFirefoxDriver(new FirefoxOptions().addArguments("-remote-allow-system-access"));
196193

197-
((HasContext) driver).setContext(FirefoxCommandContext.CHROME);
194+
driver.setContext(FirefoxCommandContext.CHROME);
198195
driver.executeScript("console.log('Inside Chrome context');");
199196

200197
// Verify the context is back to "content"
201198
Assertions.assertEquals(
202-
FirefoxCommandContext.CHROME, ((HasContext) driver).getContext(),
199+
FirefoxCommandContext.CHROME, driver.getContext(),
203200
"The context should be 'chrome'"
204201
);
205-
206-
driver.quit();
207202
}
208203

209204
@Test
@@ -214,7 +209,5 @@ public void firefoxProfile() {
214209
options.setProfile(profile);
215210

216211
driver = new FirefoxDriver(options);
217-
218-
driver.quit();
219212
}
220213
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public void remoteWebDriverWithClientConfig() throws Exception {
4848
.address(gridUrl)
4949
.config(clientConfig)
5050
.build();
51-
driver.quit();
5251
}
5352

5453
@Test
@@ -67,7 +66,6 @@ public void remoteWebDriverIgnoreSSL() throws Exception {
6766
.address(gridUrl)
6867
.config(clientConfig)
6968
.build();
70-
driver.quit();
7169
}
7270

7371
@Test
@@ -85,7 +83,6 @@ public void remoteWebDriverWithEmbedAuthUrl() throws Exception {
8583
.address(embedAuthToUrl(gridUrl, "admin", "myStrongPassword"))
8684
.config(clientConfig)
8785
.build();
88-
driver.quit();
8986
}
9087

9188
private URL embedAuthToUrl(URL url, String username, String password) throws Exception {

examples/java/src/test/java/dev/selenium/elements/InformationTest.java

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import org.openqa.selenium.WebDriver;
77
import org.openqa.selenium.WebElement;
88
import org.openqa.selenium.chrome.ChromeDriver;
9+
910
import java.time.Duration;
11+
1012
import static org.junit.jupiter.api.Assertions.assertEquals;
1113
import static org.junit.jupiter.api.Assertions.assertTrue;
1214

@@ -15,57 +17,56 @@ public class InformationTest {
1517
@Test
1618
public void informationWithElements() {
1719

18-
WebDriver driver = new ChromeDriver();
19-
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
20-
// Navigate to Url
21-
driver.get("https://www.selenium.dev/selenium/web/inputs.html");
22-
23-
// isDisplayed
24-
// Get boolean value for is element display
25-
boolean isEmailVisible = driver.findElement(By.name("email_input")).isDisplayed();
26-
assertTrue(isEmailVisible);
20+
WebDriver driver = new ChromeDriver();
21+
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
22+
// Navigate to Url
23+
driver.get("https://www.selenium.dev/selenium/web/inputs.html");
2724

28-
// isEnabled
29-
// returns true if element is enabled else returns false
30-
boolean isEnabledButton = driver.findElement(By.name("button_input")).isEnabled();
31-
assertTrue(isEnabledButton);
25+
// isDisplayed
26+
// Get boolean value for is element display
27+
boolean isEmailVisible = driver.findElement(By.name("email_input")).isDisplayed();
28+
assertTrue(isEmailVisible);
3229

33-
// isSelected
34-
// returns true if element is checked else returns false
35-
boolean isSelectedCheck = driver.findElement(By.name("checkbox_input")).isSelected();
36-
assertTrue(isSelectedCheck);
30+
// isEnabled
31+
// returns true if element is enabled
32+
boolean isEnabledButton = driver.findElement(By.name("button_input")).isEnabled();
33+
assertTrue(isEnabledButton);
3734

38-
// TagName
39-
// returns TagName of the element
40-
String tagNameInp = driver.findElement(By.name("email_input")).getTagName();
41-
assertEquals("input", tagNameInp);
35+
// isSelected
36+
// returns true if element is checked
37+
boolean isSelectedCheck = driver.findElement(By.name("checkbox_input")).isSelected();
38+
assertTrue(isSelectedCheck);
4239

43-
// GetRect
44-
// Returns height, width, x and y coordinates referenced element
45-
Rectangle res = driver.findElement(By.name("range_input")).getRect();
46-
// Rectangle class provides getX,getY, getWidth, getHeight methods
47-
assertEquals(10, res.getX());
40+
// TagName
41+
// returns TagName of the element
42+
String tagNameInp = driver.findElement(By.name("email_input")).getTagName();
43+
assertEquals("input", tagNameInp);
4844

49-
// Retrieves the computed style property 'font-size' of field
50-
String cssValue = driver.findElement(By.name("color_input")).getCssValue("font-size");
51-
assertEquals(cssValue, "13.3333px");
45+
// GetRect
46+
// Returns height, width, x and y coordinates referenced element
47+
Rectangle res = driver.findElement(By.name("range_input")).getRect();
48+
// Rectangle class provides getX,getY, getWidth, getHeight methods
49+
assertEquals(10, res.getX());
5250

51+
// Retrieves the computed style property 'font-size' of field
52+
String cssValue = driver.findElement(By.name("color_input")).getCssValue("font-size");
53+
assertEquals(cssValue, "13.3333px");
5354

54-
// GetText
55-
// Retrieves the text of the element
56-
String text = driver.findElement(By.tagName("h1")).getText();
57-
assertEquals(text, "Testing Inputs");
5855

56+
// GetText
57+
// Retrieves the text of the element
58+
String text = driver.findElement(By.tagName("h1")).getText();
59+
assertEquals(text, "Testing Inputs");
5960

60-
// FetchAttributes
61-
// identify the email text box
62-
WebElement emailTxt = driver.findElement(By.name(("email_input")));
63-
// fetch the value property associated with the textbox
64-
String valueInfo = emailTxt.getAttribute("value");
65-
assertEquals(valueInfo,"admin@localhost");
6661

62+
// FetchAttributes
63+
// identify the email text box
64+
WebElement emailTxt = driver.findElement(By.name(("email_input")));
65+
// fetch the value property associated with the textbox
66+
String valueInfo = emailTxt.getAttribute("value");
67+
assertEquals(valueInfo, "admin@localhost");
6768

68-
driver.quit();
69+
driver.quit();
6970
}
7071

7172
}

0 commit comments

Comments
 (0)