|
| 1 | +// @fixturesetup is the alias path set up for importing fixtures from testFixtures file. |
| 2 | +// Don't have to import individual page objects because they are initialized in fixtures and passed as test parameters. |
| 3 | +import { test } from '@fixturesetup'; |
| 4 | +import { standardUserCredentials, visualTestUserCredentials } from '@testdata/sauce-demo-test-data'; |
| 5 | + |
| 6 | +test.describe.configure({ mode: 'parallel' }); |
| 7 | +/** |
| 8 | + * To run tests with different user storageStates in the same spec file then isolate them in to test.describe blocks |
| 9 | + * See https://playwright.dev/docs/next/auth#multiple-signed-in-roles |
| 10 | + */ |
| 11 | +test.describe('Saucedemo tests for successful, unsuccessful logins and add products to cart @smoke', () => { |
| 12 | + // beforEach hook to navigate to home page in each test |
| 13 | + test.beforeEach('Navigating to sauce demo page', async ({ loginPage }) => { |
| 14 | + await loginPage.navigateToSauceDemoLoginPage(); |
| 15 | + }); |
| 16 | + test('Saucedemo tests - Successful login will display Products Page', async ({ loginPage, productsPage }) => { |
| 17 | + await loginPage.loginWithValidCredentials(standardUserCredentials); |
| 18 | + // verifying products page is displayed on successful login |
| 19 | + await productsPage.verifyProductsPageIsDisplayed(); |
| 20 | + }); |
| 21 | + |
| 22 | + test('Saucedemo test - Add product to cart', async ({ loginPage, productsPage, miniCartPage }) => { |
| 23 | + await loginPage.loginWithValidCredentials(visualTestUserCredentials); |
| 24 | + await productsPage.verifyProductsPageIsDisplayed(); |
| 25 | + await productsPage.addToCartByProductNumber(1); |
| 26 | + // verifying mini cart count is updated to 1 |
| 27 | + await miniCartPage.verifyMiniCartCount('1'); |
| 28 | + }); |
| 29 | + |
| 30 | + test('Saucedemo test - Products page is not displayed on failed login', async ({ loginPage, productsPage }) => { |
| 31 | + await loginPage.loginWithInvalidCredentials(); |
| 32 | + // verifying Login is still displayed |
| 33 | + await loginPage.verifyLoginPageIsDisplayed(); |
| 34 | + // verifying Products Page is not displayed |
| 35 | + await productsPage.verifyProductsPageIsNotDisplayed(); |
| 36 | + }); |
| 37 | +}); |
0 commit comments