add playwright and run e2e tests on production like environment
This commit is contained in:
parent
8dc31c9e06
commit
b1c7e01008
132
.github/workflows/end_to_end_tests.yml
vendored
132
.github/workflows/end_to_end_tests.yml
vendored
@ -1,6 +1,4 @@
|
||||
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
|
||||
|
||||
name: "End to end tests"
|
||||
name: 'End to end tests'
|
||||
|
||||
on:
|
||||
push:
|
||||
@ -10,117 +8,29 @@ on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
|
||||
start-runner:
|
||||
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false)
|
||||
name: Start self-hosted EC2 runner
|
||||
test:
|
||||
timeout-minutes: 60
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
label: ${{ steps.start-ec2-runner.outputs.label }}
|
||||
ec2-instance-id: ${{ steps.start-ec2-runner.outputs.ec2-instance-id }}
|
||||
steps:
|
||||
- name: Configure AWS credentials
|
||||
uses: aws-actions/configure-aws-credentials@v1
|
||||
with:
|
||||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
aws-region: ${{ secrets.AWS_REGION }}
|
||||
- name: Start EC2 runner
|
||||
id: start-ec2-runner
|
||||
uses: machulav/ec2-github-runner@v2
|
||||
with:
|
||||
mode: start
|
||||
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
|
||||
ec2-image-id: ami-094dbcc53250a2480
|
||||
ec2-instance-type: m5.2xlarge
|
||||
subnet-id: subnet-0ac40025f559df1bc
|
||||
security-group-id: sg-0e36e96e3b8ed2d64
|
||||
#iam-role-name: my-role-name # optional, requires additional permissions
|
||||
#aws-resource-tags: > # optional, requires additional permissions
|
||||
# [
|
||||
# {"Key": "Name", "Value": "ec2-github-runner"},
|
||||
# {"Key": "GitHubRepository", "Value": "${{ github.repository }}"}
|
||||
# ]
|
||||
|
||||
|
||||
end-to-end-tests:
|
||||
name: "End-to-end testcafe tests"
|
||||
|
||||
needs: start-runner # required to start the main job when the runner is ready
|
||||
runs-on: ${{ needs.start-runner.outputs.label }} # run the job on the newly created runner
|
||||
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: "actions/checkout@v2.0.0"
|
||||
|
||||
- name: "Setup NodeJS"
|
||||
uses: actions/setup-node@v1
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '14.x'
|
||||
|
||||
- name: "Install dependencies"
|
||||
run: npm install
|
||||
working-directory: "tests"
|
||||
|
||||
- name: "Setup .env file"
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
working-directory: tests
|
||||
- name: Install Playwright
|
||||
run: npx playwright install --with-deps
|
||||
- name: 'Setup .env file'
|
||||
run: cp .env.template .env
|
||||
|
||||
- name: "Edit ownership of file for test cases"
|
||||
run: sudo chown 1000:1000 -R .
|
||||
|
||||
- name: "Start environment"
|
||||
run: LIVE_RELOAD=0 docker-compose up -d
|
||||
|
||||
- name: "Wait for environment to build (and downloading testcafe image)"
|
||||
run: (docker-compose -f docker-compose.testcafe.yml build &) && docker-compose logs -f --tail=0 front | grep -q "Compiled successfully"
|
||||
|
||||
# - name: "temp debug: display logs"
|
||||
# run: docker-compose logs
|
||||
#
|
||||
# - name: "Wait for back start"
|
||||
# run: docker-compose logs -f back | grep -q "WorkAdventure HTTP API starting on port"
|
||||
#
|
||||
# - name: "Wait for pusher start"
|
||||
# run: docker-compose logs -f pusher | grep -q "WorkAdventure starting on port"
|
||||
|
||||
- name: "Run tests"
|
||||
run: PROJECT_DIR=$(pwd) docker-compose -f docker-compose.testcafe.yml up --exit-code-from testcafe
|
||||
|
||||
- name: Upload failed tests
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@v2
|
||||
- name: Start WorkAdventure
|
||||
run: docker-compose -f docker-compose.yaml -f docker-compose.e2e.yml up -d --build
|
||||
- name: Run Playwright tests
|
||||
run: npm run test-prod-like
|
||||
working-directory: tests
|
||||
- uses: actions/upload-artifact@v2
|
||||
if: always()
|
||||
with:
|
||||
name: my-artifact
|
||||
path: './tests/screenshots/'
|
||||
|
||||
- name: Display state
|
||||
if: ${{ failure() }}
|
||||
run: docker-compose ps
|
||||
|
||||
- name: Display logs
|
||||
if: ${{ failure() }}
|
||||
run: docker-compose logs
|
||||
|
||||
stop-runner:
|
||||
name: Stop self-hosted EC2 runner
|
||||
needs:
|
||||
- start-runner # required to get output from the start-runner job
|
||||
- end-to-end-tests # required to wait when the main job is done
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ always() }} # required to stop the runner even if the error happened in the previous jobs
|
||||
steps:
|
||||
- name: Configure AWS credentials
|
||||
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false)
|
||||
uses: aws-actions/configure-aws-credentials@v1
|
||||
with:
|
||||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
aws-region: ${{ secrets.AWS_REGION }}
|
||||
- name: Stop EC2 runner
|
||||
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false)
|
||||
uses: machulav/ec2-github-runner@v2
|
||||
with:
|
||||
mode: stop
|
||||
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
|
||||
label: ${{ needs.start-runner.outputs.label }}
|
||||
ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }}
|
||||
name: playwright-report
|
||||
path: playwright-report/
|
||||
retention-days: 30
|
||||
|
47
docker-compose.e2e.yml
Normal file
47
docker-compose.e2e.yml
Normal file
@ -0,0 +1,47 @@
|
||||
version: '3.5'
|
||||
services:
|
||||
# overrides for e2e tests to be closer to production
|
||||
# use with command:
|
||||
# docker-compose -f docker-compose.yaml -f docker-compose.e2e.yml up -d --build
|
||||
|
||||
front:
|
||||
image: 'wa-front-e2e'
|
||||
build:
|
||||
context: ./
|
||||
dockerfile: front/Dockerfile
|
||||
environment:
|
||||
STARTUP_COMMAND_1: 'envsubst < dist/env-config.template.js > dist/env-config.js'
|
||||
STARTUP_COMMAND_2: ''
|
||||
command: apache2-foreground
|
||||
volumes: []
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.front.rule=Host(`play.workadventure.localhost`)"
|
||||
- "traefik.http.routers.front.entryPoints=web"
|
||||
- "traefik.http.services.front.loadbalancer.server.port=80"
|
||||
- "traefik.http.routers.front-ssl.rule=Host(`play.workadventure.localhost`)"
|
||||
- "traefik.http.routers.front-ssl.entryPoints=websecure"
|
||||
- "traefik.http.routers.front-ssl.tls=true"
|
||||
- "traefik.http.routers.front-ssl.service=front"
|
||||
|
||||
pusher:
|
||||
image: 'wa-pusher-e2e'
|
||||
build:
|
||||
context: ./
|
||||
dockerfile: pusher/Dockerfile
|
||||
environment:
|
||||
STARTUP_COMMAND_1: ''
|
||||
STARTUP_COMMAND_2: ''
|
||||
command: yarn run runprod
|
||||
volumes: []
|
||||
|
||||
back:
|
||||
image: 'wa-back-e2e'
|
||||
build:
|
||||
context: ./
|
||||
dockerfile: back/Dockerfile
|
||||
environment:
|
||||
STARTUP_COMMAND_1: ''
|
||||
STARTUP_COMMAND_2: ''
|
||||
command: yarn run runprod
|
||||
volumes: []
|
@ -1,19 +0,0 @@
|
||||
version: "3.5"
|
||||
services:
|
||||
testcafe:
|
||||
build: tests/
|
||||
working_dir: /project/tests
|
||||
command:
|
||||
- --dev
|
||||
# Run as root to have the right to access /var/run/docker.sock
|
||||
user: root
|
||||
environment:
|
||||
BROWSER: "chromium --use-fake-device-for-media-stream"
|
||||
PROJECT_DIR: ${PROJECT_DIR}
|
||||
ADMIN_API_TOKEN: ${ADMIN_API_TOKEN}
|
||||
volumes:
|
||||
- ./:/project
|
||||
- ./maps:/maps
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
# security_opt:
|
||||
# - seccomp:unconfined
|
2
tests/.gitignore
vendored
2
tests/.gitignore
vendored
@ -1 +1,3 @@
|
||||
/node_modules
|
||||
test-results/
|
||||
playwright-report/
|
||||
|
@ -1,30 +0,0 @@
|
||||
const BROWSER = process.env.BROWSER || "chrome --use-fake-ui-for-media-stream --use-fake-device-for-media-stream";
|
||||
|
||||
module.exports = {
|
||||
"browsers": BROWSER,
|
||||
"hostname": "localhost",
|
||||
"src": "tests/",
|
||||
"screenshots": {
|
||||
"path": "screenshots/",
|
||||
"takeOnFails": true,
|
||||
"thumbnails": false,
|
||||
},
|
||||
"assertionTimeout": 20000,
|
||||
"selectorTimeout": 60000,
|
||||
|
||||
|
||||
"videoPath": "screenshots/videos",
|
||||
"videoOptions": {
|
||||
"failedOnly": true,
|
||||
}
|
||||
/*"skipJsErrors": true,
|
||||
"clientScripts": [ { "content": `
|
||||
window.addEventListener('error', function (e) {
|
||||
if (e instanceof Error && e.message.includes('_jp')) {
|
||||
console.log('Ignoring sockjs related error');
|
||||
return;
|
||||
}
|
||||
throw e;
|
||||
});
|
||||
` } ]*/
|
||||
}
|
8332
tests/package-lock.json
generated
8332
tests/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,14 +1,12 @@
|
||||
{
|
||||
"devDependencies": {
|
||||
"dockerode": "^3.3.1",
|
||||
"testcafe": "^1.18.0"
|
||||
"@playwright/test": "^1.19.1",
|
||||
"@types/dockerode": "^3.3.0",
|
||||
"axios": "^0.24.0",
|
||||
"dockerode": "^3.3.1"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "testcafe"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ffmpeg-installer/ffmpeg": "^1.1.0",
|
||||
"@types/dockerode": "^3.3.0",
|
||||
"axios": "^0.24.0"
|
||||
"test": "ADMIN_API_TOKEN=123 playwright test",
|
||||
"test-prod-like": "OVERRIDE_DOCKER_COMPOSE=docker-compose.e2e.yml npm run test"
|
||||
}
|
||||
}
|
||||
|
105
tests/playwright.config.ts
Normal file
105
tests/playwright.config.ts
Normal file
@ -0,0 +1,105 @@
|
||||
import type { PlaywrightTestConfig } from '@playwright/test';
|
||||
import { devices } from '@playwright/test';
|
||||
|
||||
/**
|
||||
* Read environment variables from file.
|
||||
* https://github.com/motdotla/dotenv
|
||||
*/
|
||||
// require('dotenv').config();
|
||||
|
||||
/**
|
||||
* See https://playwright.dev/docs/test-configuration.
|
||||
*/
|
||||
const config: PlaywrightTestConfig = {
|
||||
testDir: './tests',
|
||||
/* Maximum time one test can run for. */
|
||||
timeout: 30 * 1000,
|
||||
expect: {
|
||||
/**
|
||||
* Maximum time expect() should wait for the condition to be met.
|
||||
* For example in `await expect(locator).toHaveText();`
|
||||
*/
|
||||
timeout: 5000
|
||||
},
|
||||
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
||||
forbidOnly: !!process.env.CI,
|
||||
/* Retry on CI only */
|
||||
retries: process.env.CI ? 2 : 0,
|
||||
/* Opt out of parallel tests. */
|
||||
workers: 1,
|
||||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
||||
reporter: 'html',
|
||||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
||||
use: {
|
||||
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
|
||||
actionTimeout: 0,
|
||||
/* Base URL to use in actions like `await page.goto('/')`. */
|
||||
// baseURL: 'http://localhost:3000',
|
||||
|
||||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
||||
trace: 'on-first-retry',
|
||||
},
|
||||
|
||||
/* Configure projects for major browsers */
|
||||
projects: [
|
||||
{
|
||||
name: 'chromium',
|
||||
use: {
|
||||
...devices['Desktop Chrome'],
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: 'firefox',
|
||||
use: {
|
||||
...devices['Desktop Firefox'],
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: 'webkit',
|
||||
use: {
|
||||
...devices['Desktop Safari'],
|
||||
},
|
||||
},
|
||||
|
||||
/* Test against mobile viewports. */
|
||||
// {
|
||||
// name: 'Mobile Chrome',
|
||||
// use: {
|
||||
// ...devices['Pixel 5'],
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// name: 'Mobile Safari',
|
||||
// use: {
|
||||
// ...devices['iPhone 12'],
|
||||
// },
|
||||
// },
|
||||
|
||||
/* Test against branded browsers. */
|
||||
// {
|
||||
// name: 'Microsoft Edge',
|
||||
// use: {
|
||||
// channel: 'msedge',
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// name: 'Google Chrome',
|
||||
// use: {
|
||||
// channel: 'chrome',
|
||||
// },
|
||||
// },
|
||||
],
|
||||
|
||||
/* Folder for test artifacts such as screenshots, videos, traces, etc. */
|
||||
// outputDir: 'test-results/',
|
||||
|
||||
/* Run your local dev server before starting the tests */
|
||||
// webServer: {
|
||||
// command: 'npm run start',
|
||||
// port: 3000,
|
||||
// },
|
||||
};
|
||||
|
||||
export default config;
|
1
tests/screenshots/.gitignore
vendored
1
tests/screenshots/.gitignore
vendored
@ -1 +0,0 @@
|
||||
*
|
15
tests/tests/modules.spec.ts
Normal file
15
tests/tests/modules.spec.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
import { assertLogMessage } from './utils/log';
|
||||
import { login } from './utils/roles';
|
||||
|
||||
test.describe('Module', () => {
|
||||
test('loading should work out of the box', async ({ page }) => {
|
||||
await page.goto(
|
||||
'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Modules/with_modules.json'
|
||||
);
|
||||
|
||||
await login(page, 'Alice', 2);
|
||||
|
||||
await assertLogMessage(page, 'Successfully loaded module: foo = bar');
|
||||
});
|
||||
});
|
@ -1,44 +0,0 @@
|
||||
import {assertLogMessage} from "./utils/log";
|
||||
|
||||
const fs = require('fs');
|
||||
const Docker = require('dockerode');
|
||||
import { Selector } from 'testcafe';
|
||||
import {login} from "./utils/roles";
|
||||
import {
|
||||
findContainer,
|
||||
rebootBack,
|
||||
rebootPusher,
|
||||
resetRedis,
|
||||
rebootTraefik,
|
||||
startContainer,
|
||||
stopContainer, stopRedis, startRedis
|
||||
} from "./utils/containers";
|
||||
import {getBackDump, getPusherDump} from "./utils/debug";
|
||||
|
||||
fixture `Modules`
|
||||
.page `http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Modules/with_modules.json`;
|
||||
|
||||
test("Test that module loading works out of the box", async (t: TestController) => {
|
||||
|
||||
await login(t, 'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Modules/with_modules.json');
|
||||
|
||||
|
||||
await assertLogMessage(t, 'Successfully loaded module: foo = bar');
|
||||
|
||||
t.ctx.passed = true;
|
||||
}).after(async t => {
|
||||
if (!t.ctx.passed) {
|
||||
console.log("Test 'Test that module loading works out of the box' failed. Browser logs:")
|
||||
try {
|
||||
console.log(await t.getBrowserConsoleMessages());
|
||||
} catch (e) {
|
||||
console.error('Error while fetching browser logs (maybe linked to a closed iframe?)', e);
|
||||
try {
|
||||
console.log('Logs from main window:');
|
||||
console.log(await t.switchToMainWindow().getBrowserConsoleMessages());
|
||||
} catch (e) {
|
||||
console.error('Unable to retrieve logs', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
26
tests/tests/reconnect.spec.ts
Normal file
26
tests/tests/reconnect.spec.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
import { findContainer, startContainer, stopContainer } from './utils/containers';
|
||||
import { login } from './utils/roles';
|
||||
|
||||
test.setTimeout(60000);
|
||||
test.describe('Connection', () => {
|
||||
test('can succeed even if WorkAdventure starts while pusher is down', async ({ page }) => {
|
||||
await page.goto(
|
||||
'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/mousewheel.json'
|
||||
);
|
||||
|
||||
// Let's stop the pusher
|
||||
const container = await findContainer('pusher');
|
||||
await stopContainer(container);
|
||||
|
||||
await page.goto(
|
||||
'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/mousewheel.json'
|
||||
);
|
||||
await expect(page.locator('.error-div')).toContainText('Unable to connect to WorkAdventure');
|
||||
|
||||
await startContainer(container);
|
||||
|
||||
await page.waitForResponse(response => response.status() === 200, { timeout: 60000 }),
|
||||
await login(page);
|
||||
});
|
||||
});
|
@ -1,63 +0,0 @@
|
||||
import {assertLogMessage} from "./utils/log";
|
||||
|
||||
const fs = require('fs');
|
||||
const Docker = require('dockerode');
|
||||
import { Selector } from 'testcafe';
|
||||
import {login, resetLanguage} from "./utils/roles";
|
||||
import {findContainer, rebootBack, rebootPusher, resetRedis, startContainer, stopContainer} from "./utils/containers";
|
||||
|
||||
fixture `Reconnection`
|
||||
.page `http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/mousewheel.json`;
|
||||
|
||||
test("Test that connection can succeed even if WorkAdventure starts while pusher is down", async (t: TestController) => {
|
||||
// Let's stop the pusher
|
||||
const container = await findContainer('pusher');
|
||||
await stopContainer(container);
|
||||
|
||||
const errorMessage = Selector('.error-div');
|
||||
|
||||
await resetLanguage('en-US');
|
||||
|
||||
await t
|
||||
.navigateTo('http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/mousewheel.json')
|
||||
.expect(errorMessage.innerText).contains('Unable to connect to WorkAdventure')
|
||||
|
||||
await startContainer(container);
|
||||
|
||||
await login(t, 'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/mousewheel.json');
|
||||
|
||||
t.ctx.passed = true;
|
||||
}).after(async t => {
|
||||
if (!t.ctx.passed) {
|
||||
console.log("Test failed. Browser logs:")
|
||||
console.log(await t.getBrowserConsoleMessages());
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
test("Test that variables cache in the back don't prevent setting a variable in case the map changes", async (t: TestController) => {
|
||||
// Let's start by visiting a map that DOES not have the variable.
|
||||
fs.copyFileSync('../maps/tests/Variables/Cache/variables_cache_1.json', '../maps/tests/Variables/Cache/variables_tmp.json');
|
||||
|
||||
await t.useRole(userAlice);
|
||||
//.takeScreenshot('before_switch.png');
|
||||
|
||||
// Let's REPLACE the map by a map that has a new variable
|
||||
// At this point, the back server contains a cache of the old map (with no variables)
|
||||
fs.copyFileSync('../maps/tests/Variables/Cache/variables_cache_2.json', '../maps/tests/Variables/Cache/variables_tmp.json');
|
||||
await t.openWindow('http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/Cache/variables_tmp.json')
|
||||
.resizeWindow(960, 800)
|
||||
.useRole(userAlice);
|
||||
//.takeScreenshot('after_switch.png');
|
||||
|
||||
// Let's check we successfully manage to save the variable value.
|
||||
await assertLogMessage(t, 'SUCCESS!');
|
||||
|
||||
t.ctx.passed = true;
|
||||
}).after(async t => {
|
||||
if (!t.ctx.passed) {
|
||||
console.log("Test failed. Browser logs:")
|
||||
console.log(await t.getBrowserConsoleMessages());
|
||||
}
|
||||
});
|
||||
*/
|
22
tests/tests/translate.spec.ts
Normal file
22
tests/tests/translate.spec.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
import { login } from './utils/roles';
|
||||
|
||||
test.describe('Translation', () => {
|
||||
test('can be switched to French', async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto(
|
||||
'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/mousewheel.json'
|
||||
);
|
||||
|
||||
await login(page);
|
||||
|
||||
await page.click('.menuIcon img:first-child');
|
||||
await page.click('button:has-text("Settings")');
|
||||
await page.selectOption('.languages-switcher', 'fr-FR');
|
||||
await page.click('button:has-text("Save")');
|
||||
|
||||
await page.click('.menuIcon img:first-child');
|
||||
await expect(page.locator('.menu-submenu-container h2')).toHaveText('Paramètres');
|
||||
});
|
||||
});
|
@ -1,34 +0,0 @@
|
||||
import { Selector } from "testcafe";
|
||||
import { login } from "./utils/roles";
|
||||
|
||||
fixture`Translation`
|
||||
.page`http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/mousewheel.json`;
|
||||
|
||||
test("Test that I can switch to French", async (t: TestController) => {
|
||||
const languageSelect = Selector(".languages-switcher");
|
||||
const languageOption = languageSelect.find("option");
|
||||
|
||||
await login(
|
||||
t,
|
||||
"http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/mousewheel.json"
|
||||
);
|
||||
|
||||
await t
|
||||
.click(".menuIcon img:first-child")
|
||||
.click(Selector("button").withText("Settings"))
|
||||
.click(".languages-switcher")
|
||||
.click(languageOption.withText("Français (France)"))
|
||||
.click(Selector("button").withText("Save"))
|
||||
.wait(5000)
|
||||
|
||||
.click(".menuIcon img:first-child")
|
||||
.expect(Selector("button").withText("Paramètres").innerText)
|
||||
.contains("Paramètres");
|
||||
|
||||
t.ctx.passed = true;
|
||||
}).after(async (t) => {
|
||||
if (!t.ctx.passed) {
|
||||
console.log("Test failed. Browser logs:");
|
||||
console.log(await t.getBrowserConsoleMessages());
|
||||
}
|
||||
});
|
@ -1,6 +1,6 @@
|
||||
//import Docker from "dockerode";
|
||||
//import * as Dockerode from "dockerode";
|
||||
import Dockerode = require( 'dockerode')
|
||||
import Dockerode from 'dockerode';
|
||||
const util = require('util');
|
||||
const exec = util.promisify(require('child_process').exec);
|
||||
const { execSync } = require('child_process');
|
||||
@ -13,6 +13,7 @@ const fs = require('fs');
|
||||
export function dockerCompose(command: string): void {
|
||||
let param = '';
|
||||
const projectDir = process.env.PROJECT_DIR;
|
||||
const overrideDockerCompose = process.env.OVERRIDE_DOCKER_COMPOSE;
|
||||
|
||||
if (!projectDir && fs.existsSync('/project')) {
|
||||
// We are probably in the docker-image AND we did not pass PROJECT_DIR env variable
|
||||
@ -23,6 +24,10 @@ export function dockerCompose(command: string): void {
|
||||
const dirName = path.basename(projectDir);
|
||||
param = '--project-name '+dirName+' --project-directory '+projectDir;
|
||||
}
|
||||
|
||||
if (overrideDockerCompose) {
|
||||
param += ' -f docker-compose.yaml -f '+overrideDockerCompose;
|
||||
}
|
||||
|
||||
let stdout = execSync('docker-compose '+param+' '+command, {
|
||||
cwd: __dirname + '/../../../'
|
||||
|
@ -1,20 +1,21 @@
|
||||
import { Selector } from 'testcafe';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
/**
|
||||
* Tries to find a given log message in the logs (for 10 seconds)
|
||||
*/
|
||||
export async function assertLogMessage(t: TestController, message: string): Promise<void> {
|
||||
let i = 0;
|
||||
let logs: string[]|undefined;
|
||||
do {
|
||||
const messages = await t.getBrowserConsoleMessages();
|
||||
logs = messages['log'];
|
||||
if (logs.find((str) => str === message)) {
|
||||
break;
|
||||
}
|
||||
await t.wait(1000);
|
||||
i++;
|
||||
} while (i < 30);
|
||||
export async function assertLogMessage(page, substring): Promise<void> {
|
||||
let logs = [];
|
||||
await page.on('console', async (msg) => {
|
||||
logs.push(await msg.text());
|
||||
});
|
||||
|
||||
await t.expect(logs).contains(message);
|
||||
// wait for log to appear
|
||||
for (let i = 0; i < 10; i++) {
|
||||
if (logs.includes(substring)) {
|
||||
break;
|
||||
}
|
||||
await page.waitForTimeout(50);
|
||||
}
|
||||
|
||||
expect(logs).toContain(substring);
|
||||
}
|
||||
|
@ -1,20 +1,18 @@
|
||||
import { Role, ClientFunction } from 'testcafe';
|
||||
export async function login(
|
||||
page,
|
||||
userName: string = 'Alice',
|
||||
characterNumber: number = 2,
|
||||
browserLanguage: string | null = 'en-US'
|
||||
) {
|
||||
// window.localStorage.setItem('language', browserLanguage)
|
||||
|
||||
export const resetLanguage = ClientFunction((browserLanguage) => window.localStorage.setItem('language', browserLanguage));
|
||||
await page.fill('input[name="loginSceneName"]', userName);
|
||||
await page.click('button.loginSceneFormSubmit');
|
||||
|
||||
export async function login(t: TestController, url: string, userName: string = "Alice", characterNumber: number = 2, browserLanguage: string|null = 'en-US') {
|
||||
for (let i = 0; i < characterNumber; i++) {
|
||||
await page.click('button.selectCharacterButtonRight');
|
||||
}
|
||||
|
||||
await resetLanguage(browserLanguage);
|
||||
|
||||
t = t
|
||||
.navigateTo(url)
|
||||
.typeText('input[name="loginSceneName"]', userName)
|
||||
.click('button.loginSceneFormSubmit');
|
||||
|
||||
for (let i = 0; i < characterNumber; i++) {
|
||||
t = t.click('button.selectCharacterButtonRight');
|
||||
}
|
||||
|
||||
return t.click('button.selectCharacterSceneFormSubmit')
|
||||
.click('button.letsgo');
|
||||
await page.click('button.selectCharacterSceneFormSubmit');
|
||||
await page.click('button.letsgo');
|
||||
}
|
||||
|
164
tests/tests/variables.spec.ts
Normal file
164
tests/tests/variables.spec.ts
Normal file
@ -0,0 +1,164 @@
|
||||
import { expect, test, chromium } from '@playwright/test';
|
||||
import fs from 'fs';
|
||||
import {
|
||||
rebootBack,
|
||||
rebootPusher,
|
||||
rebootTraefik,
|
||||
resetRedis,
|
||||
startRedis,
|
||||
stopRedis,
|
||||
} from './utils/containers';
|
||||
import { getBackDump, getPusherDump } from './utils/debug';
|
||||
import { assertLogMessage } from './utils/log';
|
||||
import { login } from './utils/roles';
|
||||
|
||||
test.setTimeout(180000);
|
||||
test.describe('Variables', () => {
|
||||
// WARNING: Since this test restarts traefik and other components, it might fail when run against the vite dev server.
|
||||
// when running with --headed you can manually reload the page to avoid this issue.
|
||||
test('storage works', async ({ page }) => {
|
||||
await resetRedis();
|
||||
|
||||
await Promise.all([rebootBack(), rebootPusher()]);
|
||||
|
||||
await page.goto(
|
||||
'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json?somerandomparam=1'
|
||||
);
|
||||
await login(page);
|
||||
|
||||
const textField = page
|
||||
.frameLocator('#cowebsite-buffer iframe')
|
||||
.locator('#textField');
|
||||
await expect(textField).toHaveValue('default value');
|
||||
await textField.fill('');
|
||||
await textField.fill('new value');
|
||||
await textField.press('Tab');
|
||||
|
||||
await page.goto(
|
||||
'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json'
|
||||
);
|
||||
await expect(textField).toHaveValue('new value');
|
||||
|
||||
// Now, let's kill the reverse proxy to cut the connexion
|
||||
console.log('Rebooting traefik');
|
||||
rebootTraefik();
|
||||
console.log('Rebooting done');
|
||||
|
||||
// Maybe we should:
|
||||
// 1: stop Traefik
|
||||
// 2: detect reconnecting screen
|
||||
// 3: start Traefik again
|
||||
|
||||
await expect(textField).toHaveValue('new value', { timeout: 60000 });
|
||||
|
||||
stopRedis();
|
||||
await textField.fill('');
|
||||
await textField.fill('value set while Redis stopped');
|
||||
await textField.press('Tab');
|
||||
|
||||
startRedis();
|
||||
await page.goto('http://maps.workadventure.localhost/tests/');
|
||||
|
||||
const backDump = await getBackDump();
|
||||
//console.log('backDump', backDump);
|
||||
for (const room of backDump) {
|
||||
if (
|
||||
room.roomUrl ===
|
||||
'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json'
|
||||
) {
|
||||
throw new Error('Room still found in back');
|
||||
}
|
||||
}
|
||||
|
||||
const pusherDump = await getPusherDump();
|
||||
//console.log('pusherDump', pusherDump);
|
||||
expect(
|
||||
pusherDump[
|
||||
'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json'
|
||||
]
|
||||
).toBe(undefined);
|
||||
|
||||
await page.goto(
|
||||
'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json'
|
||||
);
|
||||
// Redis will reconnect automatically and will store the variable on reconnect!
|
||||
// So we should see the new value.
|
||||
await expect(textField).toHaveValue('value set while Redis stopped');
|
||||
|
||||
// Now, let's try to kill / reboot the back
|
||||
await rebootBack();
|
||||
|
||||
await page.goto(
|
||||
'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json'
|
||||
);
|
||||
await expect(textField).toHaveValue('value set while Redis stopped', {
|
||||
timeout: 60000,
|
||||
});
|
||||
await textField.fill('');
|
||||
await textField.fill('value set after back restart');
|
||||
await textField.press('Tab');
|
||||
|
||||
await page.goto(
|
||||
'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json'
|
||||
);
|
||||
// Redis will reconnect automatically and will store the variable on reconnect!
|
||||
// So we should see the new value.
|
||||
await expect(textField).toHaveValue('value set after back restart');
|
||||
|
||||
// Now, let's try to kill / reboot the back
|
||||
await rebootPusher();
|
||||
|
||||
await page.goto(
|
||||
'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json'
|
||||
);
|
||||
await expect(textField).toHaveValue('value set after back restart', {
|
||||
timeout: 60000,
|
||||
});
|
||||
await textField.fill('');
|
||||
await textField.fill('value set after pusher restart');
|
||||
await textField.press('Tab');
|
||||
|
||||
await page.goto(
|
||||
'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json'
|
||||
);
|
||||
// Redis will reconnect automatically and will store the variable on reconnect!
|
||||
// So we should see the new value.
|
||||
await expect(textField).toHaveValue('value set after pusher restart');
|
||||
});
|
||||
|
||||
test('cache doesnt prevent setting a variable in case the map changes', async ({
|
||||
page,
|
||||
}) => {
|
||||
// Let's start by visiting a map that DOES not have the variable.
|
||||
|
||||
fs.copyFileSync(
|
||||
'../maps/tests/Variables/Cache/variables_cache_1.json',
|
||||
'../maps/tests/Variables/Cache/variables_tmp.json'
|
||||
);
|
||||
|
||||
await page.goto(
|
||||
'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/Cache/variables_tmp.json'
|
||||
);
|
||||
|
||||
await login(page, 'Alice', 2);
|
||||
|
||||
// Let's REPLACE the map by a map that has a new variable
|
||||
// At this point, the back server contains a cache of the old map (with no variables)
|
||||
fs.copyFileSync(
|
||||
'../maps/tests/Variables/Cache/variables_cache_2.json',
|
||||
'../maps/tests/Variables/Cache/variables_tmp.json'
|
||||
);
|
||||
|
||||
const browser = await chromium.launch();
|
||||
const page2 = await browser.newPage();
|
||||
|
||||
await page2.goto(
|
||||
'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/Cache/variables_tmp.json'
|
||||
);
|
||||
|
||||
await login(page2, 'Alice', 2);
|
||||
|
||||
// Let's check we successfully manage to save the variable value.
|
||||
await assertLogMessage(page2, 'SUCCESS!');
|
||||
});
|
||||
});
|
@ -1,202 +0,0 @@
|
||||
import {assertLogMessage} from "./utils/log";
|
||||
|
||||
const fs = require('fs');
|
||||
const Docker = require('dockerode');
|
||||
import { Selector } from 'testcafe';
|
||||
import {login} from "./utils/roles";
|
||||
import {
|
||||
findContainer,
|
||||
rebootBack,
|
||||
rebootPusher,
|
||||
resetRedis,
|
||||
rebootTraefik,
|
||||
startContainer,
|
||||
stopContainer, stopRedis, startRedis
|
||||
} from "./utils/containers";
|
||||
import {getBackDump, getPusherDump} from "./utils/debug";
|
||||
|
||||
// Note: we are also testing that passing a random query parameter does not cause any issue.
|
||||
fixture `Variables`
|
||||
.page `http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json?somerandomparam=1`;
|
||||
|
||||
test("Test that variables storage works", async (t: TestController) => {
|
||||
|
||||
const variableInput = Selector('#textField');
|
||||
|
||||
await resetRedis();
|
||||
|
||||
await Promise.all([
|
||||
rebootBack(),
|
||||
rebootPusher(),
|
||||
]);
|
||||
|
||||
//const mainWindow = await t.getCurrentWindow();
|
||||
|
||||
await login(t, 'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json?somerandomparam=1');
|
||||
|
||||
await t //.useRole(userAliceOnPage('http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json?somerandomparam=1'))
|
||||
.switchToIframe("#cowebsite-buffer iframe")
|
||||
.expect(variableInput.value).eql('default value')
|
||||
.selectText(variableInput)
|
||||
.pressKey('delete')
|
||||
.typeText(variableInput, 'new value')
|
||||
.pressKey('tab')
|
||||
.switchToMainWindow()
|
||||
//.switchToWindow(mainWindow)
|
||||
.wait(500)
|
||||
// reload
|
||||
.navigateTo('http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json')
|
||||
.switchToIframe("#cowebsite-buffer iframe")
|
||||
.expect(variableInput.value).eql('new value')
|
||||
//.debug()
|
||||
.switchToMainWindow()
|
||||
//.wait(5000)
|
||||
//.switchToWindow(mainWindow)
|
||||
/*
|
||||
.wait(5000)
|
||||
//.debug()
|
||||
.switchToIframe("#cowebsite-buffer iframe")
|
||||
.expect(variableInput.value).eql('new value')
|
||||
.switchToMainWindow();*/
|
||||
|
||||
// Now, let's kill the reverse proxy to cut the connexion
|
||||
//console.log('Rebooting traefik');
|
||||
rebootTraefik();
|
||||
//console.log('Rebooting done');
|
||||
|
||||
// Maybe we should:
|
||||
// 1: stop Traefik
|
||||
// 2: detect reconnecting screen
|
||||
// 3: start Traefik again
|
||||
|
||||
|
||||
await t
|
||||
.switchToIframe("#cowebsite-buffer iframe")
|
||||
.expect(variableInput.value).eql('new value')
|
||||
|
||||
stopRedis();
|
||||
|
||||
// Redis is stopped, let's try to modify a variable.
|
||||
await t.selectText(variableInput)
|
||||
.pressKey('delete')
|
||||
.typeText(variableInput, 'value set while Redis stopped')
|
||||
.pressKey('tab')
|
||||
.switchToMainWindow()
|
||||
|
||||
startRedis();
|
||||
|
||||
// Navigate to some other map so that the pusher connection is freed.
|
||||
await t.navigateTo('http://maps.workadventure.localhost/tests/')
|
||||
.wait(3000);
|
||||
|
||||
|
||||
const backDump = await getBackDump();
|
||||
//console.log('backDump', backDump);
|
||||
for (const room of backDump) {
|
||||
if (room.roomUrl === 'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json') {
|
||||
throw new Error('Room still found in back');
|
||||
}
|
||||
}
|
||||
|
||||
const pusherDump = await getPusherDump();
|
||||
//console.log('pusherDump', pusherDump);
|
||||
await t.expect(pusherDump['http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json']).eql(undefined);
|
||||
|
||||
await t.navigateTo('http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json')
|
||||
.switchToIframe("#cowebsite-buffer iframe")
|
||||
// Redis will reconnect automatically and will store the variable on reconnect!
|
||||
// So we should see the new value.
|
||||
.expect(variableInput.value).eql('value set while Redis stopped')
|
||||
.switchToMainWindow()
|
||||
|
||||
|
||||
// Now, let's try to kill / reboot the back
|
||||
await rebootBack();
|
||||
|
||||
await t.navigateTo('http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json')
|
||||
.switchToIframe("#cowebsite-buffer iframe")
|
||||
.expect(variableInput.value).eql('value set while Redis stopped')
|
||||
.selectText(variableInput)
|
||||
.pressKey('delete')
|
||||
.typeText(variableInput, 'value set after back restart')
|
||||
.pressKey('tab')
|
||||
.switchToMainWindow()
|
||||
|
||||
.navigateTo('http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json')
|
||||
.switchToIframe("#cowebsite-buffer iframe")
|
||||
// Redis will reconnect automatically and will store the variable on reconnect!
|
||||
// So we should see the new value.
|
||||
.expect(variableInput.value).eql('value set after back restart')
|
||||
.switchToMainWindow()
|
||||
|
||||
// Now, let's try to kill / reboot the back
|
||||
await rebootPusher();
|
||||
|
||||
await t.navigateTo('http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json')
|
||||
.switchToIframe("#cowebsite-buffer iframe")
|
||||
.expect(variableInput.value).eql('value set after back restart')
|
||||
.selectText(variableInput)
|
||||
.pressKey('delete')
|
||||
.typeText(variableInput, 'value set after pusher restart')
|
||||
.pressKey('tab')
|
||||
.switchToMainWindow()
|
||||
|
||||
.navigateTo('http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json')
|
||||
.switchToIframe("#cowebsite-buffer iframe")
|
||||
// Redis will reconnect automatically and will store the variable on reconnect!
|
||||
// So we should see the new value.
|
||||
.expect(variableInput.value).eql('value set after pusher restart')
|
||||
.switchToMainWindow()
|
||||
|
||||
|
||||
t.ctx.passed = true;
|
||||
}).after(async t => {
|
||||
if (!t.ctx.passed) {
|
||||
console.log("Test 'Test that variables storage works' failed. Browser logs:")
|
||||
try {
|
||||
console.log(await t.getBrowserConsoleMessages());
|
||||
} catch (e) {
|
||||
console.error('Error while fetching browser logs (maybe linked to a closed iframe?)', e);
|
||||
try {
|
||||
console.log('Logs from main window:');
|
||||
console.log(await t.switchToMainWindow().getBrowserConsoleMessages());
|
||||
} catch (e) {
|
||||
console.error('Unable to retrieve logs', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
test("Test that variables cache in the back don't prevent setting a variable in case the map changes", async (t: TestController) => {
|
||||
// Let's start by visiting a map that DOES not have the variable.
|
||||
fs.copyFileSync('../maps/tests/Variables/Cache/variables_cache_1.json', '../maps/tests/Variables/Cache/variables_tmp.json');
|
||||
|
||||
//const aliceOnPageTmp = userAliceOnPage('http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/Cache/variables_tmp.json');
|
||||
|
||||
await login(t, 'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/Cache/variables_tmp.json', 'Alice', 2);
|
||||
|
||||
//.takeScreenshot('before_switch.png');
|
||||
|
||||
// Let's REPLACE the map by a map that has a new variable
|
||||
// At this point, the back server contains a cache of the old map (with no variables)
|
||||
fs.copyFileSync('../maps/tests/Variables/Cache/variables_cache_2.json', '../maps/tests/Variables/Cache/variables_tmp.json');
|
||||
await t.openWindow('http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/Cache/variables_tmp.json')
|
||||
.resizeWindow(960, 800)
|
||||
|
||||
await login(t, 'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/Cache/variables_tmp.json', 'Bob', 3);
|
||||
|
||||
//.takeScreenshot('after_switch.png');
|
||||
|
||||
// Let's check we successfully manage to save the variable value.
|
||||
await assertLogMessage(t, 'SUCCESS!');
|
||||
|
||||
t.ctx.passed = true;
|
||||
}).after(async t => {
|
||||
if (!t.ctx.passed) {
|
||||
console.log("Test 'Test that variables cache in the back don't prevent setting a variable in case the map changes' failed. Browser logs:")
|
||||
console.log(await t.getBrowserConsoleMessages());
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user