Skip to content

Commit 669f331

Browse files
committed
Added an additonal edge case for search filtering
1 parent 3ff2740 commit 669f331

File tree

8 files changed

+97
-18
lines changed

8 files changed

+97
-18
lines changed

.github/workflows/playwright-tests.yml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
uses: actions/checkout@v3
2020

2121
- name: Set up Node.js
22-
uses: actions/setup-node@v3
22+
uses: actions/setup-node@v4
2323
with:
2424
node-version: '20'
2525

@@ -39,9 +39,9 @@ jobs:
3939
java-distribution: temurin
4040
maven-version: 3.9.9
4141

42-
# Step 4: Verify Maven installation
43-
- name: Verify Maven version
44-
run: mvn --version
42+
# Step 4: Install playwright OS libraries
43+
- name: Install Playwright dependencies
44+
run: npx playwright install-deps
4545

4646
# Step 5: Cache Maven dependencies
4747
- name: Cache Maven dependencies
@@ -52,20 +52,17 @@ jobs:
5252
restore-keys: |
5353
${{ runner.os }}-maven
5454
55-
- name: Install Playwright dependencies
56-
run: npx playwright install-deps
57-
5855
# Step 6: Run Maven to execute Playwright tests
5956
- name: Run Playwright Tests
6057
run: mvn verify
6158

