From 4369d4a398cb05dad71aa4ad7948a0b155e054ae Mon Sep 17 00:00:00 2001 From: Krzysiek Stala Date: Thu, 27 Apr 2023 11:48:18 +0200 Subject: [PATCH] fix: flaky tests improvements (#178) --- apps/e2e-tests/page-objects/CartPage.ts | 2 +- apps/e2e-tests/page-objects/CheckoutPage.ts | 6 +++-- apps/e2e-tests/page-objects/HomePage.ts | 24 +++++++++++--------- apps/e2e-tests/page-objects/LoginPage.ts | 3 +-- apps/e2e-tests/page-objects/MyAccountPage.ts | 5 ++-- apps/e2e-tests/page-objects/ProductPage.ts | 11 +++++---- apps/e2e-tests/page-objects/RegisterPage.ts | 15 ++++++++---- 7 files changed, 38 insertions(+), 28 deletions(-) diff --git a/apps/e2e-tests/page-objects/CartPage.ts b/apps/e2e-tests/page-objects/CartPage.ts index 50da58db9..a0210b4e1 100644 --- a/apps/e2e-tests/page-objects/CartPage.ts +++ b/apps/e2e-tests/page-objects/CartPage.ts @@ -14,7 +14,7 @@ export class CartPage { } async openMiniCart() { - await this.page.waitForLoadState(); + await this.miniCartLink.waitFor(); await this.miniCartLink.click(); } diff --git a/apps/e2e-tests/page-objects/CheckoutPage.ts b/apps/e2e-tests/page-objects/CheckoutPage.ts index bf660d119..da2aeb5e1 100644 --- a/apps/e2e-tests/page-objects/CheckoutPage.ts +++ b/apps/e2e-tests/page-objects/CheckoutPage.ts @@ -40,8 +40,10 @@ export class CheckoutPage { } async goToCheckout() { - await this.page.waitForSelector("[data-testid='cart-product-image']"); - await this.goToCheckoutButton.click(); + await Promise.all([ + await this.page.waitForSelector("[data-testid='cart-product-image']"), + await this.goToCheckoutButton.click(), + ]); } async markTerms() { diff --git a/apps/e2e-tests/page-objects/HomePage.ts b/apps/e2e-tests/page-objects/HomePage.ts index a23e4fcb3..94dafa576 100644 --- a/apps/e2e-tests/page-objects/HomePage.ts +++ b/apps/e2e-tests/page-objects/HomePage.ts @@ -32,13 +32,13 @@ export class HomePage extends AbstractPage { } async clickOnSignIn() { - await this.page.waitForLoadState("load"); - await this.signInButton.isEnabled(); - await this.signInButton.click(); + await expect(this.page.getByTestId("header-sign-in-link")).toBeVisible(); + await this.signInButton.waitFor(); + await this.signInButton.dispatchEvent("click"); } async openCartPage() { - await this.page.waitForLoadState("load"); + await this.linkToCartPage.waitFor(); await this.linkToCartPage.click(); await this.page.waitForSelector("[data-testid='product-quantity']"); await this.page.waitForLoadState("load"); @@ -51,9 +51,10 @@ export class HomePage extends AbstractPage { } async openRegistrationPage() { - await this.page.waitForLoadState("load"); - await this.linkToRegistrationPage.isVisible(); - await this.linkToRegistrationPage.click(); + await Promise.all([ + await this.page.waitForLoadState("load"), + await this.linkToRegistrationPage.click(), + ]); } async typeSearchPhrase(phrase: string) { @@ -65,13 +66,14 @@ export class HomePage extends AbstractPage { async addProductToWishlist() { await Promise.all([ this.page.waitForLoadState("load"), - await this.addToWishlist.nth(13).click(), + await this.addToWishlist.nth(13).dispatchEvent("click"), ]); } async openMyAccount() { - this.page.waitForLoadState("load"); - await this.accountMenuHelloButton.click(); - await this.myAccountLink.click(); + await this.accountMenuHelloButton.waitFor(); + await this.accountMenuHelloButton.dispatchEvent("click"); + await this.myAccountLink.waitFor(); + await this.myAccountLink.dispatchEvent("click"); } } diff --git a/apps/e2e-tests/page-objects/LoginPage.ts b/apps/e2e-tests/page-objects/LoginPage.ts index d28ec0ed4..1c319494c 100644 --- a/apps/e2e-tests/page-objects/LoginPage.ts +++ b/apps/e2e-tests/page-objects/LoginPage.ts @@ -20,8 +20,7 @@ export class LoginForm { await this.usernameInput.isVisible(); await this.usernameInput.type(username); await this.passwordInput.type(password); - await this.page.waitForLoadState("load"); + await this.page.waitForLoadState(); await this.submitButton.click(); - await this.page.waitForLoadState("load"); } } diff --git a/apps/e2e-tests/page-objects/MyAccountPage.ts b/apps/e2e-tests/page-objects/MyAccountPage.ts index 625f293b8..2b1963f81 100644 --- a/apps/e2e-tests/page-objects/MyAccountPage.ts +++ b/apps/e2e-tests/page-objects/MyAccountPage.ts @@ -44,9 +44,8 @@ export class MyAccountPage { } async changePersonalData() { - await this.page.waitForLoadState(); - await this.accountChangeProfileButton.click(); - await this.page.waitForLoadState("load"); + await this.accountChangeProfileButton.waitFor(); + await this.accountChangeProfileButton.dispatchEvent("click"); } async changePersonalFirstName(firstname: string) { diff --git a/apps/e2e-tests/page-objects/ProductPage.ts b/apps/e2e-tests/page-objects/ProductPage.ts index cf3c0f0cb..8a757e9d2 100644 --- a/apps/e2e-tests/page-objects/ProductPage.ts +++ b/apps/e2e-tests/page-objects/ProductPage.ts @@ -20,7 +20,8 @@ export class ProductPage { } async addToCart() { - await this.page.waitForLoadState("load"); + await expect(this.page.getByTestId("add-to-cart-button")).toBeVisible(); + await this.addToCartButton.waitFor(); await this.addToCartButton.click(); } @@ -29,14 +30,16 @@ export class ProductPage { .getByTestId("product-variant-text") .all()) await variant.click(), await this.page.waitForLoadState("load"); - await this.addToCartButton.isEnabled(); + await this.addToCartButton.waitFor(); await this.addToCartButton.click(); await this.miniCartLink.click(); expect(this.variantText.textContent).toEqual( this.productOption.textContent ); - await this.page.waitForLoadState("load"); - await this.productRemove.click(); + await Promise.all([ + await this.page.waitForLoadState("load"), + await this.productRemove.click(), + ]); await this.page.getByTestId("cart-close-button").click(); } } diff --git a/apps/e2e-tests/page-objects/RegisterPage.ts b/apps/e2e-tests/page-objects/RegisterPage.ts index 2d1c5cb2b..e430d2349 100644 --- a/apps/e2e-tests/page-objects/RegisterPage.ts +++ b/apps/e2e-tests/page-objects/RegisterPage.ts @@ -50,16 +50,19 @@ export class RegisterForm { await this.zipcode.type(zipcode); await this.city.type(city); await this.country.selectOption({ label: "Germany" }); - await this.page.waitForLoadState("load"); } async submitRegistraionForm() { - await this.page.waitForLoadState("load"); - await this.submitButton.click(); + await Promise.all([ + this.page.waitForLoadState(), + await this.submitButton.dispatchEvent("click"), + ]); + await this.page.waitForSelector( + "[data-testid='product-box-wishlist-icon-not-in']" + ); } async createUser() { - await this.page.waitForLoadState(); await this.salutation.selectOption({ label: "Mr." }); await this.firstName.type("e2e " + faker.name.firstName()); await this.lastName.type("e2e " + faker.name.lastName()); @@ -69,7 +72,9 @@ export class RegisterForm { await this.zipcode.type(faker.address.zipCode()); await this.city.type(faker.address.city()); await this.country.selectOption({ label: "Germany" }); - await this.page.waitForLoadState("load"); await this.submitButton.click(); + await this.page.waitForSelector( + "[data-testid='product-box-wishlist-icon-not-in']" + ); } }