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