Skip to content

Commit

Permalink
feat: create new account test added
Browse files Browse the repository at this point in the history
  • Loading branch information
beemi committed Jan 6, 2024
1 parent 7950b38 commit cab42d9
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 17 deletions.
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"clean:reports": "sh ./pretest.sh",
"test": "npx playwright test tests/*.spec.ts",
"test:ui": "npx playwright test --ui",
"test:ui": "npx playwright test --ui tests/*.spec.ts",
"generate:allure:report": "allure generate my-allure-results -o allure-report --clean",
"open:allure:report": "allure open allure-report"
},
Expand All @@ -24,6 +24,7 @@
},
"homepage": "https://github.com/beemi/playwright-automation-test-example#readme",
"devDependencies": {
"@faker-js/faker": "^8.3.1",
"@playwright/test": "^1.40.1",
"@types/node": "^20.10.6",
"allure-playwright": "^2.10.0",
Expand Down
6 changes: 6 additions & 0 deletions pages/home-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ export class HomePage {
}

async clickOnLoginButton() {
expect(await this.page.isVisible('text=My account')).toBeTruthy();
expect(await this.page.title()).toContain('Your Store');
// mouse over to My account 2nd element
await this.page.hover('.icon.fas.fa-user');
await this.page.click('text=Login');
expect(await this.page.title()).toContain('Account Login');
console.log('Login button clicked');
}

async clickOnRegisterButton() {
Expand Down
5 changes: 5 additions & 0 deletions pages/login-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export class LoginPage {
await this.page.fill('input[name="password"]', password);
}

async clickOnContinueButton() {
await this.page.click('text=Continue');
console.log('Continue button clicked');
}

async clickOnLoginButton() {
await this.page.click('text=Login');
}
Expand Down
44 changes: 39 additions & 5 deletions pages/register-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,52 @@ export class RegisterPage {

async navigateToRegisterPage(url: string) {
await this.page.goto(url);
console.log('Register page opened');
}

async enterUsername(username: string) {
await this.page.fill('input[name="username"]', username);
async enterFirstName(firstName: string) {
await this.page.fill('#input-firstname', firstName);
console.log('First name entered');
}

async enterLastName(lastName: string) {
await this.page.fill('#input-lastname', lastName);
console.log('Last name entered');
}

async enterEmail(email: string) {
await this.page.fill('#input-email', email);
console.log('Email entered');
}

async enterTelephone(telephone: string) {
await this.page.fill('#input-telephone', telephone);
console.log('Telephone entered');
}

async enterPassword(password: string) {
await this.page.fill('input[name="password"]', password);
await this.page.fill('#input-password', password);
console.log('Password entered');
}

async enterConfirmPassword(confirmPassword: string) {
await this.page.fill('#input-confirm', confirmPassword);
console.log('Confirm password entered');
}

async clickOnSubscribeRadioButton() {
await this.page.click('text=Yes');
console.log('Subscribe radio button clicked');
}

async clickOnPrivacyPolicyCheckbox() {
await this.page.click('label[for=input-agree]');
console.log('Privacy Policy checkbox clicked');
}

async enterConfirmPassword(password: string) {
await this.page.fill('input[name="confirmPassword"]', password);
async clickOnContinueButton() {
await this.page.click('text=Continue');
console.log('Continue button clicked');
}

async clickOnRegisterButton() {
Expand Down
42 changes: 31 additions & 11 deletions tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
import { test, expect } from '@playwright/test';
import { RegisterPage } from '../pages/register-page';
import { HomePage } from '../pages/home-page';
import { LoginPage } from '../pages/login-page';

test('has title', async ({ page }) => {
await page.goto('https://playwright.dev/');
import { faker } from '@faker-js/faker';

// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Playwright/);
});
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('get started link', async ({ page }) => {
await page.goto('https://playwright.dev/');
test('should be able to create a account', async () => {

// Click the get started link.
await page.getByRole('link', { name: 'Get started' }).click();
const password = faker.internet.password();
await homePage.navigateToHomePage('https://ecommerce-playground.lambdatest.io/'); //navigate to home page
await homePage.clickOnLoginButton();
await loginPage.clickOnContinueButton();
await registerPage.enterFirstName(faker.person.firstName());
await registerPage.enterLastName(faker.person.lastName());
await registerPage.enterEmail(faker.internet.email());
await registerPage.enterTelephone(faker.phone.number());
await registerPage.enterPassword(password);
await registerPage.enterConfirmPassword(password);
await registerPage.clickOnSubscribeRadioButton();
await registerPage.clickOnPrivacyPolicyCheckbox();
await registerPage.clickOnContinueButton();

// Expects page to have a heading with the name of Installation.
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
// get the url of the current page
});
});

0 comments on commit cab42d9

Please sign in to comment.