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 authored Jul 19, 2022
1 parent 55b2617 commit 7933477
Show file tree
Hide file tree
Showing 48 changed files with 1,817 additions and 2,722 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ jobs:
done
cd ./apps/meteor
npm run test:playwright
npm run test:e2e
- name: Store playwright test trace
uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -683,7 +683,7 @@ jobs:
docker logs presence --tail=50
cd ./apps/meteor
IS_EE=true npm run test:playwright
IS_EE=true npm run test:e2e
- name: Store playwright test trace
uses: actions/upload-artifact@v2
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"typecheck": "cross-env NODE_OPTIONS=\"--max-old-space-size=6144\" tsc -p tsconfig.typecheck.json",
"deploy": "npm run build && pm2 startOrRestart pm2.json",
"coverage": "nyc -r html mocha --config ./.mocharc.js",
"test:playwright": "playwright test",
"test:e2e": "playwright test",
"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
201 changes: 185 additions & 16 deletions apps/meteor/tests/e2e/00-wizard.spec.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,195 @@
import { test, expect, Page } from '@playwright/test';
import { test, expect, Page, Locator } from '@playwright/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 @@ -28,14 +198,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 @@ -64,8 +233,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 @@ -77,7 +245,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: 29 additions & 24 deletions apps/meteor/tests/e2e/01-forgot-password.spec.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
import { test, expect } from '@playwright/test';
import { Page, test, expect } from '@playwright/test';

import { Global, LoginPage } from './pageobjects';
import { Auth } from './page-objects';

test.describe('[Forgot Password]', () => {
let loginPage: LoginPage;
let global: Global;
test.describe('Forgot Password', () => {
let page: Page;
let pageAuth: Auth;

test.beforeEach(async ({ page }) => {
loginPage = new LoginPage(page);
global = new Global(page);
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();
});
});
Loading

0 comments on commit 7933477

Please sign in to comment.