Skip to content

Commit 506a349

Browse files
committed
feat(e2e): cleanups
1 parent c4e0f75 commit 506a349

10 files changed

Lines changed: 44 additions & 16 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
workflow_dispatch:
1212

1313
env:
14+
BASE_URL: 'https://magento.softwaretestingboard.com/'
1415
EMAIL: ${{ secrets.EMAIL }}
1516
PASSWORD: ${{ secrets.PASSWORD }}
1617

@@ -21,7 +22,6 @@ jobs:
2122
strategy:
2223
fail-fast: false
2324
matrix:
24-
base_urls: ['https://magento.softwaretestingboard.com/']
2525
browsers: ['chromium']
2626
greps: ['@LOGIN', '@SIGN_UP', '@SANITY', '@MEN_CATEGORY_SHOP']
2727
steps:
@@ -34,7 +34,7 @@ jobs:
3434
- name: Install Playwright Browsers
3535
run: npx playwright install --with-deps
3636
- name: Run Playwright tests
37-
run: BASE_URL=${{ matrix.base_urls }} npx playwright test --grep ${{ matrix.greps }} --project=${{ matrix.browsers }}
37+
run: BASE_URL=${{ env.BASE_URL }} npx playwright test --grep ${{ matrix.greps }} --project=${{ matrix.browsers }}
3838
- uses: actions/upload-artifact@v4
3939
if: always()
4040
with:

helpers/fixtures/customFixtures/CustomFixtures.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ShoppingCartPage } from '../../../pages/cartPage/ShoppingCartPage';
99
import { WomenCategoryPage } from '../../../pages/women/WomenCategoryPage';
1010
import { ProductPage } from '../../../pages/productPage/ProductPage';
1111

