Skip to content

Commit

Permalink
Chore: Tests refactor pageobjects (#26245)
Browse files Browse the repository at this point in the history
Co-authored-by: Weslley de Campos <weslley.campos@objective.com.br>
  • Loading branch information
souzaramon and weslley543 committed Jul 19, 2022
1 parent 9b523a6 commit c6663cb
Show file tree
Hide file tree
Showing 47 changed files with 1,836 additions and 2,716 deletions.
3 changes: 3 additions & 0 deletions apps/meteor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
"deploy": "npm run build && pm2 startOrRestart pm2.json",
"coverage": "nyc -r html mocha --config ./.mocharc.js",
"test:e2e": "playwright test",
<<<<<<< HEAD
"test:e2e:nyc": "nyc report --reporter=text-summary --reporter=lcov",
=======
>>>>>>> Chore: Tests refactor pageobjects (#26245)
"testapi": "mocha --config ./.mocharc.api.js",
"testunit": "npm run .testunit:definition && npm run .testunit:client && npm run .testunit:server",
".testunit:server": "mocha --config ./.mocharc.js",
Expand Down
203 changes: 187 additions & 16 deletions apps/meteor/tests/e2e/00-wizard.spec.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,198 @@
import { Page } from '@playwright/test';
import { Page, Locator } from '@playwright/test';

import { test, expect } from './utils/test';
import { adminLogin } from './utils/mocks/userAndPasswordMock';
import { setupWizardStepRegex } from './utils/mocks/urlMock';
import { HOME_SELECTOR } from './utils/mocks/waitSelectorsMock';
import { LoginPage, SetupWizard } from './pageobjects';


import { Auth } from './page-objects';
import { ADMIN_CREDENTIALS } from './utils/constants';

class SetupWizard {
private readonly page: Page;

constructor(page: Page) {
this.page = page;
}

private get nextStep(): Locator {
return this.page.locator('//button[contains(text(), "Next")]');
}

private get fullName(): Locator {
return this.page.locator('[name="fullname"]');
}

private get userName(): Locator {
return this.page.locator('[name="username"]');
}

private get companyEmail(): Locator {
return this.page.locator('[name="companyEmail"]');
}

private get password(): Locator {
return this.page.locator('[name="password"]');
}

get goToWorkspace(): Locator {
return this.page.locator('//button[contains(text(), "Confirm")]');
}

get organizationType(): Locator {
return this.page.locator('[name="organizationType"]');
}

get organizationTypeSelect(): Locator {
return this.page.locator('.rcx-options .rcx-option:first-child');
}

get organizationName(): Locator {
return this.page.locator('[name="organizationName"]');
}

get industry(): Locator {
return this.page.locator('[name="organizationIndustry"]');
}

get industrySelect(): Locator {
return this.page.locator('.rcx-options .rcx-option:first-child');
}

get size(): Locator {
return this.page.locator('[name="organizationSize"]');
}

get sizeSelect(): Locator {
return this.page.locator('.rcx-options .rcx-option:first-child');
}

get country(): Locator {
return this.page.locator('[name="country"]');
}

get countrySelect(): Locator {
return this.page.locator('.rcx-options .rcx-option:first-child');
}

get registeredServer(): Locator {
return this.page.locator('input[name=email]');
}

get registerButton(): Locator {
return this.page.locator('//button[contains(text(), "Register")]');
}

get agreementField(): Locator {
return this.page.locator('//input[@name="agreement"]/../i[contains(@class, "rcx-check-box")]');
}

get standaloneServer(): Locator {
return this.page.locator('//a[contains(text(), "Continue as standalone")]');
}

get standaloneConfirmText(): Locator {
return this.page.locator('//*[contains(text(), "Standalone Server Confirmation")]');
}

get fullNameInvalidText(): Locator {
return this.page.locator('//input[@name="fullname"]/../following-sibling::span');
}

get userNameInvalidText(): Locator {
return this.page.locator('//input[@name="username"]/../following-sibling::span');
}

get companyEmailInvalidText(): Locator {
return this.page.locator('//input[@name="companyEmail"]/../following-sibling::span');
}

get passwordInvalidText(): Locator {
return this.page.locator('//input[@name="password"]/../../../span[contains(@class, "rcx-field__error")]');
}

get industryInvalidSelect(): Locator {
return this.page.locator('//div[@name="organizationIndustry"]/../following-sibling::span');
}

get sizeInvalidSelect(): Locator {
return this.page.locator('//div[@name="organizationSize"]/../following-sibling::span');
}

get countryInvalidSelect(): Locator {
return this.page.locator('//div[@name="country"]/../following-sibling::span');
}

get stepThreeInputInvalidMail(): Locator {
return this.page.locator('//input[@name="email"]/../../span[contains(text(), "This field is required")]');
}

async stepTwoSuccess(): Promise<void> {
await this.organizationName.type('rocket.chat.reason');
await this.organizationType.click();
await this.organizationTypeSelect.click();
await expect(this.page.locator('.rcx-options')).toHaveCount(0);
await this.industry.click();
await this.industrySelect.click();
await expect(this.page.locator('.rcx-options')).toHaveCount(0);
await this.size.click();
await this.sizeSelect.click();
await expect(this.page.locator('.rcx-options')).toHaveCount(0);
await this.country.click();
await this.countrySelect.click();
await this.nextStep.click();
}

async stepThreeSuccess(): Promise<void> {
await this.standaloneServer.click();
}

async stepOneFailedBlankFields(): Promise<void> {
await this.nextStep.click();
await expect(this.fullNameInvalidText).toBeVisible();
await expect(this.userNameInvalidText).toBeVisible();
await expect(this.companyEmailInvalidText).toBeVisible();
await expect(this.passwordInvalidText).toBeVisible();
}

async stepOneFailedWithInvalidEmail(adminCredentials: { name: string; password: string }): Promise<void> {
await this.fullName.type(adminCredentials.name);
await this.userName.type(adminCredentials.name);
await this.companyEmail.type('mail');
await this.password.type(adminCredentials.password);
await this.nextStep.click();
await expect(this.companyEmail).toBeFocused();
}

async stepTwoFailedWithBlankFields(): Promise<void> {
await this.nextStep.click();
await expect(this.organizationName).toBeVisible();
await expect(this.industryInvalidSelect).toBeVisible();
await expect(this.sizeInvalidSelect).toBeVisible();
await expect(this.countryInvalidSelect).toBeVisible();
}

async stepThreeFailedWithInvalidField(): Promise<void> {
await this.registeredServer.type('mail');
await this.registeredServer.click({ clickCount: 3 });
await this.page.keyboard.press('Backspace');
await expect(this.stepThreeInputInvalidMail).toBeVisible();
}
}

test.describe('[Wizard]', () => {
let setupWizard: SetupWizard;
let loginPage: LoginPage;
let page: Page;
let pageAuth: Auth;

let setupWizard: SetupWizard;

test.beforeEach(async ({ browser }) => {
page = await browser.newPage();
pageAuth = new Auth(page);
setupWizard = new SetupWizard(page);
loginPage = new LoginPage(page);
});

test.describe('[Step 2]', async () => {
test.beforeEach(async () => {
await page.goto('/');
await loginPage.doLogin(adminLogin, false);
await pageAuth.doLogin(ADMIN_CREDENTIALS, false);
});

test('expect required field alert showed when user dont inform data', async () => {
Expand All @@ -29,14 +201,13 @@ test.describe('[Wizard]', () => {

test('expect go to Step 3 successfully', async () => {
await setupWizard.stepTwoSuccess();
await expect(setupWizard.page).toHaveURL(setupWizardStepRegex._3);
await expect(page).toHaveURL(/.*\/setup-wizard\/3/);
});
});

test.describe('[Step 3]', async () => {
test.beforeEach(async () => {
await page.goto('');
await loginPage.doLogin(adminLogin, false);
await pageAuth.doLogin(ADMIN_CREDENTIALS, false);
await setupWizard.stepTwoSuccess();
});

Expand Down Expand Up @@ -65,8 +236,7 @@ test.describe('[Wizard]', () => {

test.describe('[Final Step]', async () => {
test.beforeEach(async () => {
await page.goto('');
await loginPage.doLogin(adminLogin, false);
await pageAuth.doLogin(ADMIN_CREDENTIALS, false);
await setupWizard.stepTwoSuccess();
await setupWizard.stepThreeSuccess();
});
Expand All @@ -78,7 +248,8 @@ test.describe('[Wizard]', () => {

test('expect confirm standalone', async () => {
await setupWizard.goToWorkspace.click();
await page.waitForSelector(HOME_SELECTOR);
// HOME_SELECTOR
await page.waitForSelector('//span[@class="rc-header__block"]');
});
});
});
53 changes: 30 additions & 23 deletions apps/meteor/tests/e2e/01-forgot-password.spec.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
import { test, expect } from './utils/test';
import { Global, LoginPage } from './pageobjects';
import { Page } from '@playwright/test'

test.describe('[Forgot Password]', () => {
let loginPage: LoginPage;
let global: Global;
import { Auth } from './page-objects';

test.beforeEach(async ({ page }) => {
loginPage = new LoginPage(page);
global = new Global(page);
test.describe('Forgot Password', () => {
let page: Page;
let pageAuth: Auth;

test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
pageAuth = new Auth(page);
});

test.beforeAll(async () => {
await page.goto('/');
await loginPage.btnForgotPassword.click();
await pageAuth.btnForgotPassword.click();
});

test('expect be required', async () => {
loginPage.btnSubmit.click();
test('expect trigger a validation error if no email is provided', async () => {
await pageAuth.btnSubmit.click();

await expect(loginPage.emailInvalidText).toBeVisible();
await expect(pageAuth.textErrorEmail).toBeVisible();
});

test('expect invalid for email without domain', async () => {
await loginPage.emailField.type('mail');
await loginPage.btnSubmit.click();
await expect(loginPage.emailInvalidText).toBeVisible();
test('expect trigger a validation if a invalid email is provided (1)', async () => {
await pageAuth.inputEmail.type('mail');
await pageAuth.btnSubmit.click();

await expect(pageAuth.textErrorEmail).toBeVisible();
});

test('expect be invalid for email with invalid domain', async () => {
await loginPage.emailField.type('mail@mail');
await loginPage.btnSubmit.click();
await expect(loginPage.emailInvalidText).toBeVisible();
test('expect trigger a validation if a invalid email is provided (2)', async () => {
await pageAuth.inputEmail.type('mail@mail');
await pageAuth.btnSubmit.click();

await expect(pageAuth.textErrorEmail).toBeVisible();
});

test('expect user type a valid email', async () => {
await loginPage.emailField.type('mail@mail.com');
await loginPage.btnSubmit.click();
await expect(global.getToastBarSuccess).toBeVisible();
test('expect to show a success toast if a valid email is provided', async () => {
await pageAuth.inputEmail.type('mail@mail.com');
await pageAuth.btnSubmit.click();

await expect(pageAuth.toastSuccess).toBeVisible();
});
});
58 changes: 34 additions & 24 deletions apps/meteor/tests/e2e/02-register.spec.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,48 @@
import { test, expect } from './utils/test';
import { registerUser } from './utils/mocks/userAndPasswordMock';
import { LoginPage } from './pageobjects';

test.describe('[Register]', () => {
let loginPage: LoginPage;
import { Page } from '@playwright/test';
import { faker } from '@faker-js/faker';

test.beforeEach(async ({ page }) => {
loginPage = new LoginPage(page);
import { Auth } from './page-objects';

test.describe('Register', () => {
let page: Page;
let pageAuth: Auth;

test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
pageAuth = new Auth(page);
});

test.beforeEach(async () => {
await page.goto('/');
await pageAuth.btnRegister.click();
});

test('expect user click in register button without data', async () => {
await loginPage.btnRegister.click();
await loginPage.btnSubmit.click();
test('expect trigger a validation error if no data is provided', async () => {
await pageAuth.btnSubmit.click();

await expect(loginPage.nameInvalidText).toBeVisible();
await expect(loginPage.emailInvalidText).toBeVisible();
await expect(loginPage.passwordInvalidText).toBeVisible();
await expect(pageAuth.textErrorName).toBeVisible();
await expect(pageAuth.textErrorEmail).toBeVisible();
await expect(pageAuth.textErrorPassword).toBeVisible();
});

test('expect user click in register button with different password', async () => {
await loginPage.btnRegister.click();
await loginPage.passwordField.type(registerUser.password);
await loginPage.emailField.type(registerUser.email);
await loginPage.nameField.type(registerUser.name);
await loginPage.confirmPasswordField.type('wrong_password');
test('expect trigger a validation error if different password is provided', async () => {
await pageAuth.inputName.type(faker.name.firstName());
await pageAuth.inputEmail.type(faker.internet.email());
await pageAuth.inputPassword.type('any_password');
await pageAuth.inputPasswordConfirm.type('any_password_2');
await pageAuth.btnSubmit.click();

await loginPage.btnSubmit.click();
await expect(loginPage.confirmPasswordInvalidText).toBeVisible();
await expect(loginPage.confirmPasswordInvalidText).toHaveText('The password confirmation does not match password');
await expect(pageAuth.textErrorPasswordConfirm).toBeVisible();
});

test('expect new user is created', async () => {
await loginPage.btnRegister.click();
await loginPage.registerNewUser(registerUser);
test('expect successfully register a new user', async () => {
await pageAuth.inputName.type(faker.name.firstName());
await pageAuth.inputEmail.type(faker.internet.email());
await pageAuth.inputPassword.type('any_password');
await pageAuth.inputPasswordConfirm.type('any_password');
await pageAuth.btnSubmit.click();
await pageAuth.btnRegisterConfirmUsername.click();
});
});
Loading

0 comments on commit c6663cb

Please sign in to comment.