Skip to content

pw locators, actions and assertions#1

Open
ChrissyDev wants to merge 3 commits intomainfrom
pw-1
Open

pw locators, actions and assertions#1
ChrissyDev wants to merge 3 commits intomainfrom
pw-1

Conversation

@ChrissyDev
Copy link
Owner

No description provided.

Copy link

@sttaran sttaran left a comment

Choose a reason for hiding this comment

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

I would expect more negative scenarios

And make them please as dedicated tests

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

test.beforeEach(async ({page})=>{
await page.goto("https://qauto.forstudy.space/");
Copy link

Choose a reason for hiding this comment

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

you baseUrl in you playwright config, use relative path

Comment on lines 13 to 17
await page.locator("#signupName").fill("Justin");
await page.locator("#signupLastName").fill("Potter");
await page.locator("#signupEmail").fill("dns-jp@test.com");
await page.locator("#signupPassword").fill("qwertY@123");
await page.locator("#signupRepeatPassword").fill("qwertY@123");
Copy link

Choose a reason for hiding this comment

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

do not hardcode values

Copy link

Choose a reason for hiding this comment

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

after you have it moved to variables you can get rid of expectedName, expectedLastName etc.

expect(passworRepeatdValue).toBe(expectedRepeatValue);

await page.getByText("Register").click();
await expect(page).toHaveURL('https://qauto.forstudy.space/panel/garage')
Copy link

Choose a reason for hiding this comment

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

use relative path

await page.locator("#signupPassword").click();
await expect(page.getByText("Email required")).toBeVisible();
await page.locator("#signupRepeatPassword").click();
await expect(page.getByText("Password required")).toBeVisible();
Copy link

Choose a reason for hiding this comment

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

you do not know where this error appears, use more precise locators

return style.borderColor;
});

expect(computedStyle).toBe('rgb(220, 53, 69)');
Copy link

Choose a reason for hiding this comment

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


test('Empty fields', async ({page})=>{
await page.locator("#signupName").click();
await page.locator("#signupLastName").click();
Copy link

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

still not resolved

const expectedValue = "qwertY@123";
expect(passwordValue).toBe(expectedValue);

const passworRepeatdValue = await page.locator("#signupPassword").evaluate(element => element.value);
Copy link

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

still not resolved

const expectedValue = "qwertY@123";
expect(passwordValue).toBe(expectedValue);

const passworRepeatdValue = await page.locator("#signupPassword").evaluate(element => element.value);
Copy link

Choose a reason for hiding this comment

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

still not resolved


test('Empty fields', async ({page})=>{
await page.locator("#signupName").click();
await page.locator("#signupLastName").click();
Copy link

Choose a reason for hiding this comment

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

still not resolved

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();
Copy link

Choose a reason for hiding this comment

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

save this locator to variable

you have to many duplicated selectors

Comment on lines +6 to +11
this.signupNameInput = '#signupName';
this.signupLastNameInput = '#signupLastName';
this.signupEmailInput = '#signupEmail';
this.signupPasswordInput = '#signupPassword';
this.signupRepeatPasswordInput = '#signupRepeatPassword';
this.registerButton = 'text=Register';
Copy link

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

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

Comment on lines +15 to +19
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);
Copy link

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

Comment on lines +36 to +42
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)');
}
Copy link

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

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

@@ -0,0 +1,54 @@
import { test, expect } from "@playwright/test";

export default class RegistrationPage {
Copy link

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
Owner Author

Choose a reason for hiding this comment

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

fixed

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

Choose a reason for hiding this comment

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

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

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants