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 with Playwright (task: All works) #25122

Merged
merged 18 commits into from
Apr 11, 2022
Merged
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
58 changes: 54 additions & 4 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ jobs:
- name: Unit Test
run: yarn testunit

- name: Install Playwright
run: npx playwright install --with-deps

- name: E2E Test API
env:
TEST_MODE: "true"
Expand All @@ -246,7 +249,7 @@ jobs:
Xvfb -screen 0 1024x768x24 :99 &
for i in $(seq 1 5); do (docker exec mongo mongo rocketchat --eval 'db.dropDatabase()') && npm run testci -- --test=testapi && s=0 && break || s=$? && sleep 1; done; (exit $s)

- name: E2E Test UI
- name: E2E Test UI (Legacy - Cypress)
env:
TEST_MODE: "true"
MONGO_URL: mongodb://localhost:27017/rocketchat
Expand All @@ -257,6 +260,24 @@ jobs:
Xvfb -screen 0 1024x768x24 :99 &
for i in $(seq 1 2); do (docker exec mongo mongo rocketchat --eval 'db.dropDatabase()') && npm run testci -- --test=testui && s=0 && break || s=$? && ([ ! -w tests/cypress/screenshots ] || mv tests/cypress/screenshots tests/cypress/screenshots-$i) && ([ ! -w tests/cypress/videos ] || mv tests/cypress/videos tests/cypress/videos-$i) && sleep 1; done; (exit $s)

- name: E2E Test UI
env:
TEST_MODE: 'true'
MONGO_URL: mongodb://localhost:27017/rocketchat
MONGO_OPLOG_URL: mongodb://localhost:27017/local
run: |
cd ./apps/meteor
echo -e 'pcm.!default {\n type hw\n card 0\n}\n\nctl.!default {\n type hw\n card 0\n}' > ~/.asoundrc
Xvfb -screen 0 1024x768x24 :99 &
docker exec mongo mongo rocketchat --eval 'db.dropDatabase()' && npm run testci -- --test=test:playwright

- name: Store playwright test trace
uses: actions/upload-artifact@v2
if: failure()
with:
name: playwright-test-trace
path: ./apps/meteor/tests/e2e/test-failures*

- name: Store cypress test screenshots
uses: actions/upload-artifact@v2
if: failure()
Expand Down Expand Up @@ -361,7 +382,7 @@ jobs:

for i in $(seq 1 5); do (docker exec mongo mongo rocketchat --eval 'db.dropDatabase()') && npm run testci -- --enterprise --test=testapi && s=0 && break || s=$? && sleep 1; done; (exit $s)

- name: E2E Test UI
- name: E2E Test UI (Legacy - Cypress)
env:
TEST_MODE: "true"
MONGO_URL: mongodb://localhost:27017/rocketchat
Expand All @@ -380,19 +401,48 @@ jobs:

for i in $(seq 1 2); do (docker exec mongo mongo rocketchat --eval 'db.dropDatabase()') && npm run testci -- --enterprise --test=testui && s=0 && break || s=$? && ([ ! -w tests/cypress/screenshots ] || mv tests/cypress/screenshots tests/cypress/screenshots-$i) && ([ ! -w tests/cypress/videos ] || mv tests/cypress/videos tests/cypress/videos-$i) && sleep 1; done; (exit $s)

- name: Install Playwright
run: npx playwright install --with-deps

- name: E2E Test UI
env:
TEST_MODE: 'true'
MONGO_URL: mongodb://localhost:27017/rocketchat
MONGO_OPLOG_URL: mongodb://localhost:27017/local
ENTERPRISE_LICENSE: ${{ secrets.ENTERPRISE_LICENSE }}
TRANSPORTER: nats://localhost:4222
CYPRESS_BASE_URL: http://localhost:4000
CYPRESS_TEST_API_URL: http://localhost:4000
OVERWRITE_SETTING_Site_Url: http://localhost:4000
SKIP_PROCESS_EVENT_REGISTRATION: "true"
run: |
echo -e 'pcm.!default {\n type hw\n card 0\n}\n\nctl.!default {\n type hw\n card 0\n}' > ~/.asoundrc
Xvfb -screen 0 1024x768x24 :99 &

