Skip to content

Commit d19e055

Browse files
committed
Added some extra conditional waits to reduce flakyness for some of the tests
1 parent 343ae1e commit d19e055

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/test/java/com/serenitydojo/playwright/PlaywrightLocatorsTest.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.serenitydojo.playwright;
22

33
import com.microsoft.playwright.*;
4+
import com.microsoft.playwright.assertions.LocatorAssertions;
45
import com.microsoft.playwright.assertions.PlaywrightAssertions;
56
import com.microsoft.playwright.options.AriaRole;
67
import com.microsoft.playwright.options.LoadState;
@@ -194,12 +195,13 @@ void byHeaderRole() {
194195
void byHeaderRoleLevel() {
195196
openPage();
196197

197-
List<String> level4Headings
198-
= page.getByRole(AriaRole.HEADING,
199-
new Page.GetByRoleOptions()
200-
.setName("Pliers")
201-
.setLevel(5))
202-
.allTextContents();
198+
Locator headings = page.getByRole(
199+
AriaRole.HEADING,
200+
new Page.GetByRoleOptions().setLevel(5)
201+
);
202+
assertThat(headings.first()).isVisible();
203+
204+
List<String> level4Headings = headings.allTextContents();
203205

204206
org.assertj.core.api.Assertions.assertThat(level4Headings).isNotEmpty();
205207
}
@@ -379,12 +381,14 @@ void filteringMenuItems() {
379381
void filteringMenuItemsByLocator() {
380382
openPage();;
381383

382-
List<String> allProducts = page.locator(".card")
384+
Locator allProducts = page.locator(".card")
383385
.filter(new Locator.FilterOptions().setHas(page.getByText("Out of stock")))
384-
.getByTestId("product-name")
385-
.allTextContents();
386+
.getByTestId("product-name");
387+
388+
assertThat(allProducts.first()).isVisible();
389+
List<String> allProductNames = allProducts.allTextContents();
386390

387-
org.assertj.core.api.Assertions.assertThat(allProducts).hasSize(1)
391+
org.assertj.core.api.Assertions.assertThat(allProductNames).hasSize(1)
388392
.allMatch(name -> name.contains("Long Nose Pliers"));
389393
}
390394
}

0 commit comments

Comments
 (0)