Skip to content

Commit 9b67d82

Browse files
committed
Cucumber sample code
1 parent e688905 commit 9b67d82

File tree

7 files changed

+87
-2
lines changed

7 files changed

+87
-2
lines changed

pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@
128128
<reportVersion>${allure.version}</reportVersion>
129129
<resultsDirectory>${project.build.directory}/allure-results</resultsDirectory>
130130
</configuration>
131+
<executions>
132+
<execution>
133+
<phase>verify</phase>
134+
<goals>
135+
<goal>report</goal>
136+
</goals>
137+
</execution>
138+
</executions>
131139
</plugin>
132140
</plugins>
133141
</build>

src/test/java/com/serenitydojo/playwright/toolshop/catalog/pageobjects/SearchComponent.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,16 @@ public void clearSearch() {
2222
page.getByTestId("search-reset").click();
2323
});
2424
}
25+
26+
public void filterBy(String filterName) {
27+
page.waitForResponse("**/products?**by_category=**", () -> {
28+
page.getByLabel(filterName).click();
29+
});
30+
}
31+
32+
public void sortBy(String sortFilter) {
33+
page.waitForResponse("**/products?sort=**", () -> {
34+
page.getByTestId("sort").selectOption(sortFilter);
35+
});
36+
}
2537
}

src/test/java/com/serenitydojo/playwright/toolshop/cucumber/CucumberTestSuite.java renamed to src/test/java/com/serenitydojo/playwright/toolshop/cucumber/CucumberTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
"pretty," +
1515
"html:target/cucumber-reports/cucumber.html"
1616
)
17-
public class CucumberTestSuite {;
17+
public class CucumberTests {
1818
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class PlaywrightCucumberFixtures {
1919
private static final ThreadLocal<Browser> browser = ThreadLocal.withInitial(() ->
2020
playwright.get().chromium().launch(
2121
new BrowserType.LaunchOptions()
22-
.setHeadless(false)
22+
.setHeadless(true)
2323
.setArgs(Arrays.asList("--no-sandbox", "--disable-extensions", "--disable-gpu"))
2424
)
2525
);

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.cucumber.datatable.DataTable;
88
import io.cucumber.java.Before;
99
import io.cucumber.java.DataTableType;
10+
import io.cucumber.java.en.And;
1011
import io.cucumber.java.en.Given;
1112
import io.cucumber.java.en.Then;
1213
import io.cucumber.java.en.When;
@@ -34,10 +35,12 @@ public void setupPageObjects() {
3435
public void sally_is_on_the_home_page() {
3536
navBar.openHomePage();
3637
}
38+
3739
@When("she searches for {string}")
3840
public void she_searches_for(String searchTerm) {
3941
searchComponent.searchBy(searchTerm);
4042
}
43+
4144
@Then("the {string} product should be displayed")
4245
public void the_product_should_be_displayed(String productName) {
4346
var matchingProducts = productList.getProductNames();
@@ -54,4 +57,32 @@ public void theFollowingProductsShouldBeDisplayed(List<ProductSummary> expectedP
5457
List<ProductSummary> matchingProducts = productList.getProductSummaries();
5558
Assertions.assertThat(matchingProducts).containsExactlyInAnyOrderElementsOf(expectedProductSummaries);
5659
}
60+
61+
@Then("no products should be displayed")
62+
public void noProductsShouldBeDisplayed() {
63+
List<ProductSummary> matchingProducts = productList.getProductSummaries();
64+
Assertions.assertThat(matchingProducts).isEmpty();
65+
}
66+
67+
@And("the message {string} should be displayed")
68+
public void theMessageShouldBeDisplayed(String messageText) {
69+
String completionMessage = productList.getSearchCompletedMessage();
70+
Assertions.assertThat(completionMessage).isEqualTo(messageText);
71+
}
72+
73+
@And("she filters by {string}")
74+
public void sheFiltersBy(String filterName) {
75+
searchComponent.filterBy(filterName);
76+
}
77+
78+
@When("she sorts by {string}")
79+
public void sheSortsBy(String sortFilter) {
80+
searchComponent.sortBy(sortFilter);
81+
}
82+
83+
@Then("the first product displayed should be {string}")
84+
public void theFirstProductDisplayedShouldBe(String firstProductName) {
85+
List<String> productNames = productList.getProductNames();
86+
Assertions.assertThat(productNames).startsWith(firstProductName);
87+
}
5788
}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,32 @@ Feature: Product Catalog
1919
| Product | Price |
2020
| Wood Saw | $12.18 |
2121
| Circular Saw | $80.19 |
22+
23+
Example: The one where Sally searches for a product that doesn't exist
24+
Given Sally is on the home page
25+
When she searches for "Product-Does-Not-Exist"
26+
Then no products should be displayed
27+
And the message "There are no products found." should be displayed
28+
29+
30+
Rule: Customers should be able to narrow downs their search by category
31+
Example: The one where Sally only wants to see Hand Saws
32+
Given Sally is on the home page
33+
When she searches for "saw"
34+
And she filters by "Hand Saw"
35+
Then the following products should be displayed:
36+
| Product | Price |
37+
| Wood Saw | $12.18 |
38+
39+
40+
Rule: Customers should be able to sort products by various criteria
41+
Scenario Outline: Sally sorts by different criteria
42+
Given Sally is on the home page
43+
When she sorts by "<Sort>"
44+
Then the first product displayed should be "<First Product>"
45+
Examples:
46+
| Sort | First Product |
47+
| Name (A - Z) | Adjustable Wrench |
48+
| Name (Z - A) | Wood Saw |
49+
| Price (High - Low) | Drawer Tool Cabinet |
50+
| Price (Low - High) | Washers |

src/test/resources/junit-platform.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ junit.jupiter.execution.parallel.console.mode=verbose
66

77
junit.jupiter.execution.parallel.config.strategy=dynamic
88
junit.jupiter.execution.parallel.config.dynamic.factor=4
9+
10+
cucumber.execution.parallel.enabled=true
11+
cucumber.execution.parallel.config.strategy=fixed
12+
cucumber.execution.parallel.config.fixed.parallelism=4
13+
cucumber.execution.parallel.config.fixed.max-pool-size=4

0 commit comments

Comments
 (0)