Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Tests refactor pageobjects #26245

Merged
merged 28 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f2b1741
chore: update e2e script name
Jul 13, 2022
2238168
refactor: remove useless constants
Jul 13, 2022
6d3c066
feat: add ADMIN_CREDENTIALS constant
Jul 13, 2022
906be14
feat: create better structured page-objects
Jul 13, 2022
a2b434e
test: update omnichannel-departaments suite to use new page-objects
Jul 13, 2022
e171019
test: update omnichannel-agents suite to use new page-objects
Jul 13, 2022
898c324
test: update forgot-password suite to use new page-objects
Jul 13, 2022
042e19c
test: update register suite to use new page-objects
Jul 13, 2022
f792470
test: update login suite to use new page-objects
Jul 13, 2022
a9405dc
test: update channel-creation suite to use new page-objects
Jul 13, 2022
f2e79c5
test: update user-preferences suite to use new page-objects
Jul 13, 2022
9bb8e7b
test: update message-popup suite to use new page-objects
Jul 13, 2022
cfd5d8b
test: update discussion suite to use new page-objects
Jul 13, 2022
8080885
chore: remove render tests
Jul 13, 2022
0b8f0c7
fix: general fixes
Jul 14, 2022
905ac4e
feat: move locators/actions to the new structure
Jul 15, 2022
7a1e7ec
refactor: update tests to use the new page-objects
Jul 15, 2022
bbca078
refactor: delete old pageobjects
Jul 15, 2022
bd17573
Merge branch 'develop' into refactor/test-pageobjects
Jul 15, 2022
882ed4d
fix: apply eslint:fix
Jul 15, 2022
b208014
ci: update e2e test script name
Jul 15, 2022
5292300
refactor: remove some mocks and unused code~
Jul 18, 2022
db35c95
refactor: remove some mocks and unused code~
Jul 18, 2022
993fdb0
fix: adjust configurations
weslley543 Jul 18, 2022
8b5a3eb
refactor: adjusting and creating a flag for normal login
weslley543 Jul 18, 2022
31ef048
refactor: fix .only from function
weslley543 Jul 18, 2022
a174a4e
refactor: adjust functon doLogin
weslley543 Jul 18, 2022
980369a
Merge branch 'develop' into refactor/test-pageobjects
weslley543 Jul 19, 2022
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
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"]');
souzaramon marked this conversation as resolved.
Show resolved Hide resolved
});
});
});
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('/');
souzaramon marked this conversation as resolved.
Show resolved Hide resolved
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