Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"license": "ISC",
"type": "module",
"devDependencies": {
"@faker-js/faker": "^8.4.1",
"@playwright/test": "^1.42.1",
"@types/node": "^20.11.30"
}
Expand Down
54 changes: 54 additions & 0 deletions pageObjects/RegistrationPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { test, expect } from "@playwright/test";

export default class RegistrationPage {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no registration page as well as login page

You can call it MainPage or WelcomePage or smth like that

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

constructor(page) {
this.page = page;
this.signupNameInput = '#signupName';
this.signupLastNameInput = '#signupLastName';
this.signupEmailInput = '#signupEmail';
this.signupPasswordInput = '#signupPassword';
this.signupRepeatPasswordInput = '#signupRepeatPassword';
this.registerButton = 'text=Register';
Comment on lines +6 to +11

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create locators instead of selectors

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this fields to a components such as RegistrationPopup

}

async fillRegistrationForm(name, lastName, email, password) {
await this.page.fill(this.signupNameInput, name);
await this.page.fill(this.signupLastNameInput, lastName);
await this.page.fill(this.signupEmailInput, email);
await this.page.fill(this.signupPasswordInput, password);
await this.page.fill(this.signupRepeatPasswordInput, password);
Comment on lines +15 to +19

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

page.fill is not recommended
image

}

async triggerWarningMessagesForFields() {
await this.page.click(this.signupNameInput);
await this.page.click(this.signupLastNameInput);
await this.page.click(this.signupEmailInput);
await this.page.click(this.signupPasswordInput);
await this.page.click(this.signupRepeatPasswordInput);
await this.page.click(this.signupNameInput);
}

async clickRegisterButton() {
await this.page.click(this.registerButton);
}


async validateRedBorder() {
await expect(this.page.locator(this.signupNameInput)).toHaveCSS('border-color', 'rgb(220, 53, 69)');
await expect(this.page.locator(this.signupLastNameInput)).toHaveCSS('border-color', 'rgb(220, 53, 69)');
await expect(this.page.locator(this.signupEmailInput)).toHaveCSS('border-color', 'rgb(220, 53, 69)');
await expect(this.page.locator(this.signupPasswordInput)).toHaveCSS('border-color', 'rgb(220, 53, 69)');
await expect(this.page.locator(this.signupRepeatPasswordInput)).toHaveCSS('border-color', 'rgb(220, 53, 69)');
}
Comment on lines +36 to +42

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

page objects are for interacting with page

assertions should not be in POM

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method btw in not universal since you can't check only one field with it


async validateEmptyFieldsFeedback() {
await expect(this.page.locator(this.signupNameInput + ' + .invalid-feedback')).toBeVisible();
await expect(this.page.locator(this.signupLastNameInput + ' + .invalid-feedback')).toBeVisible();
await expect(this.page.locator(this.signupEmailInput + ' + .invalid-feedback')).toBeVisible();
await expect(this.page.locator(this.signupPasswordInput + ' + .invalid-feedback')).toBeVisible();
await expect(this.page.locator(this.signupRepeatPasswordInput + ' + .invalid-feedback')).toBeVisible();
}
}

// module.exports = RegistrationPage;

