File tree Expand file tree Collapse file tree 4 files changed +28
-16
lines changed
selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch09/cucumber
selenium-webdriver-junit5-seljup/src/test/java/io/github/bonigarcia/webdriver/seljup/ch09/cucumber
selenium-webdriver-junit5/src/test/java/io/github/bonigarcia/webdriver/jupiter/ch09/cucumber
selenium-webdriver-testng/src/test/java/io/github/bonigarcia/webdriver/testng/ch09/cucumber Expand file tree Collapse file tree 4 files changed +28
-16
lines changed Original file line number Diff line number Diff line change 1616 */
1717package io .github .bonigarcia .webdriver .junit4 .ch09 .cucumber ;
1818
19- import static org . assertj . core . api . Assertions . assertThat ;
19+ import java . time . Duration ;
2020
2121import org .openqa .selenium .By ;
2222import org .openqa .selenium .WebDriver ;
23+ import org .openqa .selenium .support .ui .ExpectedConditions ;
24+ import org .openqa .selenium .support .ui .WebDriverWait ;
2325
2426import io .cucumber .java .en .And ;
2527import io .cucumber .java .en .Given ;
@@ -45,7 +47,6 @@ public void iNavigateTo(String url) {
4547 public void iLogin (String username , String password ) {
4648 driver .findElement (By .id ("username" )).sendKeys (username );
4749 driver .findElement (By .id ("password" )).sendKeys (password );
48-
4950 }
5051
5152 @ And ("I click Submit" )
@@ -56,8 +57,10 @@ public void iPressEnter() {
5657 @ Then ("I should see the message {string}" )
5758 public void iShouldSee (String result ) {
5859 try {
59- String bodyText = driver .findElement (By .tagName ("body" )).getText ();
60- assertThat (bodyText ).contains (result );
60+ WebDriverWait wait = new WebDriverWait (driver ,
61+ Duration .ofSeconds (10 ));
62+ wait .until (ExpectedConditions .textToBePresentInElementLocated (
63+ By .tagName ("body" ), result ));
6164 } finally {
6265 driver .quit ();
6366 }
Original file line number Diff line number Diff line change 1616 */
1717package io .github .bonigarcia .webdriver .seljup .ch09 .cucumber ;
1818
19- import static org . assertj . core . api . Assertions . assertThat ;
19+ import java . time . Duration ;
2020
2121import org .openqa .selenium .By ;
2222import org .openqa .selenium .WebDriver ;
23+ import org .openqa .selenium .support .ui .ExpectedConditions ;
24+ import org .openqa .selenium .support .ui .WebDriverWait ;
2325
2426import io .cucumber .java .en .And ;
2527import io .cucumber .java .en .Given ;
@@ -45,7 +47,6 @@ public void iNavigateTo(String url) {
4547 public void iLogin (String username , String password ) {
4648 driver .findElement (By .id ("username" )).sendKeys (username );
4749 driver .findElement (By .id ("password" )).sendKeys (password );
48-
4950 }
5051
5152 @ And ("I click Submit" )
@@ -56,8 +57,10 @@ public void iPressEnter() {
5657 @ Then ("I should see the message {string}" )
5758 public void iShouldSee (String result ) {
5859 try {
59- String bodyText = driver .findElement (By .tagName ("body" )).getText ();
60- assertThat (bodyText ).contains (result );
60+ WebDriverWait wait = new WebDriverWait (driver ,
61+ Duration .ofSeconds (10 ));
62+ wait .until (ExpectedConditions .textToBePresentInElementLocated (
63+ By .tagName ("body" ), result ));
6164 } finally {
6265 driver .quit ();
6366 }
Original file line number Diff line number Diff line change 1616 */
1717package io .github .bonigarcia .webdriver .jupiter .ch09 .cucumber ;
1818
19- import static org . assertj . core . api . Assertions . assertThat ;
19+ import java . time . Duration ;
2020
2121import org .openqa .selenium .By ;
2222import org .openqa .selenium .WebDriver ;
23+ import org .openqa .selenium .support .ui .ExpectedConditions ;
24+ import org .openqa .selenium .support .ui .WebDriverWait ;
2325
2426import io .cucumber .java .en .And ;
2527import io .cucumber .java .en .Given ;
@@ -45,7 +47,6 @@ public void iNavigateTo(String url) {
4547 public void iLogin (String username , String password ) {
4648 driver .findElement (By .id ("username" )).sendKeys (username );
4749 driver .findElement (By .id ("password" )).sendKeys (password );
48-
4950 }
5051
5152 @ And ("I click Submit" )
@@ -56,8 +57,10 @@ public void iPressEnter() {
5657 @ Then ("I should see the message {string}" )
5758 public void iShouldSee (String result ) {
5859 try {
59- String bodyText = driver .findElement (By .tagName ("body" )).getText ();
60- assertThat (bodyText ).contains (result );
60+ WebDriverWait wait = new WebDriverWait (driver ,
61+ Duration .ofSeconds (10 ));
62+ wait .until (ExpectedConditions .textToBePresentInElementLocated (
63+ By .tagName ("body" ), result ));
6164 } finally {
6265 driver .quit ();
6366 }
Original file line number Diff line number Diff line change 1616 */
1717package io .github .bonigarcia .webdriver .testng .ch09 .cucumber ;
1818
19- import static org . assertj . core . api . Assertions . assertThat ;
19+ import java . time . Duration ;
2020
2121import org .openqa .selenium .By ;
2222import org .openqa .selenium .WebDriver ;
23+ import org .openqa .selenium .support .ui .ExpectedConditions ;
24+ import org .openqa .selenium .support .ui .WebDriverWait ;
2325
2426import io .cucumber .java .en .And ;
2527import io .cucumber .java .en .Given ;
@@ -45,7 +47,6 @@ public void iNavigateTo(String url) {
4547 public void iLogin (String username , String password ) {
4648 driver .findElement (By .id ("username" )).sendKeys (username );
4749 driver .findElement (By .id ("password" )).sendKeys (password );
48-
4950 }
5051
5152 @ And ("I click Submit" )
@@ -56,8 +57,10 @@ public void iPressEnter() {
5657 @ Then ("I should see the message {string}" )
5758 public void iShouldSee (String result ) {
5859 try {
59- String bodyText = driver .findElement (By .tagName ("body" )).getText ();
60- assertThat (bodyText ).contains (result );
60+ WebDriverWait wait = new WebDriverWait (driver ,
61+ Duration .ofSeconds (10 ));
62+ wait .until (ExpectedConditions .textToBePresentInElementLocated (
63+ By .tagName ("body" ), result ));
6164 } finally {
6265 driver .quit ();
6366 }
You can’t perform that action at this time.
0 commit comments