add playwright and run e2e tests on production like environment

This commit is contained in:
Lukas Hass
2022-02-18 14:40:20 +01:00
parent 8dc31c9e06
commit b1c7e01008
20 changed files with 1987 additions and 7331 deletions
+2
View File
@@ -1 +1,3 @@
/node_modules
test-results/
playwright-report/
-30
View File
@@ -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;
});
` } ]*/
}
+1544 -6788
View File
File diff suppressed because it is too large Load Diff
+6 -8
View File
@@ -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
View 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
View File
@@ -1 +0,0 @@
*
+15
View 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');
});
});
-44
View File
@@ -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
View 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);
});
});
-63
View File
@@ -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
View 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');
});
});
-34
View File
@@ -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());
}
});
+6 -1
View File
@@ -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 + '/../../../'
+15 -14
View File
@@ -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);
}
+14 -16
View File
@@ -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
View 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!');
});
});
-202
View File
@@ -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());
}
});