|
1 | 1 | package com.serenitydojo.playwright; |
2 | 2 |
|
3 | | -import com.microsoft.playwright.Browser; |
4 | 3 | import com.microsoft.playwright.Page; |
5 | | -import com.microsoft.playwright.Playwright; |
6 | | -import com.microsoft.playwright.impl.AssertionsTimeout; |
| 4 | +import com.microsoft.playwright.junit.UsePlaywright; |
7 | 5 | import org.junit.jupiter.api.Assertions; |
8 | 6 | import org.junit.jupiter.api.Test; |
9 | 7 |
|
| 8 | +@UsePlaywright |
10 | 9 | public class ASimplePlaywrightTest { |
11 | 10 |
|
12 | 11 | @Test |
13 | | - void shouldShowThePageTitle() { |
14 | | - Playwright playwright = Playwright.create(); |
15 | | - Browser browser = playwright.chromium().launch(); |
16 | | - Page page = browser.newPage(); |
17 | | - |
| 12 | + void shouldShowThePageTitle(Page page) { |
18 | 13 | page.navigate("https://practicesoftwaretesting.com"); |
19 | 14 | String title = page.title(); |
20 | 15 |
|
21 | 16 | Assertions.assertTrue(title.contains("Practice Software Testing")); |
22 | | - |
23 | | - browser.close(); |
24 | | - playwright.close(); |
25 | 17 | } |
26 | 18 |
|
27 | 19 | @Test |
28 | | - void shouldShowSearchTermsInTheTitle() { |
29 | | - Playwright playwright = Playwright.create(); |
30 | | - Browser browser = playwright.chromium().launch(); |
31 | | - Page page = browser.newPage(); |
32 | | - |
| 20 | + void shouldShowSearchTermsInTheTitle(Page page) { |
33 | 21 | page.navigate("https://practicesoftwaretesting.com"); |
34 | 22 | page.locator("[placeholder=Search]").fill("Pliers"); |
35 | 23 | page.locator("button:has-text('Search')").click(); |
36 | 24 |
|
37 | 25 | int matchingProductCount = page.locator(".card-title").count(); |
38 | 26 |
|
39 | 27 | Assertions.assertTrue(matchingProductCount > 0); |
40 | | - |
41 | | - browser.close(); |
42 | | - playwright.close(); |
43 | 28 | } |
44 | 29 | } |
0 commit comments