Skip to content

Commit 586e5f2

Browse files
committed
Updated dependencies to Playwright 1.57.0 and JUnit 6.0.1
1 parent 9f7fb8a commit 586e5f2

File tree

4 files changed

+61
-67
lines changed

4 files changed

+61
-67
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818
<dependency>
1919
<groupId>com.microsoft.playwright</groupId>
2020
<artifactId>playwright</artifactId>
21-
<version>1.48.0</version>
21+
<version>1.57.0</version>
2222
<scope>test</scope>
2323
</dependency>
2424
<dependency>
2525
<groupId>org.junit.jupiter</groupId>
2626
<artifactId>junit-jupiter</artifactId>
27-
<version>5.11.1</version>
27+
<version>6.0.1</version>
2828
<scope>test</scope>
2929
</dependency>
3030
<dependency>
3131
<groupId>org.assertj</groupId>
3232
<artifactId>assertj-core</artifactId>
33-
<version>3.26.3</version>
33+
<version>3.27.6</version>
3434
</dependency>
3535
<dependency>
3636
<groupId>com.deque.html.axe-core</groupId>

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,5 @@ void chainedAssertionsOnProductSearchResults() {
8787
Locator searchField = page.getByPlaceholder("Search");
8888
searchField.fill("Pliers");
8989
searchField.press("Enter");
90-
91-
9290
}
93-
94-
9591
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static void setUpBrowser() {
3232
playwright = Playwright.create();
3333
playwright.selectors().setTestIdAttribute("data-test");
3434
browser = playwright.chromium().launch(
35-
new BrowserType.LaunchOptions().setHeadless(true)
35+
new BrowserType.LaunchOptions().setHeadless(false)
3636
.setArgs(Arrays.asList("--no-sandbox", "--disable-extensions", "--disable-gpu"))
3737
);
3838
}
@@ -132,6 +132,7 @@ void allProductPricesShouldBeCorrectValues() {
132132
void shouldSortInAlphabeticalOrder() {
133133
page.getByLabel("Sort").selectOption("Name (A - Z)");
134134
page.waitForLoadState(LoadState.NETWORKIDLE);
135+
page.waitForTimeout(500);
135136

136137
List<String> productNames = page.getByTestId("product-name").allTextContents();
137138

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

Lines changed: 56 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
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;
6+
import com.microsoft.playwright.junit.UsePlaywright;
57
import com.microsoft.playwright.options.AriaRole;
68
import com.microsoft.playwright.options.LoadState;
79
import com.microsoft.playwright.options.SelectOption;
@@ -15,7 +17,8 @@
1517

1618
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
1719

18-
@Execution(ExecutionMode.SAME_THREAD)
20+
@UsePlaywright
21+
@Disabled
1922
public class PlaywrightLocatorsTest {
2023

2124
protected static Playwright playwright;
@@ -55,20 +58,20 @@ static void tearDown() {
5558
class LocatingElementsUsingCSS {
5659

5760
@BeforeEach
58-
void openContactPage() {
61+
void openContactPage(Page page) {
5962
page.navigate("https://practicesoftwaretesting.com/contact");
6063
}
6164

6265
@DisplayName("By id")
6366
@Test
64-
void locateTheFirstNameFieldByID() {
67+
void locateTheFirstNameFieldByID(Page page) {
6568
page.locator("#first_name").fill("Sarah-Jane");
6669
assertThat(page.locator("#first_name")).hasValue("Sarah-Jane");
6770
}
6871

6972
@DisplayName("By CSS class")
7073
@Test
71-
void locateTheSendButtonByCssClass() {
74+
void locateTheSendButtonByCssClass(Page page) {
7275
page.locator("#first_name").fill("Sarah-Jane");
7376
page.locator(".btnSubmit").click();
7477
List<String> alertMessages = page.locator(".alert").allTextContents();
@@ -78,7 +81,7 @@ void locateTheSendButtonByCssClass() {
7881

7982
@DisplayName("By attribute")
8083
@Test
81-
void locateTheSendButtonByAttribute() {
84+
void locateTheSendButtonByAttribute(Page page) {
8285
page.locator("input[placeholder='Your last name *']").fill("Smith");
8386
assertThat(page.locator("#last_name")).hasValue("Smith");
8487
}
@@ -89,14 +92,14 @@ void locateTheSendButtonByAttribute() {
8992
class LocatingElementsByTextUsingCSS {
9093

9194
@BeforeEach
92-
void openContactPage() {
95+
void openContactPage(Page page) {
9396
page.navigate("https://practicesoftwaretesting.com/contact");
9497
}
9598

9699
// :has-text matches any element containing specified text somewhere inside.
97100
@DisplayName("Using :has-text")
98101
@Test
99-
void locateTheSendButtonByText() {
102+
void locateTheSendButtonByText(Page page) {
100103
page.locator("#first_name").fill("Sarah-Jane");
101104
page.locator("#last_name").fill("Smith");
102105
page.locator("input:has-text('Send')").click();
@@ -105,7 +108,7 @@ void locateTheSendButtonByText() {
105108
// :text matches the smallest element containing specified text.
106109
@DisplayName("Using :text")
107110
@Test
108-
void locateAProductItemByText() {
111+
void locateAProductItemByText(Page page) {
109112
page.locator(".navbar :text('Home')").click();
110113
page.locator(".card :text('Bolt')").click();
111114
assertThat(page.locator("[data-test=product-name]")).hasText("Bolt Cutters");
@@ -114,7 +117,7 @@ void locateAProductItemByText() {
114117
// Exact matches
115118
@DisplayName("Using :text-is")
116119
@Test
117-
void locateAProductItemByTextIs() {
120+
void locateAProductItemByTextIs(Page page) {
118121
page.locator(".navbar :text('Home')").click();
119122
page.locator(".card :text-is('Bolt Cutters')").click();
120123
assertThat(page.locator("[data-test=product-name]")).hasText("Bolt Cutters");
@@ -123,7 +126,7 @@ void locateAProductItemByTextIs() {
123126
// matching with regular expressions
124127
@DisplayName("Using :text-matches")
125128
@Test
126-
void locateAProductItemByTextMatches() {
129+
void locateAProductItemByTextMatches(Page page) {
127130
page.locator(".navbar :text('Home')").click();
128131
page.locator(".card :text-matches('Bolt \\\\w+')").click();
129132
assertThat(page.locator("[data-test=product-name]")).hasText("Bolt Cutters");
@@ -134,20 +137,20 @@ void locateAProductItemByTextMatches() {
134137
@Nested
135138
class LocatingVisibleElements {
136139
@BeforeEach
137-
void openContactPage() {
138-
openPage();
140+
void openContactPage(Page page) {
141+
openPage(page);
139142
}
140143

141144
@DisplayName("Finding visible and invisible elements")
142145
@Test
143-
void locateVisibleAndInvisibleItems() {
146+
void locateVisibleAndInvisibleItems(Page page) {
144147
int dropdownItems = page.locator(".dropdown-item").count();
145148
Assertions.assertTrue(dropdownItems > 0);
146149
}
147150

148151
@DisplayName("Finding only visible elements")
149152
@Test
150-
void locateVisibleItems() {
153+
void locateVisibleItems(Page page) {
151154
int dropdownItems = page.locator(".dropdown-item:visible").count();
152155
Assertions.assertTrue(dropdownItems == 0);
153156
}
@@ -159,7 +162,7 @@ class LocatingElementsByRole {
159162

160163
@DisplayName("Using the BUTTON role")
161164
@Test
162-
void byButton() {
165+
void byButton(Page page) {
163166
page.navigate("https://practicesoftwaretesting.com/contact");
164167

165168

@@ -173,8 +176,8 @@ void byButton() {
173176

174177
@DisplayName("Using the HEADING role")
175178
@Test
176-
void byHeaderRole() {
177-
openPage();
179+
void byHeaderRole(Page page) {
180+
openPage(page);
178181

179182
page.locator("#search-query").fill("Pliers");
180183

@@ -191,25 +194,25 @@ void byHeaderRole() {
191194

192195
@DisplayName("Using the HEADING role and level")
193196
@Test
194-
void byHeaderRoleLevel() {
195-
openPage();
196-
197-
List<String> level4Headings
198-
= page.getByRole(AriaRole.HEADING,
199-
new Page.GetByRoleOptions()
200-
.setName("Pliers")
201-
.setLevel(5))
202-
.allTextContents();
197+
void byHeaderRoleLevel(Page page) {
198+
openPage(page);
199+
200+
Locator headings = page.getByRole(
201+
AriaRole.HEADING,
202+
new Page.GetByRoleOptions().setLevel(5)
203+
);
204+
assertThat(headings.first()).isVisible();
205+
206+
List<String> level4Headings = headings.allTextContents();
203207

204208
org.assertj.core.api.Assertions.assertThat(level4Headings).isNotEmpty();
205209
}
206210

207211
@DisplayName("Identifying checkboxes")
208212
@Test
209-
void byCheckboxes() {
210-
playwright.selectors().setTestIdAttribute("data-test");
213+
void byCheckboxes(Page page) {
211214

212-
openPage();
215+
openPage(page);
213216
page.getByLabel("Hammer").click();
214217
page.getByLabel("Chisels").click();
215218
page.getByLabel("Wrench").click();
@@ -241,7 +244,7 @@ class LocatingElementsByPlaceholdersAndLabels {
241244

242245
@DisplayName("Using a label")
243246
@Test
244-
void byLabel() {
247+
void byLabel(Page page) {
245248
page.navigate("https://practicesoftwaretesting.com/contact");
246249

247250
page.getByLabel("First name").fill("Obi-Wan");
@@ -254,7 +257,7 @@ void byLabel() {
254257

255258
@DisplayName("Using a placeholder text")
256259
@Test
257-
void byPlaceholder() {
260+
void byPlaceholder(Page page) {
258261
page.navigate("https://practicesoftwaretesting.com/contact");
259262

260263
page.getByPlaceholder("Your first name").fill("Obi-Wan");
@@ -272,29 +275,29 @@ void byPlaceholder() {
272275
class LocatingElementsByText {
273276

274277
@BeforeEach
275-
void openTheCatalogPage() {
276-
openPage();
278+
void openTheCatalogPage(Page page) {
279+
openPage(page);
277280
}
278281

279282
@DisplayName("Locating an element by text contents")
280283
@Test
281-
void byText() {
284+
void byText(Page page) {
282285
page.getByText("Bolt Cutters").click();
283286

284287
PlaywrightAssertions.assertThat(page.getByText("MightyCraft Hardware")).isVisible();
285288
}
286289

287290
@DisplayName("Using alt text")
288291
@Test
289-
void byAltText() {
292+
void byAltText(Page page) {
290293
page.getByAltText("Combination Pliers").click();
291294

292295
PlaywrightAssertions.assertThat(page.getByText("ForgeFlex Tools")).isVisible();
293296
}
294297

295298
@DisplayName("Using title")
296299
@Test
297-
void byTitle() {
300+
void byTitle(Page page) {
298301
page.getByAltText("Combination Pliers").click();
299302

300303
page.getByTitle("Practice Software Testing - Toolshop").click();
@@ -305,17 +308,10 @@ void byTitle() {
305308
@Nested
306309
class LocatingElementsByTestID {
307310

308-
@BeforeAll
309-
static void setTestId() {
310-
playwright.selectors().setTestIdAttribute("data-test");
311-
}
312-
313311
@DisplayName("Using a custom data-test field")
314312
@Test
315-
void byTestId() {
316-
openPage();
317-
318-
playwright.selectors().setTestIdAttribute("data-test");
313+
void byTestId(Page page) {
314+
openPage(page);
319315

320316
page.getByTestId("search-query").fill("Pliers");
321317
page.getByTestId("search-submit").click();
@@ -334,8 +330,8 @@ static void setTestId() {
334330

335331
@DisplayName("Using roles")
336332
@Test
337-
void locatingAMenuItemUsingRoles() {
338-
openPage();
333+
void locatingAMenuItemUsingRoles(Page page) {
334+
openPage(page);
339335

340336
page.getByRole(AriaRole.MENUBAR, new Page.GetByRoleOptions().setName("Main Menu"))
341337
.getByRole(AriaRole.MENUITEM, new Locator.GetByRoleOptions().setName("Home"))
@@ -344,8 +340,8 @@ void locatingAMenuItemUsingRoles() {
344340

345341
@DisplayName("Using roles with other strategies")
346342
@Test
347-
void locatingAMenuItemUsingRolesAndOtherStrategies() {
348-
openPage();
343+
void locatingAMenuItemUsingRolesAndOtherStrategies(Page page) {
344+
openPage(page);
349345

350346
page.getByRole(AriaRole.MENUBAR, new Page.GetByRoleOptions().setName("Main Menu"))
351347
.getByText("Home")
@@ -354,8 +350,8 @@ void locatingAMenuItemUsingRolesAndOtherStrategies() {
354350

355351
@DisplayName("filtering locators by text")
356352
@Test
357-
void filteringMenuItems() {
358-
openPage();
353+
void filteringMenuItems(Page page) {
354+
openPage(page);
359355

360356
page.getByRole(AriaRole.MENUBAR, new Page.GetByRoleOptions().setName("Main Menu"))
361357
.getByText("Categories")
@@ -376,21 +372,22 @@ void filteringMenuItems() {
376372

377373
@DisplayName("filtering locators by locator")
378374
@Test
379-
void filteringMenuItemsByLocator() {
380-
openPage();;
375+
void filteringMenuItemsByLocator(Page page) {
376+
openPage(page);
381377

382-
List<String> allProducts = page.locator(".card")
378+
Locator allProducts = page.locator(".card")
383379
.filter(new Locator.FilterOptions().setHas(page.getByText("Out of stock")))
384-
.getByTestId("product-name")
385-
.allTextContents();
380+
.getByTestId("product-name");
381+
382+
assertThat(allProducts.first()).isVisible();
383+
List<String> allProductNames = allProducts.allTextContents();
386384

387-
org.assertj.core.api.Assertions.assertThat(allProducts).hasSize(1)
385+
org.assertj.core.api.Assertions.assertThat(allProductNames).hasSize(1)
388386
.allMatch(name -> name.contains("Long Nose Pliers"));
389387
}
390388
}
391389

392-
private void openPage() {
390+
private void openPage(Page page) {
393391
page.navigate("https://practicesoftwaretesting.com");
394-
page.waitForLoadState(LoadState.NETWORKIDLE);
395392
}
396393
}

0 commit comments

Comments
 (0)