File tree Expand file tree Collapse file tree 4 files changed +24
-16
lines changed
selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch09/performance
selenium-webdriver-junit5-seljup/src/test/java/io/github/bonigarcia/webdriver/seljup/ch09/performance
selenium-webdriver-junit5/src/test/java/io/github/bonigarcia/webdriver/jupiter/ch09/performance
selenium-webdriver-testng/src/test/java/io/github/bonigarcia/webdriver/testng/ch09/performance Expand file tree Collapse file tree 4 files changed +24
-16
lines changed Original file line number Diff line number Diff line change 1616 */
1717package io .github .bonigarcia .webdriver .junit4 .ch09 .performance ;
1818
19- import static org .assertj .core .api .Assertions .assertThat ;
20-
2119import java .io .File ;
2220import java .io .IOException ;
21+ import java .time .Duration ;
2322
2423import org .junit .After ;
2524import org .junit .Before ;
2827import org .openqa .selenium .Proxy ;
2928import org .openqa .selenium .WebDriver ;
3029import org .openqa .selenium .chrome .ChromeOptions ;
30+ import org .openqa .selenium .support .ui .ExpectedConditions ;
31+ import org .openqa .selenium .support .ui .WebDriverWait ;
3132
3233import io .github .bonigarcia .wdm .WebDriverManager ;
3334import net .lightbody .bmp .BrowserMobProxy ;
@@ -77,8 +78,9 @@ public void testHarCreator() {
7778 driver .findElement (By .id ("password" )).sendKeys ("user" );
7879 driver .findElement (By .cssSelector ("button" )).click ();
7980
80- String bodyText = driver .findElement (By .tagName ("body" )).getText ();
81- assertThat (bodyText ).contains ("Login successful" );
81+ WebDriverWait wait = new WebDriverWait (driver , Duration .ofSeconds (10 ));
82+ wait .until (ExpectedConditions .textToBePresentInElementLocated (
83+ By .tagName ("body" ), "Login successful" ));
8284 }
8385
8486}
Original file line number Diff line number Diff line change 1616 */
1717package io .github .bonigarcia .webdriver .seljup .ch09 .performance ;
1818
19- import static org .assertj .core .api .Assertions .assertThat ;
20-
2119import java .io .File ;
2220import java .io .IOException ;
21+ import java .time .Duration ;
2322
2423import org .junit .jupiter .api .AfterEach ;
2524import org .junit .jupiter .api .BeforeEach ;
3029import org .openqa .selenium .WebDriver ;
3130import org .openqa .selenium .chrome .ChromeDriver ;
3231import org .openqa .selenium .chrome .ChromeOptions ;
32+ import org .openqa .selenium .support .ui .ExpectedConditions ;
33+ import org .openqa .selenium .support .ui .WebDriverWait ;
3334
3435import io .github .bonigarcia .seljup .Options ;
3536import io .github .bonigarcia .seljup .SeleniumJupiter ;
@@ -80,8 +81,9 @@ void testHarCreator(ChromeDriver driver) {
8081 driver .findElement (By .id ("password" )).sendKeys ("user" );
8182 driver .findElement (By .cssSelector ("button" )).click ();
8283
83- String bodyText = driver .findElement (By .tagName ("body" )).getText ();
84- assertThat (bodyText ).contains ("Login successful" );
84+ WebDriverWait wait = new WebDriverWait (driver , Duration .ofSeconds (10 ));
85+ wait .until (ExpectedConditions .textToBePresentInElementLocated (
86+ By .tagName ("body" ), "Login successful" ));
8587 }
8688
8789}
Original file line number Diff line number Diff line change 1616 */
1717package io .github .bonigarcia .webdriver .jupiter .ch09 .performance ;
1818
19- import static org .assertj .core .api .Assertions .assertThat ;
20-
2119import java .io .File ;
2220import java .io .IOException ;
21+ import java .time .Duration ;
2322
2423import org .junit .jupiter .api .AfterEach ;
2524import org .junit .jupiter .api .BeforeEach ;
2827import org .openqa .selenium .Proxy ;
2928import org .openqa .selenium .WebDriver ;
3029import org .openqa .selenium .chrome .ChromeOptions ;
30+ import org .openqa .selenium .support .ui .ExpectedConditions ;
31+ import org .openqa .selenium .support .ui .WebDriverWait ;
3132
3233import io .github .bonigarcia .wdm .WebDriverManager ;
3334import net .lightbody .bmp .BrowserMobProxy ;
@@ -77,8 +78,9 @@ void testHarCreator() {
7778 driver .findElement (By .id ("password" )).sendKeys ("user" );
7879 driver .findElement (By .cssSelector ("button" )).click ();
7980
80- String bodyText = driver .findElement (By .tagName ("body" )).getText ();
81- assertThat (bodyText ).contains ("Login successful" );
81+ WebDriverWait wait = new WebDriverWait (driver , Duration .ofSeconds (10 ));
82+ wait .until (ExpectedConditions .textToBePresentInElementLocated (
83+ By .tagName ("body" ), "Login successful" ));
8284 }
8385
8486}
Original file line number Diff line number Diff line change 1616 */
1717package io .github .bonigarcia .webdriver .testng .ch09 .performance ;
1818
19- import static org .assertj .core .api .Assertions .assertThat ;
20-
2119import java .io .File ;
2220import java .io .IOException ;
21+ import java .time .Duration ;
2322
2423import org .openqa .selenium .By ;
2524import org .openqa .selenium .Proxy ;
2625import org .openqa .selenium .WebDriver ;
2726import org .openqa .selenium .chrome .ChromeOptions ;
27+ import org .openqa .selenium .support .ui .ExpectedConditions ;
28+ import org .openqa .selenium .support .ui .WebDriverWait ;
2829import org .testng .annotations .AfterMethod ;
2930import org .testng .annotations .BeforeMethod ;
3031import org .testng .annotations .Test ;
@@ -77,8 +78,9 @@ public void testHarCreator() {
7778 driver .findElement (By .id ("password" )).sendKeys ("user" );
7879 driver .findElement (By .cssSelector ("button" )).click ();
7980
80- String bodyText = driver .findElement (By .tagName ("body" )).getText ();
81- assertThat (bodyText ).contains ("Login successful" );
81+ WebDriverWait wait = new WebDriverWait (driver , Duration .ofSeconds (10 ));
82+ wait .until (ExpectedConditions .textToBePresentInElementLocated (
83+ By .tagName ("body" ), "Login successful" ));
8284 }
8385
8486}
You can’t perform that action at this time.
0 commit comments