Skip to content

Commit 28e3f2f

Browse files
committed
Reorganising tests for Allure
1 parent de8ebd3 commit 28e3f2f

File tree

11 files changed

+62
-18
lines changed

11 files changed

+62
-18
lines changed

.idea/compiler.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
</dependency>
8787
</dependencies>
8888
</plugin>
89+
8990
<plugin>
9091
<groupId>io.qameta.allure</groupId>
9192
<artifactId>allure-maven</artifactId>
@@ -94,8 +95,16 @@
9495
<reportVersion>${allure.version}</reportVersion>
9596
<resultsDirectory>${project.build.directory}/allure-results</resultsDirectory>
9697
</configuration>
98+
<executions>
99+
<execution>
100+
<id>allure-reports</id>
101+
<phase>verify</phase>
102+
<goals>
103+
<goal>report</goal>
104+
</goals>
105+
</execution>
106+
</executions>
97107
</plugin>
98108
</plugins>
99109
</build>
100-
101110
</project>

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.serenitydojo.playwright.toolshop.catalog.pageobjects.*;
44
import com.serenitydojo.playwright.toolshop.fixtures.PlaywrightTestCase;
55
import io.qameta.allure.Feature;
6+
import io.qameta.allure.Step;
67
import io.qameta.allure.Story;
78
import org.assertj.core.api.Assertions;
89
import org.junit.jupiter.api.BeforeEach;
@@ -23,7 +24,7 @@ public class AddToCartTest extends PlaywrightTestCase {
2324

2425
@BeforeEach
2526
void openHomePage() {
26-
page.navigate("https://practicesoftwaretesting.com");
27+
navBar.openHomePage();
2728
}
2829

2930
@BeforeEach
@@ -36,7 +37,7 @@ void setUp() {
3637
}
3738

3839
@Test
39-
@Story("Check out")
40+
@Story("Checking out a product")
4041
@DisplayName("Checking out a single item")
4142
void whenCheckingOutASingleItem() {
4243
searchComponent.searchBy("pliers");
@@ -60,7 +61,7 @@ void whenCheckingOutASingleItem() {
6061
}
6162

6263
@Test
63-
@Story("Check out")
64+
@Story("Checking out a product")
6465
@DisplayName("Checking out multiple items")
6566
void whenCheckingOutMultipleItems() {
6667
navBar.openHomePage();

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import org.junit.jupiter.api.Test;
1313

1414
@DisplayName("Searching for products")
15-
@Feature("Searching for products")
15+
@Feature("Product Catalog")
1616
public class SearchForProductsTest extends PlaywrightTestCase {
1717

1818
@BeforeEach
@@ -22,7 +22,7 @@ void openHomePage() {
2222

2323
@Nested
2424
@DisplayName("Searching by keyword")
25-
@Story("Searching by keyword")
25+
@Story("Searching for products")
2626
class SearchingByKeyword {
2727

2828
@Test
@@ -66,6 +66,5 @@ void clearingTheSearchResults() {
6666
var matchingProducts = productList.getProductNames();
6767
Assertions.assertThat(matchingProducts).hasSize(9);
6868
}
69-
7069
}
7170
}
Lines changed: 7 additions & 3 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.ScreenshotManager;
45
import io.qameta.allure.Step;
56

67
public class NavBar {
@@ -10,18 +11,21 @@ public NavBar(Page page) {
1011
this.page = page;
1112
}
1213

13-
@Step("Open cart")
14+
@Step("Open the shopping cart")
1415
public void openCart() {
1516
page.getByTestId("nav-cart").click();
17+
ScreenshotManager.takeScreenshot(page, "Shopping cart");
1618
}
1719

18-
@Step("Open the home page")
20+
@Step("Open home page")
1921
public void openHomePage() {
2022
page.navigate("https://practicesoftwaretesting.com");
23+
ScreenshotManager.takeScreenshot(page, "Home page");
2124
}
2225

23-
@Step("Open the Contact page")
26+
@Step("Open contact page")
2427
public void toTheContactPage() {
2528
page.navigate("https://practicesoftwaretesting.com/contact");
29+
ScreenshotManager.takeScreenshot(page, "Contact page");
2630
}
2731
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.microsoft.playwright.Page;
44
import com.microsoft.playwright.options.AriaRole;
5+
import com.serenitydojo.playwright.toolshop.fixtures.ScreenshotManager;
56
import io.qameta.allure.Step;
67

78
public class ProductDetails {
@@ -11,11 +12,12 @@ public ProductDetails(Page page) {
1112
this.page = page;
1213
}
1314

14-
@Step("Increase product quantity")
15+
@Step("Increase quantity")
1516
public void increaseQuanityBy(int increment) {
1617
for (int i = 1; i <= increment; i++) {
1718
page.getByTestId("increase-quantity").click();
1819
}
20+
ScreenshotManager.takeScreenshot(page, "Quantity increased by " + increment);
1921
}
2022

2123
@Step("Add to cart")
@@ -27,5 +29,6 @@ public void addToCart() {
2729
page.getByRole(AriaRole.ALERT).click();
2830
}
2931
);
32+
ScreenshotManager.takeScreenshot(page, "Added to cart");
3033
}
3134
}

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

Lines changed: 2 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.ScreenshotManager;
45
import io.qameta.allure.Step;
56

67
import java.util.List;
@@ -19,6 +20,7 @@ public List<String> getProductNames() {
1920

2021
@Step("View product details")
2122
public void viewProductDetails(String productName) {
23+
ScreenshotManager.takeScreenshot(page, "View product details for " + productName);
2224
page.locator(".card").getByText(productName).click();
2325
}
2426

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.microsoft.playwright.Page;
44
import com.microsoft.playwright.options.AriaRole;
5+
import io.qameta.allure.Step;
56

67
public class SearchComponent {
78
private final Page page;
@@ -10,13 +11,15 @@ public SearchComponent(Page page) {
1011
this.page = page;
1112
}
1213

14+
@Step("Search for keyword")
1315
public void searchBy(String keyword) {
1416
page.waitForResponse("**/products/search?q=" + keyword, () -> {
1517
page.getByPlaceholder("Search").fill(keyword);
1618
page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Search")).click();
1719
});
1820
}
1921

22+
@Step("Clear the search criteria")
2023
public void clearSearch() {
2124
page.waitForResponse("**/products**", () -> {
2225
page.getByTestId("search-reset").click();

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
2121

2222
@DisplayName("Contact form")
23-
@Feature("Contact form")
23+
@Feature("Contacts")
2424
public class ContactFormTest extends PlaywrightTestCase {
2525

2626
ContactForm contactForm;
@@ -33,7 +33,7 @@ void openContactPage() {
3333
navigate.toTheContactPage();
3434
}
3535

36-
@Story("Submitting a request")
36+
@Story("Contact form")
3737
@DisplayName("Customers can use the contact form to contact us")
3838
@Test
3939
void completeForm() throws URISyntaxException {
@@ -52,7 +52,7 @@ void completeForm() throws URISyntaxException {
5252
.contains("Thanks for your message! We will contact you shortly.");
5353
}
5454

55-
@Story("Submitting a request")
55+
@Story("Contact form")
5656
@DisplayName("First name, last name, email and message are mandatory")
5757
@ParameterizedTest(name = "{arguments} is a mandatory field")
5858
@ValueSource(strings = {"First name", "Last name", "Email", "Message"})
@@ -75,7 +75,7 @@ void mandatoryFields(String fieldName) {
7575
assertThat(errorMessage).isVisible();
7676
}
7777

78-
@Story("Submitting a request")
78+
@Story("Contact form")
7979
@DisplayName("The message must be at least 50 characters long")
8080
@Test
8181
void messageTooShort() {
@@ -91,7 +91,7 @@ void messageTooShort() {
9191
assertThat(page.getByRole(AriaRole.ALERT)).hasText("Message must be minimal 50 characters");
9292
}
9393

94-
@Story("Submitting a request")
94+
@Story("Contact form")
9595
@DisplayName("The email address must be correctly formatted")
9696
@ParameterizedTest(name = "'{arguments}' should be rejected")
9797
@ValueSource(strings = {"not-an-email", "not-an.email.com", "notanemail"})

src/test/java/com/serenitydojo/playwright/toolshop/fixtures/PlaywrightTestCase.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.serenitydojo.playwright.toolshop.fixtures;
22

33
import com.microsoft.playwright.*;
4+
import io.qameta.allure.Allure;
45
import org.junit.jupiter.api.AfterAll;
56
import org.junit.jupiter.api.AfterEach;
67
import org.junit.jupiter.api.BeforeEach;
78

9+
import java.io.ByteArrayInputStream;
10+
import java.nio.file.Paths;
811
import java.util.Arrays;
912

1013
public abstract class PlaywrightTestCase {
@@ -21,7 +24,7 @@ public abstract class PlaywrightTestCase {
2124
playwright.get().chromium().launch(
2225
new BrowserType.LaunchOptions()
2326
.setHeadless(true)
24-
.setArgs(Arrays.asList("--no-sandbox", "--disable-extensions", "--disable-gpu"))
27+
.setArgs(Arrays.asList("--no-sandbox", "--disable-extensions", "--disable-gpu"))
2528
)
2629
);
2730

@@ -37,6 +40,7 @@ void setUpBrowserContext() {
3740

3841
@AfterEach
3942
void closeContext() {
43+
ScreenshotManager.takeScreenshot(page, "End of test");
4044
browserContext.close();
4145
}
4246

@@ -48,5 +52,4 @@ static void tearDown() {
4852
playwright.get().close();
4953
playwright.remove();
5054
}
51-
5255
}

0 commit comments

Comments
 (0)