cd ./apps/meteor

docker exec mongo mongo rocketchat --eval 'db.dropDatabase()' && npm run testci -- --enterprise --test=test:playwright:ee

- name: Store playwright test trace
uses: actions/upload-artifact@v2
if: failure()
with:
name: ee-playwright-test-trace
path: ./apps/meteor/tests/e2e/test-failures*

- name: Store cypress test screenshots
uses: actions/upload-artifact@v2
if: failure()
with:
name: ee-cypress-test-screenshots
path: apps/meteor/tests/cypress/screenshots*
path: ./apps/meteor/tests/cypress/screenshots*

- name: Store cypress test videos
uses: actions/upload-artifact@v2
if: failure()
with:
name: ee-cypress-test-videos
path: apps/meteor/tests/cypress/videos*
path: ./apps/meteor/tests/cypress/videos*
# notification:
# runs-on: ubuntu-20.04
# needs: test
Expand Down
3 changes: 3 additions & 0 deletions apps/meteor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"deploy": "npm run build && pm2 startOrRestart pm2.json",
"coverage": "nyc -r html mocha --config ./.mocharc.js",
"testci": "node .scripts/start.js",
"test:playwright": "playwright test",
"test:playwright:ee": "ENTERPRISE=true playwright test",
"testui": "cypress run",
"testui-pass": "cypress run --spec ./tests/cypress/integration/01-pass/**/*.spec.js",
"testui-intermittent": "cypress run --spec ./tests/cypress/integration/02-intermittent/**/*.spec.js",
Expand Down Expand Up @@ -65,6 +67,7 @@
"@babel/preset-env": "^7.14.7",
"@babel/preset-react": "^7.14.5",
"@babel/register": "^7.14.5",
"@playwright/test": "1.20.2",
"@rocket.chat/eslint-config": "^0.4.0",
"@rocket.chat/livechat": "^1.12.2",
"@settlin/spacebars-loader": "^1.0.9",
Expand Down
18 changes: 18 additions & 0 deletions apps/meteor/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { PlaywrightTestConfig } from '@playwright/test';

const config: PlaywrightTestConfig = {
outputDir: 'tests/e2e/test-failures',
reporter: [['list']],
workers: 1,
use: {
baseURL: process.env.ENTERPRISE ? 'http://localhost:4000' : 'http://localhost:3000',
headless: true,
viewport: { width: 1024, height: 768 },
ignoreHTTPSErrors: true,
video: 'retain-on-failure',
screenshot: 'only-on-failure',
trace: 'retain-on-failure',
},
testDir: 'tests/e2e',
};
export default config;
82 changes: 82 additions & 0 deletions apps/meteor/tests/e2e/00-wizard.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { test, expect } from '@playwright/test';

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

test.describe('[Wizard]', () => {
let setupWizard: SetupWizard;
let loginPage: LoginPage;
test.beforeEach(async ({ page }) => {
setupWizard = new SetupWizard(page);
loginPage = new LoginPage(page);
});

test.describe('[Step 2]', async () => {
test.beforeEach(async ({ baseURL }) => {
const baseUrl = baseURL;
await setupWizard.goto(baseUrl as string);
await loginPage.login(adminLogin);
});

test('expect required field alert showed when user dont inform data', async () => {
await setupWizard.stepTwoFailedWithBlankFields();
});

test('expect go to Step 3 successfully', async () => {
await setupWizard.stepTwoSuccess();
await expect(setupWizard.getPage()).toHaveURL(setupWizardStepRegex._3);
});
});

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

test('expect have email field to register the server', async () => {
await expect(setupWizard.registeredServer()).toBeVisible();
});

test('expect start "Register" button disabled', async () => {
await expect(setupWizard.registerButton()).toBeDisabled();
});

test('expect show an error on invalid email', async () => {
await setupWizard.stepThreeFailedWithInvalidField();
});

test('expect enable "Register" button when email is valid and terms checked', async () => {
await setupWizard.registeredServer().type(VALID_EMAIL);
await setupWizard.agreementField().click();
await expect(setupWizard.registerButton()).toBeEnabled();
});

test('expect have option for standalone server', async () => {
await expect(setupWizard.standaloneServer()).toBeVisible();
});
});

