diff --git a/README.md b/README.md index be9f987..ae9029f 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,14 @@ # Playwright-Store +[![Build status] (https://github.com/JakubRumpca/Playwright-Store/blob/main/.github/workflows/pipeline.yml/badge.svg)](https://github.com/JakubRumpca/Playwright-Store/actions/workflows/pipeline.yml) The repository contains playwright automated tests of the online store available at https://www.saucedemo.com/. The website was created for training purposes, where you can practice testing web applications on it, so using bots such as automatic tests is allowed and does not violate the regulations. ## Technologies - **TypeScript** -- **Node** - The version I use is v18.18.0. (It is required for dependency installation) -- **NPM** - The version I use is 9.8.1. -- **Java** - The version I use is 17.0.11. (Needed to run the Allure test reporting tool) +- **Node** - Version used -> 20. (It is required for dependency installation) +- **NPM** - Version used -> 10. +- **Java** - Version used -> 21. (Needed to run the Allure test reporting tool) ## Repository content @@ -22,8 +23,40 @@ The repository contains playwright automated tests of the online store available To run the tests, follow these steps: -- **npm install** - to install dependencies. -- remove **.template** from the file name **.env.template**. It defines the secrets needed to log in. -- **npm run tests** - runs all e2e tests. -- **npm run report** - runs the Allure tool which generates an HTML report that contains test results, which facilitates analysis. -- **npm run tests 'file name'** - To run the selected test, add the file name at the end of the command. Example -> **npm run tests users.spec.ts** +1. Install dependencies: + +```bash +npm install +``` + +2. Install playwright browsers: + +```bash +npx playwright install +``` + +3. remove **.template** from the file name **.env.template**. It defines the secrets needed to log in. + +```bash +cp .env.template .env +``` + +4. To runs all e2e tests: + +```bash +npm run tests +``` + +5. To run the Allure tool which generates an HTML report that contains test results, which facilitates analysis: + +```bash +npm run report +``` + +6. To run the selected test, add the file name at the end of the command. (**npm run tests 'file name'**) + +Example: + +```bash +npm run tests users.spec.ts +``` \ No newline at end of file diff --git a/tests/order.spec.ts b/tests/order.spec.ts index 46313ff..7707e0a 100644 --- a/tests/order.spec.ts +++ b/tests/order.spec.ts @@ -11,14 +11,19 @@ const orderData: customerData = { postalCode: "84-200" }; const inventoryItemListLocator: string = '[data-test="inventory-item"]'; +let homePage: HomePage; +let cart: Cart; -test('Should order backpack and bike light', async ({ page }) => { +test.beforeEach(async ({page}) => { const loginPage = new LoginPage(page); - const homePage = new HomePage(page); + homePage = new HomePage(page); + cart = new Cart(page); + await loginPage.login(process.env.STANDARD_USER, process.env.PASSWORD); +}) + +test('Should order backpack and bike light', async ({ page }) => { const customerCheckoutForm = new CustomerCheckoutForm(page); - const cart = new Cart(page); const checkout = new Checkout(page); - await loginPage.login(process.env.STANDARD_USER, process.env.PASSWORD); await homePage.addProduct("backpack"); await homePage.addProduct("bike-light"); await homePage.goToYourCart(); @@ -30,10 +35,6 @@ test('Should order backpack and bike light', async ({ page }) => { }); test('Should add three products to the cart and then remove one of them', async ({ page }) => { - const loginPage = new LoginPage(page); - const homePage = new HomePage(page); - const cart = new Cart(page); - await loginPage.login(process.env.STANDARD_USER, process.env.PASSWORD); await homePage.addProduct("backpack"); await homePage.addProduct("bike-light"); await homePage.addProduct("onesie"); diff --git a/tests/users.spec.ts b/tests/users.spec.ts index 8297ece..6b2d6aa 100644 --- a/tests/users.spec.ts +++ b/tests/users.spec.ts @@ -1,14 +1,18 @@ import { test, expect } from '@playwright/test'; import { LoginPage } from '../page_object/loginPage'; +let loginPage: LoginPage + +test.beforeEach(async ({page}) => { + loginPage = new LoginPage(page); +}) + test('Should check if the standard user can log in', async ({ page }) => { - const loginPage = new LoginPage(page); await loginPage.login(process.env.STANDARD_USER, process.env.PASSWORD); await expect(page.locator('[data-test="title"]')).toContainText('Products'); }); test('Should check if the locked user can not log in', async ({ page }) => { - const loginPage = new LoginPage(page); await loginPage.login(process.env.LOCKED_USER, process.env.PASSWORD); await expect(page.locator('[data-test="error"]')).toContainText('Epic sadface: Sorry, this user has been locked out.'); });