Skip to content

Commit ba56998

Browse files
committed
Simplify add extension tests in Chrome and Edge
1 parent 3e4cc91 commit ba56998

File tree

8 files changed

+67
-69
lines changed

8 files changed

+67
-69
lines changed

selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch05/caps/extensions/AddExtensionChromeJUnit4Test.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*/
1717
package io.github.bonigarcia.webdriver.junit4.ch05.caps.extensions;
1818

19-
import static org.openqa.selenium.support.ui.ExpectedConditions.attributeToBe;
20-
import static org.openqa.selenium.support.ui.ExpectedConditions.not;
19+
import static java.lang.invoke.MethodHandles.lookup;
20+
import static org.slf4j.LoggerFactory.getLogger;
2121

2222
import java.net.URISyntaxException;
2323
import java.nio.file.Path;
@@ -31,18 +31,20 @@
3131
import org.openqa.selenium.WebDriver;
3232
import org.openqa.selenium.WebElement;
3333
import org.openqa.selenium.chrome.ChromeOptions;
34-
import org.openqa.selenium.support.ui.WebDriverWait;
34+
import org.slf4j.Logger;
3535

3636
import io.github.bonigarcia.wdm.WebDriverManager;
3737

3838
public class AddExtensionChromeJUnit4Test {
3939

40+
static final Logger log = getLogger(lookup().lookupClass());
41+
4042
WebDriver driver;
4143

4244
@Before
4345
public void setup() throws URISyntaxException {
44-
Path extension = Paths
45-
.get(ClassLoader.getSystemResource("shade_dark_mode.crx").toURI());
46+
Path extension = Paths.get(
47+
ClassLoader.getSystemResource("shade_dark_mode.crx").toURI());
4648
ChromeOptions options = new ChromeOptions();
4749
options.addExtensions(extension.toFile());
4850

@@ -60,11 +62,9 @@ public void teardown() throws InterruptedException {
6062
@Test
6163
public void testAddExtension() {
6264
driver.get("https://bonigarcia.dev/selenium-webdriver-java/");
63-
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
64-
6565
WebElement body = driver.findElement(By.tagName("body"));
66-
String whiteRgba = "rgba(255, 255, 255, 1)";
67-
wait.until(not(attributeToBe(body, "background-color", whiteRgba)));
66+
log.debug("Background color is {}"
67+
+ body.getCssValue("background-color"));
6868
}
6969

7070
}

selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch05/caps/extensions/AddExtensionEdgeJUnit4Test.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*/
1717
package io.github.bonigarcia.webdriver.junit4.ch05.caps.extensions;
1818

19-
import static org.openqa.selenium.support.ui.ExpectedConditions.attributeToBe;
20-
import static org.openqa.selenium.support.ui.ExpectedConditions.not;
19+
import static java.lang.invoke.MethodHandles.lookup;
20+
import static org.slf4j.LoggerFactory.getLogger;
2121

2222
import java.net.URISyntaxException;
2323
import java.nio.file.Path;
@@ -31,12 +31,14 @@
3131
import org.openqa.selenium.WebDriver;
3232
import org.openqa.selenium.WebElement;
3333
import org.openqa.selenium.edge.EdgeOptions;
34-
import org.openqa.selenium.support.ui.WebDriverWait;
34+
import org.slf4j.Logger;
3535

3636
import io.github.bonigarcia.wdm.WebDriverManager;
3737

3838
public class AddExtensionEdgeJUnit4Test {
3939

40+
static final Logger log = getLogger(lookup().lookupClass());
41+
4042
WebDriver driver;
4143

4244
@Before
@@ -60,11 +62,9 @@ public void teardown() throws InterruptedException {
6062
@Test
6163
public void testAddExtension() {
6264
driver.get("https://bonigarcia.dev/selenium-webdriver-java/");
63-
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
64-
6565
WebElement body = driver.findElement(By.tagName("body"));
66-
String whiteRgba = "rgba(255, 255, 255, 1)";
67-
wait.until(not(attributeToBe(body, "background-color", whiteRgba)));
66+
log.debug("Background color is {}"
67+
+ body.getCssValue("background-color"));
6868
}
6969

7070
}

selenium-webdriver-junit5-seljup/src/test/java/io/github/bonigarcia/webdriver/seljup/ch05/caps/extensions/AddExtensionChromeSelJupTest.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
*/
1717
package io.github.bonigarcia.webdriver.seljup.ch05.caps.extensions;
1818

19-
import static org.openqa.selenium.support.ui.ExpectedConditions.attributeToBe;
20-
import static org.openqa.selenium.support.ui.ExpectedConditions.not;
19+
import static java.lang.invoke.MethodHandles.lookup;
20+
import static org.slf4j.LoggerFactory.getLogger;
2121

2222
import java.net.URISyntaxException;
2323
import java.nio.file.Path;
2424
import java.nio.file.Paths;
25-
import java.time.Duration;
2625

2726
import org.junit.jupiter.api.BeforeEach;
2827
import org.junit.jupiter.api.Test;
@@ -31,14 +30,16 @@
3130
import org.openqa.selenium.WebElement;
3231
import org.openqa.selenium.chrome.ChromeDriver;
3332
import org.openqa.selenium.chrome.ChromeOptions;
34-
import org.openqa.selenium.support.ui.WebDriverWait;
33+
import org.slf4j.Logger;
3534

3635
import io.github.bonigarcia.seljup.Options;
3736
import io.github.bonigarcia.seljup.SeleniumJupiter;
3837

3938
@ExtendWith(SeleniumJupiter.class)
4039
class AddExtensionChromeSelJupTest {
4140

41+
static final Logger log = getLogger(lookup().lookupClass());
42+
4243
@Options
4344
ChromeOptions options = new ChromeOptions();
4445

@@ -52,11 +53,9 @@ void setup() throws URISyntaxException {
5253
@Test
5354
void testAddExtension(ChromeDriver driver) {
5455
driver.get("https://bonigarcia.dev/selenium-webdriver-java/");
55-
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
56-
5756
WebElement body = driver.findElement(By.tagName("body"));
58-
String whiteRgba = "rgba(255, 255, 255, 1)";
59-
wait.until(not(attributeToBe(body, "background-color", whiteRgba)));
57+
log.debug("Background color is {}"
58+
+ body.getCssValue("background-color"));
6059
}
6160

6261
}

selenium-webdriver-junit5-seljup/src/test/java/io/github/bonigarcia/webdriver/seljup/ch05/caps/extensions/AddExtensionEdgeSelJupTest.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
*/
1717
package io.github.bonigarcia.webdriver.seljup.ch05.caps.extensions;
1818

19-
import static org.openqa.selenium.support.ui.ExpectedConditions.attributeToBe;
20-
import static org.openqa.selenium.support.ui.ExpectedConditions.not;
19+
import static java.lang.invoke.MethodHandles.lookup;
20+
import static org.slf4j.LoggerFactory.getLogger;
2121

2222
import java.net.URISyntaxException;
2323
import java.nio.file.Path;
2424
import java.nio.file.Paths;
25-
import java.time.Duration;
2625

2726
import org.junit.jupiter.api.BeforeEach;
2827
import org.junit.jupiter.api.Test;
@@ -31,14 +30,16 @@
3130
import org.openqa.selenium.WebElement;
3231
import org.openqa.selenium.edge.EdgeDriver;
3332
import org.openqa.selenium.edge.EdgeOptions;
34-
import org.openqa.selenium.support.ui.WebDriverWait;
33+
import org.slf4j.Logger;
3534

3635
import io.github.bonigarcia.seljup.Options;
3736
import io.github.bonigarcia.seljup.SeleniumJupiter;
3837

3938
@ExtendWith(SeleniumJupiter.class)
4039
class AddExtensionEdgeSelJupTest {
4140

41+
static final Logger log = getLogger(lookup().lookupClass());
42+
4243
@Options
4344
EdgeOptions options = new EdgeOptions();
4445

@@ -52,11 +53,9 @@ void setup() throws URISyntaxException {
5253
@Test
5354
void testAddExtension(EdgeDriver driver) {
5455
driver.get("https://bonigarcia.dev/selenium-webdriver-java/");
55-
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
56-
5756
WebElement body = driver.findElement(By.tagName("body"));
58-
String whiteRgba = "rgba(255, 255, 255, 1)";
59-
wait.until(not(attributeToBe(body, "background-color", whiteRgba)));
57+
log.debug("Background color is {}"
58+
+ body.getCssValue("background-color"));
6059
}
6160

6261
}

selenium-webdriver-junit5/src/test/java/io/github/bonigarcia/webdriver/jupiter/ch05/caps/extensions/AddExtensionChromeJupiterTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*/
1717
package io.github.bonigarcia.webdriver.jupiter.ch05.caps.extensions;
1818

19-
import static org.openqa.selenium.support.ui.ExpectedConditions.attributeToBe;
20-
import static org.openqa.selenium.support.ui.ExpectedConditions.not;
19+
import static java.lang.invoke.MethodHandles.lookup;
20+
import static org.slf4j.LoggerFactory.getLogger;
2121

2222
import java.net.URISyntaxException;
2323
import java.nio.file.Path;
@@ -31,18 +31,20 @@
3131
import org.openqa.selenium.WebDriver;
3232
import org.openqa.selenium.WebElement;
3333
import org.openqa.selenium.chrome.ChromeOptions;
34-
import org.openqa.selenium.support.ui.WebDriverWait;
34+
import org.slf4j.Logger;
3535

3636
import io.github.bonigarcia.wdm.WebDriverManager;
3737

3838
class AddExtensionChromeJupiterTest {
3939

40+
static final Logger log = getLogger(lookup().lookupClass());
41+
4042
WebDriver driver;
4143

4244
@BeforeEach
4345
void setup() throws URISyntaxException {
44-
Path extension = Paths
45-
.get(ClassLoader.getSystemResource("shade_dark_mode.crx").toURI());
46+
Path extension = Paths.get(
47+
ClassLoader.getSystemResource("shade_dark_mode.crx").toURI());
4648
ChromeOptions options = new ChromeOptions();
4749
options.addExtensions(extension.toFile());
4850

@@ -58,13 +60,11 @@ void teardown() throws InterruptedException {
5860
}
5961

6062
@Test
61-
void testAddExtension() {
63+
public void testAddExtension() {
6264
driver.get("https://bonigarcia.dev/selenium-webdriver-java/");
63-
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
64-
6565
WebElement body = driver.findElement(By.tagName("body"));
66-
String whiteRgba = "rgba(255, 255, 255, 1)";
67-
wait.until(not(attributeToBe(body, "background-color", whiteRgba)));
66+
log.debug("Background color is {}"
67+
+ body.getCssValue("background-color"));
6868
}
6969

7070
}

selenium-webdriver-junit5/src/test/java/io/github/bonigarcia/webdriver/jupiter/ch05/caps/extensions/AddExtensionEdgeJupiterTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*/
1717
package io.github.bonigarcia.webdriver.jupiter.ch05.caps.extensions;
1818

19-
import static org.openqa.selenium.support.ui.ExpectedConditions.attributeToBe;
20-
import static org.openqa.selenium.support.ui.ExpectedConditions.not;
19+
import static java.lang.invoke.MethodHandles.lookup;
20+
import static org.slf4j.LoggerFactory.getLogger;
2121

2222
import java.net.URISyntaxException;
2323
import java.nio.file.Path;
@@ -31,18 +31,20 @@
3131
import org.openqa.selenium.WebDriver;
3232
import org.openqa.selenium.WebElement;
3333
import org.openqa.selenium.edge.EdgeOptions;
34-
import org.openqa.selenium.support.ui.WebDriverWait;
34+
import org.slf4j.Logger;
3535

3636
import io.github.bonigarcia.wdm.WebDriverManager;
3737

3838
class AddExtensionEdgeJupiterTest {
3939

40+
static final Logger log = getLogger(lookup().lookupClass());
41+
4042
WebDriver driver;
4143

4244
@BeforeEach
4345
void setup() throws URISyntaxException {
44-
Path extension = Paths
45-
.get(ClassLoader.getSystemResource("shade_dark_mode.crx").toURI());
46+
Path extension = Paths.get(
47+
ClassLoader.getSystemResource("shade_dark_mode.crx").toURI());
4648
EdgeOptions options = new EdgeOptions();
4749
options.addExtensions(extension.toFile());
4850

@@ -60,11 +62,9 @@ void teardown() throws InterruptedException {
6062
@Test
6163
void testAddExtension() {
6264
driver.get("https://bonigarcia.dev/selenium-webdriver-java/");
63-
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
64-
6565
WebElement body = driver.findElement(By.tagName("body"));
66-
String whiteRgba = "rgba(255, 255, 255, 1)";
67-
wait.until(not(attributeToBe(body, "background-color", whiteRgba)));
66+
log.debug("Background color is {}"
67+
+ body.getCssValue("background-color"));
6868
}
6969

7070
}

selenium-webdriver-testng/src/test/java/io/github/bonigarcia/webdriver/testng/ch05/caps/extensions/AddExtensionChromeNGTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*/
1717
package io.github.bonigarcia.webdriver.testng.ch05.caps.extensions;
1818

19-
import static org.openqa.selenium.support.ui.ExpectedConditions.attributeToBe;
20-
import static org.openqa.selenium.support.ui.ExpectedConditions.not;
19+
import static java.lang.invoke.MethodHandles.lookup;
20+
import static org.slf4j.LoggerFactory.getLogger;
2121

2222
import java.net.URISyntaxException;
2323
import java.nio.file.Path;
@@ -28,7 +28,7 @@
2828
import org.openqa.selenium.WebDriver;
2929
import org.openqa.selenium.WebElement;
3030
import org.openqa.selenium.chrome.ChromeOptions;
31-
import org.openqa.selenium.support.ui.WebDriverWait;
31+
import org.slf4j.Logger;
3232
import org.testng.annotations.AfterMethod;
3333
import org.testng.annotations.BeforeMethod;
3434
import org.testng.annotations.Test;
@@ -37,12 +37,14 @@
3737

3838
public class AddExtensionChromeNGTest {
3939

40+
static final Logger log = getLogger(lookup().lookupClass());
41+
4042
WebDriver driver;
4143

4244
@BeforeMethod
4345
public void setup() throws URISyntaxException {
44-
Path extension = Paths
45-
.get(ClassLoader.getSystemResource("shade_dark_mode.crx").toURI());
46+
Path extension = Paths.get(
47+
ClassLoader.getSystemResource("shade_dark_mode.crx").toURI());
4648
ChromeOptions options = new ChromeOptions();
4749
options.addExtensions(extension.toFile());
4850

@@ -60,11 +62,9 @@ public void teardown() throws InterruptedException {
6062
@Test
6163
public void testAddExtension() {
6264
driver.get("https://bonigarcia.dev/selenium-webdriver-java/");
63-
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
64-
6565
WebElement body = driver.findElement(By.tagName("body"));
66-
String whiteRgba = "rgba(255, 255, 255, 1)";
67-
wait.until(not(attributeToBe(body, "background-color", whiteRgba)));
66+
log.debug("Background color is {}"
67+
+ body.getCssValue("background-color"));
6868
}
6969

7070
}

selenium-webdriver-testng/src/test/java/io/github/bonigarcia/webdriver/testng/ch05/caps/extensions/AddExtensionEdgeNGTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*/
1717
package io.github.bonigarcia.webdriver.testng.ch05.caps.extensions;
1818

19-
import static org.openqa.selenium.support.ui.ExpectedConditions.attributeToBe;
20-
import static org.openqa.selenium.support.ui.ExpectedConditions.not;
19+
import static java.lang.invoke.MethodHandles.lookup;
20+
import static org.slf4j.LoggerFactory.getLogger;
2121

2222
import java.net.URISyntaxException;
2323
import java.nio.file.Path;
@@ -28,7 +28,7 @@
2828
import org.openqa.selenium.WebDriver;
2929
import org.openqa.selenium.WebElement;
3030
import org.openqa.selenium.edge.EdgeOptions;
31-
import org.openqa.selenium.support.ui.WebDriverWait;
31+
import org.slf4j.Logger;
3232
import org.testng.annotations.AfterMethod;
3333
import org.testng.annotations.BeforeMethod;
3434
import org.testng.annotations.Test;
@@ -37,12 +37,14 @@
3737

3838
public class AddExtensionEdgeNGTest {
3939

40+
static final Logger log = getLogger(lookup().lookupClass());
41+
4042
WebDriver driver;
4143

4244
@BeforeMethod
4345
public void setup() throws URISyntaxException {
44-
Path extension = Paths
45-
.get(ClassLoader.getSystemResource("shade_dark_mode.crx").toURI());
46+
Path extension = Paths.get(
47+
ClassLoader.getSystemResource("shade_dark_mode.crx").toURI());
4648
EdgeOptions options = new EdgeOptions();
4749
options.addExtensions(extension.toFile());
4850

@@ -60,11 +62,9 @@ public void teardown() throws InterruptedException {
6062
@Test
6163
public void testAddExtension() {
6264
driver.get("https://bonigarcia.dev/selenium-webdriver-java/");
63-
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
64-
6565
WebElement body = driver.findElement(By.tagName("body"));
66-
String whiteRgba = "rgba(255, 255, 255, 1)";
67-
wait.until(not(attributeToBe(body, "background-color", whiteRgba)));
66+
log.debug("Background color is {}"
67+
+ body.getCssValue("background-color"));
6868
}
6969

7070
}

0 commit comments

Comments
 (0)