Skip to content
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
6 changes: 6 additions & 0 deletions examples/java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.gradle
/build
/out
/target
/selenium.pdf
/selenium.xml*
6 changes: 4 additions & 2 deletions examples/java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ repositories {
}

dependencies {
testImplementation 'org.seleniumhq.selenium:selenium-java:4.38.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.13.4'
testImplementation 'org.seleniumhq.selenium:selenium-java:4.40.0'
testImplementation 'org.seleniumhq.selenium:selenium-grid:4.40.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:6.0.2'
testImplementation 'com.titusfortner:selenium-logger:2.4.0'
}

test {
Expand Down
5 changes: 3 additions & 2 deletions examples/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<selenium.version>4.38.0</selenium.version>
<selenium.version>4.40.0</selenium.version>
</properties>

<repositories>
Expand Down Expand Up @@ -44,13 +44,14 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.13.4</version>
<version>6.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.titusfortner</groupId>
<artifactId>selenium-logger</artifactId>
<version>2.4.0</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
10 changes: 3 additions & 7 deletions examples/java/src/test/java/dev/selenium/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,11 @@ protected ChromeDriver startChromeDriver(ChromeOptions options) {
}

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

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

protected File getTempDirectory(String prefix) {
Expand Down Expand Up @@ -156,7 +152,7 @@ protected void enableLogging() {
}

@AfterEach
public void quit() {
public final void closeBrowser() {
if (driver != null) {
driver.quit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ void canHaveTheDefaultBackgroundColor() {

@AfterAll
public static void cleanup() {
driver.quit();
if (driver != null) {
driver.quit();
driver = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ public void setNetworkConditions() {
() -> Assertions.assertEquals(networkConditions.getUploadThroughput(), actualConditions.getUploadThroughput())
);
((EdgeDriver) driver).deleteNetworkConditions();
driver.quit();
}

@Test
Expand Down
19 changes: 6 additions & 13 deletions examples/java/src/test/java/dev/selenium/browsers/FirefoxTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.remote.service.DriverFinder;





public class FirefoxTest extends BaseTest {
private FirefoxDriver driver;

@AfterEach
public void clearProperties() {
System.clearProperty(GeckoDriverService.GECKO_DRIVER_LOG_PROPERTY);
System.clearProperty(GeckoDriverService.GECKO_DRIVER_LOG_LEVEL_PROPERTY);driver.quit();
System.clearProperty(GeckoDriverService.GECKO_DRIVER_LOG_LEVEL_PROPERTY);
if (driver != null) {
driver.quit();
}
}

@Test
Expand Down Expand Up @@ -186,24 +185,20 @@ public void fullPageScreenshot() throws Exception {
// Verify the screenshot file exists
Assertions.assertTrue(targetFile.exists(), "The full page screenshot file should exist");
Files.deleteIfExists(targetFile.toPath());

driver.quit();
}

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

((HasContext) driver).setContext(FirefoxCommandContext.CHROME);
driver.setContext(FirefoxCommandContext.CHROME);
driver.executeScript("console.log('Inside Chrome context');");

// Verify the context is back to "content"
Assertions.assertEquals(
FirefoxCommandContext.CHROME, ((HasContext) driver).getContext(),
FirefoxCommandContext.CHROME, driver.getContext(),
"The context should be 'chrome'"
);

driver.quit();
}

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

driver = new FirefoxDriver(options);

driver.quit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public void remoteWebDriverWithClientConfig() throws Exception {
.address(gridUrl)
.config(clientConfig)
.build();
driver.quit();
}

@Test
Expand All @@ -67,7 +66,6 @@ public void remoteWebDriverIgnoreSSL() throws Exception {
.address(gridUrl)
.config(clientConfig)
.build();
driver.quit();
}

@Test
Expand All @@ -85,7 +83,6 @@ public void remoteWebDriverWithEmbedAuthUrl() throws Exception {
.address(embedAuthToUrl(gridUrl, "admin", "myStrongPassword"))
.config(clientConfig)
.build();
driver.quit();
}

private URL embedAuthToUrl(URL url, String username, String password) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import java.time.Duration;

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

Expand All @@ -15,57 +17,56 @@ public class InformationTest {
@Test
public void informationWithElements() {

WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
// Navigate to Url
driver.get("https://www.selenium.dev/selenium/web/inputs.html");

// isDisplayed
// Get boolean value for is element display
boolean isEmailVisible = driver.findElement(By.name("email_input")).isDisplayed();
assertTrue(isEmailVisible);
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
// Navigate to Url
driver.get("https://www.selenium.dev/selenium/web/inputs.html");

// isEnabled
// returns true if element is enabled else returns false
boolean isEnabledButton = driver.findElement(By.name("button_input")).isEnabled();
assertTrue(isEnabledButton);
// isDisplayed
// Get boolean value for is element display
boolean isEmailVisible = driver.findElement(By.name("email_input")).isDisplayed();
assertTrue(isEmailVisible);

// isSelected
// returns true if element is checked else returns false
boolean isSelectedCheck = driver.findElement(By.name("checkbox_input")).isSelected();
assertTrue(isSelectedCheck);
// isEnabled
// returns true if element is enabled
boolean isEnabledButton = driver.findElement(By.name("button_input")).isEnabled();
assertTrue(isEnabledButton);

// TagName
// returns TagName of the element
String tagNameInp = driver.findElement(By.name("email_input")).getTagName();
assertEquals("input", tagNameInp);
// isSelected
// returns true if element is checked
boolean isSelectedCheck = driver.findElement(By.name("checkbox_input")).isSelected();
assertTrue(isSelectedCheck);

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

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

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

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

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

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

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

driver.quit();
driver.quit();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ public void eightComponents() {
}

@AfterEach
public void teardown() {
driver.quit();
public final void teardown() {
if (driver != null) {
driver.quit();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ public void createSession() {
wait = new WebDriverWait(driver, Duration.ofSeconds(10));
}

@AfterEach
public void endSession() {
driver.quit();
}

@Test
public void alertInformationTest() {
driver.get("https://www.selenium.dev/selenium/web/alerts.html#");
Expand Down
Loading