2 changes: 1 addition & 1 deletion playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const config = defineConfig({
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
headless: false,
baseURL: 'https://quato.forstudy.space/',
baseURL: 'https://qauto.forstudy.space/',
httpCredentials:{
username: "guest",
password: 'welcome2qauto'
Expand Down
52 changes: 0 additions & 52 deletions tests/example.spec.js

This file was deleted.

219 changes: 219 additions & 0 deletions tests/qauto/homework1.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
import { test, expect } from "@playwright/test";
import { faker } from '@faker-js/faker';
import RegistrationPage from "../../pageObjects/RegistrationPage";


test.describe('Registration form test', () => {
let registrationPage;

test.beforeEach(async ({ page }) => {
await page.goto('/');
await page.locator('.btn-primary').click();
await expect(page.locator('.modal-content')).toBeVisible();
registrationPage = new RegistrationPage(page);
});

test('Positive', async ({ page }) => {
const signupName = faker.person.firstName();
const signupLastName = faker.person.lastName();
const signupEmail = faker.internet.email();
const signupPassword = faker.internet.password();

await registrationPage.fillRegistrationForm(signupName, signupLastName, signupEmail, signupPassword);

const name = await page.locator('#signupName').evaluate(element => element.value);
expect(name).toBe(signupName);
Comment on lines +24 to +25

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


const lastName = await page.locator('#signupLastName').evaluate(element => element.value);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not use selectors in tests

expect(lastName).toBe(signupLastName);

const email = await page.locator('#signupEmail').evaluate(element => element.value);
expect(email).toBe(signupEmail);

const passwordValue = await page.locator('#signupPassword').evaluate(element => element.value);
expect(passwordValue).toBe(signupPassword);

await registrationPage.clickRegisterButton();
await expect(page).toHaveURL('/panel/garage');
});

test('Empty fields', async ({ page }) => {
// await registrationPage.clickRegisterButton();
await registrationPage.triggerWarningMessagesForFields();
await registrationPage.validateEmptyFieldsFeedback();
});

test('Check red border', async ({ page }) => {
await registrationPage.triggerWarningMessagesForFields();
await registrationPage.validateRedBorder();
// await registrationPage.clickRegisterButton();
// await registrationPage.validateRedBorder();
});
});

export {};


// import { test, expect } from "@playwright/test";
// import { faker } from '@faker-js/faker';
// import RegistrationPage from "../../pageObjects/RegistrationPage"; // Adjust import path

// test.describe('Registration form test', () => {
// let registrationPage;

// test.beforeEach(async ({ page }) => { // Use 'page' provided as a parameter
// await page.goto('/');
// await page.locator('.btn-primary').click();
// await expect(page.locator('.modal-content')).toBeVisible();
// registrationPage = new RegistrationPage(page);
// });

// test('Positive', async ({ page }) => { // Use 'page' provided as a parameter
// const signupName = faker.person.firstName();
// const signupLastName = faker.person.lastName();
// const signupEmail = faker.internet.email();
// const signupPassword = faker.internet.password();

// await registrationPage.fillRegistrationForm(signupName, signupLastName, signupEmail, signupPassword);

// const name = await page.locator('#signupName').evaluate(element => element.value);
// expect(name).toBe(signupName);

// const lastName = await page.locator('#signupLastName').evaluate(element => element.value);
// expect(lastName).toBe(signupLastName);

// const email = await page.locator('#signupEmail').evaluate(element => element.value);
// expect(email).toBe(signupEmail);

// const passwordValue = await page.locator('#signupPassword').evaluate(element => element.value);
// expect(passwordValue).toBe(signupPassword);

// await registrationPage.clickRegisterButton();
// await expect(page).toHaveURL('/panel/garage');
// });
// });

// import { test, expect } from "@playwright/test";
// import { faker } from '@faker-js/faker';
// import RegistrationPage from "../../pageObjects/RegistrationPage";


// test.describe('Registration form test', () => {
// let page;
// let registrationPage;

// test.beforeEach(async ({ page }) => {
// await page.goto('/');
// await page.locator('.btn-primary').click();
// await expect(page.locator('.modal-content')).toBeVisible();
// registrationPage = new RegistrationPage(page);
// });

// test('Positive', async () => {
// const signupName = faker.person.firstName();
// const signupLastName = faker.person.lastName();
// const signupEmail = faker.internet.email();
// const signupPassword = faker.internet.password();

// await registrationPage.fillRegistrationForm(signupName, signupLastName, signupEmail, signupPassword);

// const name = await page.locator('#signupName').evaluate(element => element.value);
// expect(name).toBe(signupName);

// const lastName = await page.locator('#signupLastName').evaluate(element => element.value);
// expect(lastName).toBe(signupLastName);

// const email = await page.locator('#signupEmail').evaluate(element => element.value);
// expect(email).toBe(signupEmail);

// const passwordValue = await page.locator('#signupPassword').evaluate(element => element.value);
// expect(passwordValue).toBe(signupPassword);

// await registrationPage.clickRegisterButton();
// await expect(page).toHaveURL('/panel/garage');
// });

// test('Empty fields', async () => {
// await registrationPage.clickRegisterButton();
// await registrationPage.validateEmptyFieldsFeedback();
// });

// test('Check red border', async () => {
// await registrationPage.validateRedBorder();
// await registrationPage.clickRegisterButton();
// await registrationPage.validateRedBorder();
// });
// });


// const signupName = faker.person.firstName();
// const signupLastName = faker.person.lastName();
// const signupEmail = faker.internet.email();
// const signupPassword = faker.internet.password();


// test.describe('Registration form test', () => {

// test.beforeEach(async ({page})=>{
// await page.goto("/");
// await page.locator(".btn-primary").click();
// await expect(page.locator(".modal-content")).toBeVisible();
// })

// test('Positive', async ({ page }) => {
// await page.locator("#signupName").fill(signupName);
// await page.locator("#signupLastName").fill(signupLastName);
// await page.locator("#signupEmail").fill(signupEmail);
// await page.locator("#signupPassword").fill(signupPassword);
// await page.locator("#signupRepeatPassword").fill(signupPassword);


// const name = await page.locator("#signupName").evaluate(element => element.value);
// expect(name).toBe(signupName);

// const lastName = await page.locator("#signupLastName").evaluate(element => element.value);
// expect(lastName).toBe(signupLastName);

// const email = await page.locator("#signupEmail").evaluate(element => element.value);
// expect(email).toBe(signupEmail);

// const passwordValue = await page.locator("#signupPassword").evaluate(element => element.value);
// expect(passwordValue).toBe(signupPassword);

// const passworRepeatdValue = await page.locator("#signupPassword").evaluate(element => element.value);
// expect(passworRepeatdValue).toBe(signupPassword);

// await page.getByText("Register").click();
// await expect(page).toHaveURL('/' + 'panel/garage')
// });

// test('Empty fields', async ({page})=>{
// await page.locator("#signupName").click();
// await page.locator("#signupLastName").click();
// await expect(page.locator("#signupName + .invalid-feedback")).toBeVisible();
// await page.locator("#signupEmail").click();
// await expect(page.locator("#signupLastName + .invalid-feedback")).toBeVisible();
// await page.locator("#signupPassword").click();
// await expect(page.locator("#signupEmail + .invalid-feedback")).toBeVisible();
// await page.locator("#signupRepeatPassword").click();
// await expect(page.locator("#signupPassword + .invalid-feedback")).toBeVisible();
// await page.getByText("Registration").click();
// await expect(page.locator("#signupRepeatPassword + .invalid-feedback")).toBeVisible();
// })

// test('Check red border', async ({ page }) => {
// await page.locator("#signupName").click();
// await page.locator("#signupLastName").click();
// await expect(page.locator("#signupName")).toHaveCSS('border-color', 'rgb(220, 53, 69)');
// await page.locator("#signupEmail").click();
// await expect(page.locator("#signupLastName")).toHaveCSS('border-color', 'rgb(220, 53, 69)');
// await page.locator("#signupPassword").click();
// await expect(page.locator("#signupEmail")).toHaveCSS('border-color', 'rgb(220, 53, 69)');
// await page.locator("#signupRepeatPassword").click();
// await expect(page.locator("#signupPassword")).toHaveCSS('border-color', 'rgb(220, 53, 69)');
// await page.getByText("Registration").click();
// await expect(page.locator("#signupRepeatPassword")).toHaveCSS('border-color', 'rgb(220, 53, 69)');
// });

// });