Skip to content

Commit 51f5264

Browse files
committed
Updated dependencies to Playwright 1.57.0 and JUnit 6.0.1
2 parents 0263ddb + 0073e79 commit 51f5264

File tree

8 files changed

+103
-185
lines changed

8 files changed

+103
-185
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ buildNumber.properties
99
.mvn/timing.properties
1010
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
1111
.mvn/wrapper/maven-wrapper.jar
12-
12+
.allure
13+
.idea
1314
# Eclipse m2e generated files
1415
# Eclipse Core
1516
.project

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
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>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.serenitydojo.playwright;
2+
3+
import com.microsoft.playwright.BrowserType;
4+
import com.microsoft.playwright.junit.Options;
5+
import com.microsoft.playwright.junit.OptionsFactory;
6+
7+
import java.util.Arrays;
8+
9+
public class HeadlessChromeOptions implements OptionsFactory {
10+
@Override
11+
public Options getOptions() {
12+
return new Options().setLaunchOptions(
13+
new BrowserType.LaunchOptions()
14+
.setArgs(Arrays.asList("--no-sandbox", "--disable-extensions", "--disable-gpu"))
15+
).setHeadless(true)
16+
.setTestIdAttribute("data-test");
17+
}
18+
}

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/PlaywrightCollectionsTest.java

Lines changed: 11 additions & 38 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.junit.UsePlaywright;
45
import com.microsoft.playwright.options.AriaRole;
56
import com.microsoft.playwright.options.SelectOption;
67
import org.assertj.core.api.Assertions;
@@ -12,50 +13,22 @@
1213

1314
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
1415