62-
# # Step 7: Archive ZIP files in the root directory
63-
# - name: Archive ZIP files
64-
# if: always() # Ensure this step runs even if previous steps fail
65-
# uses: actions/upload-artifact@v4
66-
# with:
67-
# name: zip-archives
68-
# path: 'target/*.zip'
59+
# Step 7: Archive any trace files
60+
- name: Archive trace files
61+
if: always()
62+
uses: actions/upload-artifact@v4
63+
with:
64+
name: traces
65+
path: target/traces/*.zip
6966

7067
# Step 8: Deploy Allure report to GitHub Pages
7168
- name: Deploy Allure Report to GitHub Pages

src/test/java/com/serenitydojo/playwright/toolshop/catalog/AddToCartTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.serenitydojo.playwright.toolshop.catalog.pageobjects.*;
66
import com.serenitydojo.playwright.toolshop.fixtures.ChromeHeadlessOptions;
77
import com.serenitydojo.playwright.toolshop.fixtures.TakesFinalScreenshot;
8+
import com.serenitydojo.playwright.toolshop.fixtures.WithTracing;
89
import io.qameta.allure.Feature;
910
import io.qameta.allure.Story;
1011
import org.assertj.core.api.Assertions;
@@ -17,7 +18,7 @@
1718
@DisplayName("Shopping Cart")
1819
@Feature("Shopping Cart")
1920
@UsePlaywright(ChromeHeadlessOptions.class)
20-
public class AddToCartTest implements TakesFinalScreenshot {
21+
public class AddToCartTest implements TakesFinalScreenshot, WithTracing {
2122

2223
SearchComponent searchComponent;
2324
ProductList productList;

src/test/java/com/serenitydojo/playwright/toolshop/catalog/SearchForProductsTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.serenitydojo.playwright.toolshop.catalog.pageobjects.SearchComponent;
77
import com.serenitydojo.playwright.toolshop.fixtures.ChromeHeadlessOptions;
88
import com.serenitydojo.playwright.toolshop.fixtures.TakesFinalScreenshot;
9+
import com.serenitydojo.playwright.toolshop.fixtures.WithTracing;
910
import io.qameta.allure.Feature;
1011
import io.qameta.allure.Story;
1112
import org.assertj.core.api.Assertions;
@@ -17,7 +18,7 @@
1718
@DisplayName("Searching for products")
1819
@Feature("Product Catalog")
1920
@UsePlaywright(ChromeHeadlessOptions.class)
20-
public class SearchForProductsTest implements TakesFinalScreenshot {
21+
public class SearchForProductsTest implements TakesFinalScreenshot, WithTracing {
2122

2223
@BeforeEach
2324
void openHomePage(Page page) {

src/test/java/com/serenitydojo/playwright/toolshop/contact/ContactFormTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.serenitydojo.playwright.toolshop.catalog.pageobjects.NavBar;
88
import com.serenitydojo.playwright.toolshop.fixtures.ChromeHeadlessOptions;
99
import com.serenitydojo.playwright.toolshop.fixtures.TakesFinalScreenshot;
10+
import com.serenitydojo.playwright.toolshop.fixtures.WithTracing;
1011
import io.qameta.allure.Feature;
1112
import io.qameta.allure.Story;
1213
import org.assertj.core.api.Assertions;
@@ -25,7 +26,7 @@
2526
@DisplayName("Contact form")
2627
@Feature("Contacts")
2728
@UsePlaywright(ChromeHeadlessOptions.class)
28-
public class ContactFormTest implements TakesFinalScreenshot {
29+
public class ContactFormTest implements TakesFinalScreenshot, WithTracing {
2930

3031
ContactForm contactForm;
3132
NavBar navigate;

src/test/java/com/serenitydojo/playwright/toolshop/cucumber/stepdefinitions/PlaywrightCucumberFixtures.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void setUpBrowserContext() {
3434
page.set(browserContext.get().newPage());
3535
}
3636

37-
@After
37+
@After(order = 100)
3838
public void closeContext() {
3939
browserContext.get().close();
4040
}
@@ -51,4 +51,9 @@ public static void tearDown() {
5151
public static Page getPage() {
5252
return page.get();
5353
}
54+
55+
public static BrowserContext getBrowserContext() {
56+
return browserContext.get();
57+
}
58+
5459
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.serenitydojo.playwright.toolshop.cucumber.stepdefinitions;
2+
3+
import com.microsoft.playwright.Tracing;
4+
import io.cucumber.java.After;
5+
import io.cucumber.java.Before;
6+
import io.cucumber.java.Scenario;
7+
8+
import java.nio.file.Paths;
9+
10+
public class ScenarioTracingFixtures {
11+
12+
13+
@Before
14+
public void setupTrace() {
15+
PlaywrightCucumberFixtures.getBrowserContext().tracing().start(
16+
new Tracing.StartOptions()
17+
.setScreenshots(true)
18+
.setSnapshots(true)
19+
.setSources(true)
20+
);
21+
}
22+
23+
@After(order = 1000)
24+
public void recordTrace(Scenario scenario) {
25+
26+
String traceName = scenario.getName();
27+
PlaywrightCucumberFixtures.getBrowserContext().tracing().stop(
28+
new Tracing.StopOptions()
29+
.setPath(Paths.get("target/traces/trace-" + traceName + ".zip"))
30+
);
31+
}
32+
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.serenitydojo.playwright.toolshop.fixtures;
2+
3+
import com.microsoft.playwright.BrowserContext;
4+
import com.microsoft.playwright.Tracing;
5+
import org.junit.jupiter.api.AfterEach;
6+
import org.junit.jupiter.api.BeforeEach;
7+
import org.junit.jupiter.api.TestInfo;
8+
9+
import java.nio.file.Paths;
10+
11+
public interface WithTracing {
12+
13+
14+
@BeforeEach
15+
default void setupTrace(BrowserContext context) {
16+
context.tracing().start(
17+
new Tracing.StartOptions()
18+
.setScreenshots(true)
19+
.setSnapshots(true)
20+
.setSources(true)
21+
);
22+
}
23+
24+
@AfterEach
25+
default void recordTrace(TestInfo testInfo, BrowserContext context) {
26+
String traceName = testInfo.getDisplayName().replace(" ","-").toLowerCase();
27+
context.tracing().stop(
28+
new Tracing.StopOptions()
29+
.setPath(Paths.get("target/traces/trace-" + traceName + ".zip"))
30+
);
31+
}
32+
33+
}

src/test/resources/features/catalog/product_catalog.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ Feature: Product Catalog
3636
| Product | Price |
3737
| Wood Saw | $12.18 |
3838

39+
Example: The one where Sally only wants to see Power Drills
40+
Given Sally is on the home page
41+
When she searches for "drill"
42+
And she filters by "Power Tools"
43+
Then the following products should be displayed:
44+
| Product | Price |
45+
| Cordless Drill 24V | $66.54 |
46+
| Cordless Drill 12V | $46.50 |
3947

4048
Rule: Customers should be able to sort products by various criteria
4149
Scenario Outline: Sally sorts by different criteria

0 commit comments

Comments
 (0)