test.describe('[Final Step]', async () => {
test.beforeEach(async () => {
await setupWizard.goto('');
await loginPage.login(adminLogin);
await setupWizard.stepTwoSuccess();
await setupWizard.stepThreeSuccess();
});

test('expect confirm the standalone option', async () => {
await expect(setupWizard.goToWorkspace()).toBeVisible();
await expect(setupWizard.standaloneConfirmText()).toBeVisible();
});

test('expect confirm standalone', async () => {
await setupWizard.goToWorkspace().click();
await setupWizard.waitForSelector(HOME_SELECTOR);
});
});
});
39 changes: 39 additions & 0 deletions apps/meteor/tests/e2e/01-forgot-password.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { test, expect } from '@playwright/test';

import LoginPage from './utils/pageobjects/LoginPage';
import { VALID_EMAIL, INVALID_EMAIL, INVALID_EMAIL_WITHOUT_MAIL_PROVIDER } from './utils/mocks/userAndPasswordMock';

test.describe('[Forgot Password]', () => {
let loginPage: LoginPage;

test.beforeEach(async ({ page, baseURL }) => {
loginPage = new LoginPage(page);
const baseUrl = baseURL as string;
await loginPage.goto(baseUrl);
await loginPage.gotToForgotPassword();
});

test('expect be required', async () => {
loginPage.submit();

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

test('expect invalid for email without domain', async () => {
await loginPage.emailField().type(INVALID_EMAIL_WITHOUT_MAIL_PROVIDER);
await loginPage.submit();
await expect(loginPage.emailInvalidText()).toBeVisible();
});

test('expect be invalid for email with invalid domain', async () => {
await loginPage.emailField().type(INVALID_EMAIL);
await loginPage.submit();
await expect(loginPage.emailInvalidText()).toBeVisible();
});

test('expect user type a valid email', async () => {
await loginPage.emailField().type(VALID_EMAIL);
await loginPage.submit();
await expect(loginPage.getToastMessageSuccess()).toBeVisible();
});
});
27 changes: 27 additions & 0 deletions apps/meteor/tests/e2e/02-register.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { test } from '@playwright/test';

import { registerUser, WRONG_PASSWORD } from './utils/mocks/userAndPasswordMock';
import LoginPage from './utils/pageobjects/LoginPage';

test.describe('[Register]', () => {
let loginPage: LoginPage;

test.beforeEach(async ({ page, baseURL }) => {
const URL = baseURL as string;
loginPage = new LoginPage(page);
await loginPage.goto(URL);
});

test('expect user click in register button without data', async () => {
await loginPage.registerFail();
});

test('expect user click in register button with different password', async () => {
await loginPage.registerFailWithDifferentPassword(registerUser, WRONG_PASSWORD);
});

test('expect new user is created', async () => {
await loginPage.gotToRegister();
await loginPage.registerNewUser(registerUser);
});
});
29 changes: 29 additions & 0 deletions apps/meteor/tests/e2e/03-login.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { test, expect } from '@playwright/test';

import { validUser } from './utils/mocks/userAndPasswordMock';
import LoginPage from './utils/pageobjects/LoginPage';
import { HOME_SELECTOR } from './utils/mocks/waitSelectorsMock';

test.describe('[Login]', () => {
let loginPage: LoginPage;

test.beforeEach(async ({ page, baseURL }) => {
const baseUrl = baseURL;
loginPage = new LoginPage(page);
await loginPage.goto(baseUrl as string);
});

test('expect user write a password incorrectly', async () => {
const invalidUserPassword = {
email: validUser.email,
password: 'any_password1',
};
await loginPage.login(invalidUserPassword);
await expect(loginPage.getToastError()).toBeVisible();
});

test('expect user make login', async () => {
await loginPage.login(validUser);
await loginPage.waitForSelector(HOME_SELECTOR);
});
});
Loading