Skip to content

Commit e688905

Browse files
committed
Data tables
1 parent 41462f5 commit e688905

File tree

6 files changed

+39
-2
lines changed

6 files changed

+39
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ buildNumber.properties
1717
.classpath
1818
.allure
1919
allure-results
20+
.idea

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.serenitydojo.playwright.toolshop.catalog.pageobjects;
22

33
import com.microsoft.playwright.Page;
4+
import com.serenitydojo.playwright.toolshop.fixtures.ProductSummary;
45
import io.qameta.allure.Step;
56

67
import java.util.List;
@@ -17,6 +18,16 @@ public List<String> getProductNames() {
1718
return page.getByTestId("product-name").allInnerTexts();
1819
}
1920

21+
public List<ProductSummary> getProductSummaries() {
22+
return page.locator(".card").all()
23+
.stream()
24+
.map(productCard -> {
25+
String productName = productCard.getByTestId("product-name").textContent().strip();
26+
String productPrice = productCard.getByTestId("product-price").textContent();
27+
return new ProductSummary(productName, productPrice);
28+
}).toList();
29+
}
30+
2031
@Step("View product details")
2132
public void viewProductDetails(String productName) {
2233
page.locator(".card").getByText(productName).click();

src/test/java/com/serenitydojo/playwright/toolshop/cucumber/CucumberTestSuite.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 CucumberTestSuite {;
1818
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
import com.serenitydojo.playwright.toolshop.catalog.pageobjects.NavBar;
44
import com.serenitydojo.playwright.toolshop.catalog.pageobjects.ProductList;
55
import com.serenitydojo.playwright.toolshop.catalog.pageobjects.SearchComponent;
6+
import com.serenitydojo.playwright.toolshop.fixtures.ProductSummary;
7+
import io.cucumber.datatable.DataTable;
68
import io.cucumber.java.Before;
9+
import io.cucumber.java.DataTableType;
710
import io.cucumber.java.en.Given;
811
import io.cucumber.java.en.Then;
912
import io.cucumber.java.en.When;
1013
import io.cucumber.java.eo.Se;
1114
import io.cucumber.messages.types.Product;
1215
import org.assertj.core.api.Assertions;
1316

17+
import java.util.List;
18+
import java.util.Map;
19+
1420
public class ProductCatalogStepDefinitions {
1521

1622
NavBar navBar;
@@ -38,4 +44,14 @@ public void the_product_should_be_displayed(String productName) {
3844
Assertions.assertThat(matchingProducts).contains(productName);
3945
}
4046

47+
@DataTableType
48+
public ProductSummary productSummaryRow(Map<String, String> productData) {
49+
return new ProductSummary(productData.get("Product"),productData.get("Price"));
50+
}
51+
52+
@Then("the following products should be displayed:")
53+
public void theFollowingProductsShouldBeDisplayed(List<ProductSummary> expectedProductSummaries) {
54+
List<ProductSummary> matchingProducts = productList.getProductSummaries();
55+
Assertions.assertThat(matchingProducts).containsExactlyInAnyOrderElementsOf(expectedProductSummaries);
56+
}
4157
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.serenitydojo.playwright.toolshop.fixtures;
2+
3+
public record ProductSummary(String name, String price) {}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ Feature: Product Catalog
1212
When she searches for "Adjustable Wrench"
1313
Then the "Adjustable Wrench" product should be displayed
1414

15-
15+
Example: The one where Sally searches for a more general term
16+
Given Sally is on the home page
17+
When she searches for "saw"
18+
Then the following products should be displayed:
19+
| Product | Price |
20+
| Wood Saw | $12.18 |
21+
| Circular Saw | $80.19 |

0 commit comments

Comments
 (0)