Skip to content

Commit

Permalink
Add before.all & update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubRumpca committed Jun 12, 2024
1 parent fb7dc63 commit fa6b6ff
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 18 deletions.
49 changes: 41 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
```
17 changes: 9 additions & 8 deletions tests/order.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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");
Expand Down
8 changes: 6 additions & 2 deletions tests/users.spec.ts
Original file line number Diff line number Diff line change
@@ -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.');
});

0 comments on commit fa6b6ff

Please sign in to comment.