Skip to content

Commit 41462f5

Browse files
committed
Sample code
1 parent fd29a09 commit 41462f5

File tree

9 files changed

+128
-134
lines changed

9 files changed

+128
-134
lines changed

pom.xml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,28 @@
4141
<version>5.11.3</version>
4242
<scope>test</scope>
4343
</dependency>
44+
<dependency>
45+
<groupId>org.junit.platform</groupId>
46+
<artifactId>junit-platform-suite</artifactId>
47+
<version>1.11.3</version>
48+
<scope>test</scope>
49+
</dependency>
4450
<dependency>
4551
<groupId>io.cucumber</groupId>
4652
<artifactId>cucumber-java</artifactId>
4753
<version>7.20.1</version>
54+
<scope>test</scope>
4855
</dependency>
4956
<dependency>
5057
<groupId>io.cucumber</groupId>
5158
<artifactId>cucumber-junit</artifactId>
5259
<version>7.20.1</version>
60+
<scope>test</scope>
5361
</dependency>
5462
<dependency>
5563
<groupId>io.cucumber</groupId>
5664
<artifactId>cucumber-junit-platform-engine</artifactId>
5765
<version>7.20.1</version>
58-
</dependency>
59-
<dependency>
60-
<groupId>org.junit.platform</groupId>
61-
<artifactId>junit-platform-suite</artifactId>
62-
<version>1.11.3</version>
6366
<scope>test</scope>
6467
</dependency>
6568
<dependency>
@@ -79,12 +82,12 @@
7982
</dependency>
8083
<dependency>
8184
<groupId>io.qameta.allure</groupId>
82-
<artifactId>allure-cucumber7-jvm</artifactId>
85+
<artifactId>allure-junit-platform</artifactId>
8386
<scope>test</scope>
8487
</dependency>
8588
<dependency>
8689
<groupId>io.qameta.allure</groupId>
87-
<artifactId>allure-junit-platform</artifactId>
90+
<artifactId>allure-cucumber7-jvm</artifactId>
8891
<scope>test</scope>
8992
</dependency>
9093
</dependencies>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public SearchComponent(Page page) {
1111
}
1212

1313
public void searchBy(String keyword) {
14-
page.waitForResponse("**/products/search?q=" + keyword, () -> {
14+
page.waitForResponse("**/products/search?**", () -> {
1515
page.getByPlaceholder("Search").fill(keyword);
1616
page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Search")).click();
1717
});

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88
@Suite
99
@IncludeEngines("cucumber")
10-
@ConfigurationParameter(key="cucumber.plugin",
11-
value = "io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm, " +
12-
"pretty, " +
13-
"html:target/cucumber-reports/cucumber.html, " +
14-
"json:target/cucumber-reports/cucumber.json")
1510
@SelectClasspathResource("/features")
16-
public class AcceptanceTestSuite {
11+
@ConfigurationParameter(
12+
key="cucumber.plugin",
13+
value = "io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm," +
14+
"pretty," +
15+
"html:target/cucumber-reports/cucumber.html"
16+
)
17+
public class CucumberTestSuite {
1718
}

src/test/java/com/serenitydojo/playwright/toolshop/cucumber/PlaywrightHooks.java

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/test/java/com/serenitydojo/playwright/toolshop/cucumber/SearchStepDefinitions.java

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.serenitydojo.playwright.toolshop.cucumber.stepdefinitions;
2+
3+
import com.microsoft.playwright.*;
4+
import io.cucumber.java.After;
5+
import io.cucumber.java.AfterAll;
6+
import io.cucumber.java.Before;
7+
8+
import java.util.Arrays;
9+
10+
public class PlaywrightCucumberFixtures {
11+
private static final ThreadLocal<Playwright> playwright
12+
= ThreadLocal.withInitial(() -> {
13+
Playwright playwright = Playwright.create();
14+
playwright.selectors().setTestIdAttribute("data-test");
15+
return playwright;
16+
}
17+
);
18+
19+
private static final ThreadLocal<Browser> browser = ThreadLocal.withInitial(() ->
20+
playwright.get().chromium().launch(
21+
new BrowserType.LaunchOptions()
22+
.setHeadless(false)
23+
.setArgs(Arrays.asList("--no-sandbox", "--disable-extensions", "--disable-gpu"))
24+
)
25+
);
26+
27+
private static final ThreadLocal<BrowserContext> browserContext = new ThreadLocal<>();
28+
29+
private static final ThreadLocal<Page> page = new ThreadLocal<>();
30+
31+
@Before(order = 100)
32+
public void setUpBrowserContext() {
33+
browserContext.set(browser.get().newContext());
34+
page.set(browserContext.get().newPage());
35+
}
36+
37+
@After
38+
public void closeContext() {
39+
browserContext.get().close();
40+
}
41+
42+
@AfterAll
43+
public static void tearDown() {
44+
browser.get().close();
45+
browser.remove();
46+
47+
playwright.get().close();
48+
playwright.remove();
49+
}
50+
51+
public static Page getPage() {
52+
return page.get();
53+
}
54+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.serenitydojo.playwright.toolshop.cucumber.stepdefinitions;
2+
3+
import com.serenitydojo.playwright.toolshop.catalog.pageobjects.NavBar;
4+
import com.serenitydojo.playwright.toolshop.catalog.pageobjects.ProductList;
5+
import com.serenitydojo.playwright.toolshop.catalog.pageobjects.SearchComponent;
6+
import io.cucumber.java.Before;
7+
import io.cucumber.java.en.Given;
8+
import io.cucumber.java.en.Then;
9+
import io.cucumber.java.en.When;
10+
import io.cucumber.java.eo.Se;
11+
import io.cucumber.messages.types.Product;
12+
import org.assertj.core.api.Assertions;
13+
14+
public class ProductCatalogStepDefinitions {
15+
16+
NavBar navBar;
17+
SearchComponent searchComponent;
18+
ProductList productList;
19+
20+
@Before
21+
public void setupPageObjects() {
22+
navBar = new NavBar(PlaywrightCucumberFixtures.getPage());
23+
searchComponent = new SearchComponent(PlaywrightCucumberFixtures.getPage());
24+
productList = new ProductList(PlaywrightCucumberFixtures.getPage());
25+
}
26+
27+
@Given("Sally is on the home page")
28+
public void sally_is_on_the_home_page() {
29+
navBar.openHomePage();
30+
}
31+
@When("she searches for {string}")
32+
public void she_searches_for(String searchTerm) {
33+
searchComponent.searchBy(searchTerm);
34+
}
35+
@Then("the {string} product should be displayed")
36+
public void the_product_should_be_displayed(String productName) {
37+
var matchingProducts = productList.getProductNames();
38+
Assertions.assertThat(matchingProducts).contains(productName);
39+
}
40+
41+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Feature: Product Catalog
2+
3+
As a customer,
4+
I want to easily search, filter, and sort products in the catalog
5+
So that I can find what I need quickly.
6+
7+
Sally is an online shopper
8+
9+
Rule: Customers should be able to search for products by name
10+
Example: The one where Sally searches for an Adjustable Wrench
11+
Given Sally is on the home page
12+
When she searches for "Adjustable Wrench"
13+
Then the "Adjustable Wrench" product should be displayed
14+
15+

src/test/resources/features/search_for_products.feature

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)