12-
type MyFixtures = {
12+
type TestFixtures = {
1313
loginPage: LoginPage;
1414
loadAppAndLogin: LoginPage;
1515
lumaMainPage: LumaMainPage;
@@ -26,7 +26,7 @@ type MyFixtures = {
2626
/**
2727
* @description custom fixtures to promote reusability and prevent repeating same workflows in each test file
2828
*/
29-
export const test = base.extend<MyFixtures>({
29+
export const test = base.extend<TestFixtures>({
3030
loadAppAndLogin: async ({ page }, use) => {
3131
let loginPage = new LoginPage(page);
3232
await loginPage.loadApp();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"test": "npx playwright test --project='chromium'",
7+
"test": "npx playwright test --project='chromium' --workers 1",
88
"build": "tsc -p tsconfig.json --noEmit",
99
"test:changed": "npx playwright test --project='chromium' --only-changed --workers 1",
1010
"ui-mode": "npx playwright test --ui",

pages/BasePage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class BasePage {
5050
}
5151
}
5252

53-
public async loadApp(url: (string | undefined) = process.env.BASE_URL) {
53+
public async loadApp(url = process.env.BASE_URL as string) {
5454
if (url !== undefined) {
5555
await this.page.goto(url);
5656
} else {
@@ -121,7 +121,7 @@ export class BasePage {
121121
* @description applies to every button that has the type of submit e.g "<button type=submit></button>""
122122
*/
123123
public async clickOnButtonWithRole(buttonName: string) {
124-
const submitButton = this.page.getByRole('button', { name: new RegExp(`^\\${buttonName}\\b$`, 'i') });
124+
const submitButton = this.page.getByRole('button', { name: buttonName, exact: true });
125125
await this.clickElement(submitButton);
126126
}
127127
}

pages/LumaMainPage.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ export class LumaMainPage extends BasePage {
117117
}
118118

119119
private async validateCartSubTotalPrice(expectedSubTotalPrice: string) {
120-
const cartSubTotalPriceInnerText = await this.page.locator(this.cartSubtotalPrice).innerText();
121-
expect(cartSubTotalPriceInnerText.trim()).toBe(expectedSubTotalPrice);
120+
const cartSubTotalPriceInnerText = await this.getInnerText(this.cartSubtotalPrice);
121+
expect(cartSubTotalPriceInnerText).toBe(expectedSubTotalPrice);
122122
}
123123

124124
private async modifyCartItemQuantity(itemText: string, itemQuantity: string) {
@@ -210,7 +210,11 @@ export class LumaMainPage extends BasePage {
210210
* @param inputFieldsLocator
211211
* @param options
212212
*/
213-
public async handleClientSideValidationErrors(expectedCount: number, inputFieldsLocator: Locator[], options?: ClientSideValiationErrorOptionalParamsInterface) {
213+
public async handleClientSideValidationErrors(
214+
expectedCount: number,
215+
inputFieldsLocator: Locator[],
216+
options?: ClientSideValiationErrorOptionalParamsInterface
217+
) {
214218
const cliendSideValidationError = this.page.locator(this.clientSideValidationErrorLocator);
215219
const validationErrorsCount = await this.countElements(cliendSideValidationError);
216220
expect(validationErrorsCount).toBe(expectedCount);

pages/checkoutPage/CheckOutShippingPage.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ export class CheckoutShippingPage extends LumaMainPage {
4545
* @param shippingMethod
4646
* @param options
4747
*/
48-
public async fillShippingDetails(options?: { signIn?: boolean, email?: string, password?: string, expectedUserAddressDetails?: string[] } & UserShippingDetailsParams) {
48+
public async fillShippingDetails(
49+
options?: {
50+
signIn?: boolean,
51+
email?: string,
52+
password?: string,
53+
expectedUserAddressDetails?: string[]
54+
} & UserShippingDetailsParams) {
4955
if (options?.signIn && options.email !== undefined && options.password !== undefined) {
5056
await this.signIn(options.email, options.password)
5157
await this.page.waitForTimeout(2500);

pages/checkoutPage/CheckoutReviewAndPaymentPage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class CheckoutReviewAndPaymentPage extends LumaMainPage {
1010
try {
1111
await this.changeCheckBoxState(confirmationLabel);
1212
} catch (error) {
13-
throw new Error(`error was detected when confirming billig and shipping address: ${error}`)
13+
throw new Error(`an error was detected when confirming billig and shipping address: ${error}`)
1414
}
1515
}
1616

pages/createNewAccountPage/CreateAnAccountPage.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,14 @@ export class CreateAnAccountPage extends LumaMainPage {
4545
await this.clickElement(createAccountSubmitButton);
4646
}
4747

48-
public async createNewCustomerAccount(firstname: string, lastname: string, email: string, passwordStrengh: string, registerConfirmationText: string, password: string = process.env.PASSWORD as string) {
48+
public async createNewCustomerAccount(
49+
firstname: string,
50+
lastname: string,
51+
email: string,
52+
passwordStrengh: string,
53+
registerConfirmationText: string,
54+
password: string = process.env.PASSWORD as string
55+
) {
4956
await this.clickCreateAccount();
5057
await this.fillFirstName(firstname);
5158
await this.fillLastName(lastname);

pages/loginPage/LoginPage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class LoginPage extends LumaMainPage {
1616
await this.fillText(passwordField, password);
1717
const signInButton = this.page.getByRole('button', { name: 'Sign In' });
1818
await this.clickElement(signInButton);
19-
await this.page.waitForTimeout(2500);
19+
await this.page.waitForTimeout(3500);
2020
}
2121
if (options?.negativeTest && options.expectedErrorCount !== undefined) {
2222
await this.handleClientSideValidationErrors(options.expectedErrorCount, [emailField, passwordField], options)

pages/pageComponents/sidebarShoppingComponent/SideBarShoppingComponentPage.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,19 @@ export class SideBarShoppingComponentPage extends BasePage {
2020
/**
2121
* @description validates the filtered by options if we added filters to the product that we want to purchase
2222
*/
23-
public async validateFilteredOptions(expectedFilterList: string[]) {
23+
public async validateFilteredOptions(expectedFilterList: string | string[]) {
24+
const listOfFilteredItems: string[] = [];
2425
const filteredByItems = this.page.locator(this.filteredByItemsLocator)
25-
await expect(filteredByItems).toContainText(expectedFilterList);
26+
const filteredItemsCount = await this.countElements(filteredByItems);
27+
if (filteredItemsCount > 1) {
28+
const filteredItemsList = await filteredByItems.all();
29+
for (let item of filteredItemsList) {
30+
const itemText = await this.getInnerText(item);
31+
listOfFilteredItems.push(itemText);
32+
}
33+
expect(listOfFilteredItems).toEqual(expectedFilterList);
34+
} else {
35+
await expect(filteredByItems).toContainText(expectedFilterList);
36+
}
2637
}
2738
}

0 commit comments

Comments
 (0)