Skip to content

Commit

Permalink
feat: allure reports added
Browse files Browse the repository at this point in the history
  • Loading branch information
beemi committed Jan 6, 2024
1 parent 3d18e16 commit 68c3f21
Show file tree
Hide file tree
Showing 8 changed files with 742 additions and 80 deletions.
519 changes: 511 additions & 8 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@
},
"scripts": {
"clean:reports": "sh ./pretest.sh",
"codegen": "npx playwright codegen",
"test": "TEST_ENVIRONMENT=dev npx playwright test tests/*.spec.ts",
"test:ui": "npx playwright test --ui tests/*.spec.ts",
"test:ui": "TEST_ENVIRONMENT=dev npx playwright test --ui tests/*.spec.ts",
"generate:allure:report": "allure generate allure-results -o allure-report --clean",
"open:allure:report": "allure open allure-report"
},
"repository": {
"type": "git",
"url": "git+https://github.com/beemi/playwright-automation-test-example.git"
},
"author": "",
"author": {
"name": "Beemi",
"email": "beemi.raja@gmail.com"
},
"license": "ISC",
"bugs": {
"url": "https://github.com/beemi/playwright-automation-test-example/issues"
Expand All @@ -26,17 +30,18 @@
"devDependencies": {
"@faker-js/faker": "^8.3.1",
"@playwright/test": "^1.40.1",
"playwright": "1.40.0",
"@types/node": "^20.10.6",
"allure-playwright": "^2.10.0",
"assert": "^2.0.0",
"chai": "^4.3.3",
"chance": "^1.1.7",
"expect": "^26.6.2",
"playwright": "1.40.0",
"ts-node": "^10.9.2",
"typescript": "^4.4.3",
"uuid": "^8.3.2",
"ts-loader": "^9.2.6"
"ts-loader": "^9.2.6",
"winston": "^3.3.3"
},
"dependencies": {
"dotenv": "^16.3.1",
Expand Down
7 changes: 6 additions & 1 deletion pages/home-page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { expect, type Locator, type Page } from '@playwright/test';


const logger = require('../test-utils/logger')('home-page.ts');


export class HomePage {
private page: Page;

Expand All @@ -9,12 +13,13 @@ export class HomePage {

async navigateToHomePage(url: string) {
await this.page.goto(url);
console.log('Navigated to: ' + url);
logger.info('Navigated to home page');
}

async clickOnLoginButton() {
expect(await this.page.isVisible('text=My account')).toBeTruthy();
expect(await this.page.title()).toContain('Your Store');
logger.info('My account button is visible');
// mouse over to My account 2nd element
await this.page.hover('.icon.fas.fa-user');
await this.page.click('text=Login');
Expand Down
8 changes: 6 additions & 2 deletions pages/login-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ export class LoginPage {
}

async clickOnLogoutButton() {
await this.page.click('text=Logout');
await this.page.click("//a[contains(text(),'Logout')]");
console.log('Logout button clicked');
await this.page.waitForSelector('#input-email');
await this.page.waitForSelector('#common-success');
expect(await this.page.isVisible('#common-success')).toBeTruthy();
const successMessage = await this.page.textContent('#common-success');
expect(successMessage).toContain('You have been logged off your account. It is now safe to leave the computer.');
console.log('Logout success message is: ' + successMessage);
}

async clickOnBillingLineButton() {
Expand Down
4 changes: 3 additions & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {PlaywrightTestConfig} from '@playwright/test'
const config: PlaywrightTestConfig = {
globalSetup: require.resolve('./global-setup'),
timeout: 600000,
retries: 2,
retries: 0,
fullyParallel: true,
workers: 2,
use: {
baseURL: process.env.BASE_URL,
ignoreHTTPSErrors: true,
Expand Down
18 changes: 18 additions & 0 deletions test-utils/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {createLogger, transports, format} from 'winston'

const logger = createLogger({
transports: [new transports.Console()],
format: format.combine(
format.colorize(),
format.timestamp(),
format.printf(({ timestamp, level, message, service }) => {
return `[${timestamp}] ${service} ${level}: ${message}`;
})
),
});

module.exports = function (name: any) {
return logger.child({ moduleName: name })
}


70 changes: 44 additions & 26 deletions tests/login.spec.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,55 @@
import { test, expect } from '@playwright/test';
import { HomePage } from '../pages/home-page';
import { LoginPage } from '../pages/login-page';
import {expect, test} from '@playwright/test';
import {allure} from "allure-playwright";

import {HomePage} from '../pages/home-page';
import {LoginPage} from '../pages/login-page';

test.describe('Login', () => {

let homePage: HomePage;
let loginPage: LoginPage;
let homePage: HomePage;
let loginPage: LoginPage;

test.beforeEach(async ({page}) => {
homePage = new HomePage(page);
loginPage = new LoginPage(page);
});

test('should be able to login', async ({page}) => {

await allure.epic("Login");
await allure.feature("Login feature");
await allure.story("Login story");

test.beforeEach(async ({page}) => {
homePage = new HomePage(page);
loginPage = new LoginPage(page);
});
const email = process.env.USER_EMAIL_NAME;
const password = process.env.USER_PASSWORD;

test('should be able to login', async ({page}) => {
await allure.step("Navigate to home page", async () => {
await homePage.navigateToHomePage("/");
});

const email = process.env.USER_EMAIL_NAME;
const password = process.env.USER_PASSWORD;
await allure.step("Click on login button", async () => {
await homePage.clickOnLoginButton();
});

await homePage.navigateToHomePage("/");
await homePage.clickOnLoginButton();
// @ts-ignore
await loginPage.enterEmail(email);
// @ts-ignore
await loginPage.enterPassword(password);
await loginPage.clickOnLoginButton();
await allure.step("Enter email and password", async () => {
// @ts-ignore
await loginPage.enterEmail(email);
// @ts-ignore
await loginPage.enterPassword(password);
});

await allure.step("Click on login button", async () => {
await loginPage.clickOnLoginButton();
});

// get the url of the current page
const url = page.url();
expect(url).toContain('account/account');
console.log('Current page url is: ' + url);
await allure.step("Verify that user is logged in", async () => {
const url = page.url();
expect(url).toContain('account/account');
console.log('Current page url is: ' + url);
});

// logout
await loginPage.clickOnLogoutButton();
});
await allure.step("Logout", async () => {
await loginPage.clickOnLogoutButton();
});
});
});
183 changes: 145 additions & 38 deletions tests/register.spec.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,150 @@
import { test, expect } from '@playwright/test';
import { RegisterPage } from '../pages/register-page';
import { HomePage } from '../pages/home-page';
import { LoginPage } from '../pages/login-page';
import {expect, test} from '@playwright/test';
import {allure} from "allure-playwright";

import { faker } from '@faker-js/faker';
import {RegisterPage} from '../pages/register-page';
import {HomePage} from '../pages/home-page';
import {LoginPage} from '../pages/login-page';

import {faker} from '@faker-js/faker';

test.describe('Create new user account', () => {

let registerPage: RegisterPage;
let homePage: HomePage;
let loginPage: LoginPage;

test.beforeEach(async ({page}) => {
registerPage = new RegisterPage(page);
homePage = new HomePage(page);
loginPage = new LoginPage(page);
});

test('should be able to create a account', async ({page}) => {

const email = faker.internet.email();
const password = faker.internet.password();

await homePage.navigateToHomePage("/");
await homePage.clickOnLoginButton();
await loginPage.clickOnContinueButton();
await registerPage.enterFirstName(faker.person.firstName());
await registerPage.enterLastName(faker.person.lastName());
await registerPage.enterEmail(email);
await registerPage.enterTelephone(faker.phone.number());
await registerPage.enterPassword(password);
await registerPage.enterConfirmPassword(password);
await registerPage.clickOnSubscribeRadioButton();
await registerPage.clickOnPrivacyPolicyCheckbox();
await registerPage.clickOnContinueButton();

// get the url of the current page
const url = page.url();
expect(url).toContain('account/success');
console.log('Current page url is: ' + url);
});
let registerPage: RegisterPage;
let homePage: HomePage;
let loginPage: LoginPage;

test.beforeEach(async ({page}) => {

await allure.epic("Register");
await allure.feature("Register feature");
await allure.story("Register story");

registerPage = new RegisterPage(page);
homePage = new HomePage(page);
loginPage = new LoginPage(page);
});

test('should be able to create a account', async ({page}) => {

const email = faker.internet.email();
const password = faker.internet.password();

await allure.step("Navigate to home page", async () => {
await homePage.navigateToHomePage("/");
});

await allure.step("Click on login button", async () => {
await homePage.clickOnLoginButton();
});

await allure.step("Click on continue button", async () => {
await loginPage.clickOnContinueButton();
});

await allure.step("Enter first name", async () => {
await registerPage.enterFirstName(faker.person.firstName());
});

await allure.step("Enter last name", async () => {
await registerPage.enterLastName(faker.person.lastName());
});

await allure.step("Enter email", async () => {
await registerPage.enterEmail(email);
});

await allure.step("Enter telephone", async () => {
await registerPage.enterTelephone(faker.phone.number());
});

await allure.step("Enter password", async () => {
await registerPage.enterPassword(password);
});

await allure.step("Enter confirm password", async () => {
await registerPage.enterConfirmPassword(password);
});

await allure.step("Click on subscribe radio button", async () => {
await registerPage.clickOnSubscribeRadioButton();
});

await allure.step("Click on privacy policy checkbox", async () => {
await registerPage.clickOnPrivacyPolicyCheckbox();
});

await allure.step("Click on continue button", async () => {
await registerPage.clickOnContinueButton();
});

await allure.step("Verify that user is logged in", async () => {
const url = page.url();
expect(url).toContain('account/success');
console.log('Current page url is: ' + url);
});
});

test('shouln\'t be able to create a account with existing email', async ({page}) => {

const email = process.env.USER_EMAIL_NAME;
const password = faker.internet.password();

await allure.step("Navigate to home page", async () => {
await homePage.navigateToHomePage("/");

});

await allure.step("Click on login button", async () => {
await homePage.clickOnLoginButton();
});

await allure.step("Click on continue button", async () => {
await loginPage.clickOnContinueButton();
});

await allure.step("Enter first name", async () => {
await registerPage.enterFirstName(faker.person.firstName());
});

await allure.step("Enter last name", async () => {
await registerPage.enterLastName(faker.person.lastName());
});

await allure.step("Enter email", async () => {
// @ts-ignore
await registerPage.enterEmail(email);
});

await allure.step("Enter telephone", async () => {
await registerPage.enterTelephone(faker.phone.number());
});

await allure.step("Enter password", async () => {
await registerPage.enterPassword(password);
});

await allure.step("Enter confirm password", async () => {
await registerPage.enterConfirmPassword(password);
});

await allure.step("Click on subscribe radio button", async () => {
await registerPage.clickOnSubscribeRadioButton();
});

await allure.step("Click on privacy policy checkbox", async () => {
await registerPage.clickOnPrivacyPolicyCheckbox();
});

await allure.step("Click on continue button", async () => {
await registerPage.clickOnContinueButton();
});

await allure.step("Verify that Email is already registered", async () => {
const warnMessage = page.getByText('Warning: E-Mail Address is')

expect(warnMessage).toBeTruthy();
expect(warnMessage).toHaveText('Warning: E-Mail Address is already registered!');
console.log('Warning message is: ' + warnMessage);
});
});
});

0 comments on commit 68c3f21

Please sign in to comment.