Skip to content

Commit 7486fac

Browse files
committed
Include explicit wait in har creator tests
1 parent ae318ce commit 7486fac

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch09/performance/HarCreatorJUnit4Test.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
*/
1717
package io.github.bonigarcia.webdriver.junit4.ch09.performance;
1818

19-
import static org.assertj.core.api.Assertions.assertThat;
20-
2119
import java.io.File;
2220
import java.io.IOException;
21+
import java.time.Duration;
2322

2423
import org.junit.After;
2524
import org.junit.Before;
@@ -28,6 +27,8 @@
2827
import org.openqa.selenium.Proxy;
2928
import org.openqa.selenium.WebDriver;
3029
import org.openqa.selenium.chrome.ChromeOptions;
30+
import org.openqa.selenium.support.ui.ExpectedConditions;
31+
import org.openqa.selenium.support.ui.WebDriverWait;
3132

3233
import io.github.bonigarcia.wdm.WebDriverManager;
3334
import 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
}

selenium-webdriver-junit5-seljup/src/test/java/io/github/bonigarcia/webdriver/seljup/ch09/performance/HarCreatorSelJupTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
*/
1717
package io.github.bonigarcia.webdriver.seljup.ch09.performance;
1818

19-
import static org.assertj.core.api.Assertions.assertThat;
20-
2119
import java.io.File;
2220
import java.io.IOException;
21+
import java.time.Duration;
2322

2423
import org.junit.jupiter.api.AfterEach;
2524
import org.junit.jupiter.api.BeforeEach;
@@ -30,6 +29,8 @@
3029
import org.openqa.selenium.WebDriver;
3130
import org.openqa.selenium.chrome.ChromeDriver;
3231
import org.openqa.selenium.chrome.ChromeOptions;
32+
import org.openqa.selenium.support.ui.ExpectedConditions;
33+
import org.openqa.selenium.support.ui.WebDriverWait;
3334

3435
import io.github.bonigarcia.seljup.Options;
3536
import 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
}

selenium-webdriver-junit5/src/test/java/io/github/bonigarcia/webdriver/jupiter/ch09/performance/HarCreatorJupiterTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
*/
1717
package io.github.bonigarcia.webdriver.jupiter.ch09.performance;
1818

19-
import static org.assertj.core.api.Assertions.assertThat;
20-
2119
import java.io.File;
2220
import java.io.IOException;
21+
import java.time.Duration;
2322

2423
import org.junit.jupiter.api.AfterEach;
2524
import org.junit.jupiter.api.BeforeEach;
@@ -28,6 +27,8 @@
2827
import org.openqa.selenium.Proxy;
2928
import org.openqa.selenium.WebDriver;
3029
import org.openqa.selenium.chrome.ChromeOptions;
30+
import org.openqa.selenium.support.ui.ExpectedConditions;
31+
import org.openqa.selenium.support.ui.WebDriverWait;
3132

3233
import io.github.bonigarcia.wdm.WebDriverManager;
3334
import 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
}

selenium-webdriver-testng/src/test/java/io/github/bonigarcia/webdriver/testng/ch09/performance/HarCreatorNGTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616
*/
1717
package io.github.bonigarcia.webdriver.testng.ch09.performance;
1818

19-
import static org.assertj.core.api.Assertions.assertThat;
20-
2119
import java.io.File;
2220
import java.io.IOException;
21+
import java.time.Duration;
2322

2423
import org.openqa.selenium.By;
2524
import org.openqa.selenium.Proxy;
2625
import org.openqa.selenium.WebDriver;
2726
import org.openqa.selenium.chrome.ChromeOptions;
27+
import org.openqa.selenium.support.ui.ExpectedConditions;
28+
import org.openqa.selenium.support.ui.WebDriverWait;
2829
import org.testng.annotations.AfterMethod;
2930
import org.testng.annotations.BeforeMethod;
3031
import 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
}

0 commit comments

Comments
 (0)