diff --git a/tests/tests/test.ts b/tests/tests/test.ts index eecafb13..c7747578 100644 --- a/tests/tests/test.ts +++ b/tests/tests/test.ts @@ -1,19 +1,17 @@ +import {assertLogMessage} from "./utils/log"; + const fs = require('fs') +import { Selector } from 'testcafe'; +import {userAlice} from "./utils/roles"; fixture `Variables` .page `http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/Cache/variables_tmp.json`; -test("Test that variables cache in the back don't prevent setting a variable in case the map changes", async t => { +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 - .typeText('input[name="loginSceneName"]', 'foo') - .click('button.loginSceneFormSubmit') - .click('button.selectCharacterButtonRight') - .click('button.selectCharacterButtonRight') - .click('button.selectCharacterSceneFormSubmit') - .click('button.letsgo'); + await t.useRole(userAlice); //.takeScreenshot('before_switch.png'); // Let's REPLACE the map by a map that has a new variable @@ -23,19 +21,9 @@ test("Test that variables cache in the back don't prevent setting a variable in await t.resizeWindow(960, 800); - await t - .typeText('input[name="loginSceneName"]', 'foo') - .click('button.loginSceneFormSubmit') - .click('button.selectCharacterButtonRight') - .click('button.selectCharacterButtonRight') - .click('button.selectCharacterSceneFormSubmit') - .click('button.letsgo'); + await t.useRole(userAlice); //.takeScreenshot('after_switch.png'); - const messages = await t.getBrowserConsoleMessages(); - - const logs = messages['log']; - // Let's check we successfully manage to save the variable value. await assertLogMessage(t, 'SUCCESS!'); @@ -46,22 +34,3 @@ test("Test that variables cache in the back don't prevent setting a variable in console.log(await t.getBrowserConsoleMessages()); } }); - -/** - * Tries to find a given log message in the logs (for 10 seconds) - */ -async function assertLogMessage(t, message: string): Promise { - 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 < 10); - - await t.expect(logs).contains(message); -} diff --git a/tests/tests/utils/log.ts b/tests/tests/utils/log.ts new file mode 100644 index 00000000..2c5980b1 --- /dev/null +++ b/tests/tests/utils/log.ts @@ -0,0 +1,20 @@ +import { Selector } from 'testcafe'; + +/** + * Tries to find a given log message in the logs (for 10 seconds) + */ +export async function assertLogMessage(t: TestController, message: string): Promise { + 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 < 10); + + await t.expect(logs).contains(message); +} diff --git a/tests/tests/utils/roles.ts b/tests/tests/utils/roles.ts new file mode 100644 index 00000000..7ed4cad7 --- /dev/null +++ b/tests/tests/utils/roles.ts @@ -0,0 +1,20 @@ +import { Role } from 'testcafe'; + +export const userAlice = Role('http://play.workadventure.localhost/', async t => { + await t + .typeText('input[name="loginSceneName"]', 'Alice') + .click('button.loginSceneFormSubmit') + .click('button.selectCharacterButtonRight') + .click('button.selectCharacterButtonRight') + .click('button.selectCharacterSceneFormSubmit') + .click('button.letsgo'); +}); + +export const userBob = Role('http://play.workadventure.localhost/', async t => { + await t + .typeText('input[name="loginSceneName"]', 'Bob') + .click('button.loginSceneFormSubmit') + .click('button.selectCharacterButtonRight') + .click('button.selectCharacterSceneFormSubmit') + .click('button.letsgo'); +});