16+
@UsePlaywright(HeadlessChromeOptions.class)
1517
public class PlaywrightCollectionsTest {
1618

17-
protected static Playwright playwright;
18-
protected static Browser browser;
19-
protected static BrowserContext browserContext;
20-
21-
Page page;
22-
23-
@BeforeAll
24-
static void setUpBrowser() {
25-
playwright = Playwright.create();
26-
browser = playwright.chromium().launch(
27-
new BrowserType.LaunchOptions().setHeadless(true)
28-
.setArgs(Arrays.asList("--no-sandbox", "--disable-extensions", "--disable-gpu"))
29-
);
30-
playwright.selectors().setTestIdAttribute("data-test");
31-
}
32-
3319
@BeforeEach
34-
void setUp() {
35-
browserContext = browser.newContext();
36-
page = browserContext.newPage();
37-
openPage();
38-
}
39-
40-
@AfterEach
41-
void closeContext() {
42-
browserContext.close();
43-
}
44-
45-
@AfterAll
46-
static void tearDown() {
47-
browser.close();
48-
playwright.close();
20+
void setUp(Page page) {
21+
openPage(page);
4922
}
5023

51-
private void openPage() {
24+
private void openPage(Page page) {
5225
page.navigate("https://practicesoftwaretesting.com");
5326
page.waitForCondition(() -> page.getByTestId("product-name").count() > 0);
5427
}
5528

5629
@DisplayName("Counting items in a list")
5730
@Test
58-
void countingItemsOnThePage() {
31+
void countingItemsOnThePage(Page page) {
5932

6033
int itemsOnThePage = page.locator(".card").count();
6134

@@ -64,23 +37,23 @@ void countingItemsOnThePage() {
6437

6538
@DisplayName("Finding the first matching item")
6639
@Test
67-
void findingTheFirstMatchingItem() {
40+
void findingTheFirstMatchingItem(Page page) {
6841

6942
page.locator(".card").first().click();
7043

7144
}
7245

7346
@DisplayName("Finding the nth matching item")
7447
@Test
75-
void findingNthMatchingItem() {
48+
void findingNthMatchingItem(Page page) {
7649

7750
page.locator(".card").nth(2).click();
7851

7952
}
8053

8154
@DisplayName("Finding the last matching item")
8255
@Test
83-
void findingLastMatchingItem() {
56+
void findingLastMatchingItem(Page page) {
8457

8558
page.locator(".card").last().click();
8659

@@ -92,7 +65,7 @@ class FindingTheTextInAList {
9265

9366
@DisplayName("and finding all the text values ")
9467
@Test
95-
void withAllTextContents() {
68+
void withAllTextContents(Page page) {
9669

9770
List<String> itemNames = page.getByTestId("product-name").allTextContents();
9871

@@ -110,7 +83,7 @@ void withAllTextContents() {
11083

11184
@DisplayName("and asserting with hasText")
11285
@Test
113-
void withHasText() {
86+
void withHasText(Page page) {
11487
assertThat(page.getByTestId("product-name"))
11588
.hasText(new String[]{
11689
" Combination Pliers ",

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

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,34 @@
11
package com.serenitydojo.playwright;
22

3-
import com.microsoft.playwright.*;
3+
import com.microsoft.playwright.Page;
4+
import com.microsoft.playwright.junit.UsePlaywright;
45
import com.microsoft.playwright.options.AriaRole;
56
import org.junit.jupiter.api.*;
6-
import org.junit.jupiter.api.parallel.Execution;
7-
import org.junit.jupiter.api.parallel.ExecutionMode;
87
import org.junit.jupiter.params.ParameterizedTest;
98
import org.junit.jupiter.params.provider.ValueSource;
109

1110
import java.net.URISyntaxException;
1211
import java.nio.file.Path;
1312
import java.nio.file.Paths;
14-
import java.util.Arrays;
1513
import java.util.List;
1614

1715
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
1816

19-
@Execution(ExecutionMode.SAME_THREAD)
17+
@UsePlaywright(HeadlessChromeOptions.class)
2018
public class PlaywrightFormsTest {
2119

22-
protected static Playwright playwright;
23-
protected static Browser browser;
24-
protected static BrowserContext browserContext;
25-
26-
Page page;
27-
28-
@BeforeAll
29-
static void setUpBrowser() {
30-
playwright = Playwright.create();
31-
browser = playwright.chromium().launch(
32-
new BrowserType.LaunchOptions().setHeadless(true)
33-
.setArgs(Arrays.asList("--no-sandbox", "--disable-extensions", "--disable-gpu"))
34-
);
35-
}
36-
37-
@BeforeEach
38-
void setUp() {
39-
browserContext = browser.newContext();
40-
page = browserContext.newPage();
41-
}
42-
43-
@AfterEach
44-
void closeContext() {
45-
browserContext.close();
46-
}
47-
48-
@AfterAll
49-
static void tearDown() {
50-
browser.close();
51-
playwright.close();
52-
}
53-
5420
@DisplayName("Interacting with text fields")
5521
@Nested
5622
class WhenInteractingWithTextFields {
5723

5824
@BeforeEach
59-
void openContactPage() {
25+
void openContactPage(Page page) {
6026
page.navigate("https://practicesoftwaretesting.com/contact");
6127
}
6228

6329
@DisplayName("Complete the form")
6430
@Test
65-
void completeForm() throws URISyntaxException {
31+
void completeForm(Page page) throws URISyntaxException {
6632
var firstNameField = page.getByLabel("First name");
6733
var lastNameField = page.getByLabel("Last name");
6834
var emailNameField = page.getByLabel("Email");
@@ -93,7 +59,7 @@ void completeForm() throws URISyntaxException {
9359
@DisplayName("Mandatory fields")
9460
@ParameterizedTest
9561
@ValueSource(strings = {"First name", "Last name", "Email", "Message"})
96-
void mandatoryFields(String fieldName) {
62+
void mandatoryFields(String fieldName, Page page) {
9763
var firstNameField = page.getByLabel("First name");
9864
var lastNameField = page.getByLabel("Last name");
9965
var emailNameField = page.getByLabel("Email");
@@ -121,7 +87,7 @@ void mandatoryFields(String fieldName) {
12187

12288
@DisplayName("Text fields")
12389
@Test
124-
void textFieldValues() {
90+
void textFieldValues(Page page) {
12591
var messageField = page.getByLabel("Message");
12692

12793
messageField.fill("This is my message");
@@ -131,7 +97,7 @@ void textFieldValues() {
13197

13298
@DisplayName("Dropdown lists")
13399
@Test
134-
void dropdownFieldValues() {
100+
void dropdownFieldValues(Page page) {
135101
var subjectField = page.getByLabel("Subject");
136102

137103
subjectField.selectOption("Warranty");
@@ -141,7 +107,7 @@ void dropdownFieldValues() {
141107

142108
@DisplayName("File uploads")
143109
@Test
144-
void fileUploads() throws URISyntaxException {
110+
void fileUploads(Page page) throws URISyntaxException {
145111
var attachmentField = page.getByLabel("Attachment");
146112

147113
Path attachment = Paths.get(ClassLoader.getSystemResource("data/sample-data.txt").toURI());
@@ -156,7 +122,7 @@ void fileUploads() throws URISyntaxException {
156122

157123
@DisplayName("By CSS class")
158124
@Test
159-
void locateTheSendButtonByCssClass() {
125+
void locateTheSendButtonByCssClass(Page page) {
160126
page.locator("#first_name").fill("Sarah-Jane");
161127
page.locator(".btnSubmit").click();
162128
List<String> alertMessages = page.locator(".alert").allTextContents();
@@ -166,7 +132,7 @@ void locateTheSendButtonByCssClass() {
166132

167133
@DisplayName("By attribute")
168134
@Test
169-
void locateTheSendButtonByAttribute() {
135+
void locateTheSendButtonByAttribute(Page page) {
170136
page.locator("input[placeholder='Your last name *']").fill("Smith");
171137
assertThat(page.locator("#last_name")).hasValue("Smith");
172138
}

0 commit comments

Comments
 (0)