From 94762c86c514652781ef32cc025d86198a3845e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 6 Dec 2021 11:21:18 +0100 Subject: [PATCH] Refactoring tests --- tests/tests/reconnect.ts | 4 ++-- tests/tests/utils/roles.ts | 36 ++++++++++-------------------------- tests/tests/variables.ts | 37 ++++++++++++++++++++----------------- 3 files changed, 32 insertions(+), 45 deletions(-) diff --git a/tests/tests/reconnect.ts b/tests/tests/reconnect.ts index fa7352da..62f92fd2 100644 --- a/tests/tests/reconnect.ts +++ b/tests/tests/reconnect.ts @@ -3,7 +3,7 @@ import {assertLogMessage} from "./utils/log"; const fs = require('fs'); const Docker = require('dockerode'); import { Selector } from 'testcafe'; -import {userAlice} from "./utils/roles"; +import {login} from "./utils/roles"; import {findContainer, rebootBack, rebootPusher, resetRedis, startContainer, stopContainer} from "./utils/containers"; fixture `Reconnection` @@ -22,7 +22,7 @@ test("Test that connection can succeed even if WorkAdventure starts while pusher await startContainer(container); - await t.useRole(userAlice); + await login(t, 'http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/mousewheel.json'); t.ctx.passed = true; }).after(async t => { diff --git a/tests/tests/utils/roles.ts b/tests/tests/utils/roles.ts index 5282e564..7630f086 100644 --- a/tests/tests/utils/roles.ts +++ b/tests/tests/utils/roles.ts @@ -1,31 +1,15 @@ import { Role } from 'testcafe'; -export const userAliceOnPage = (url: string) => Role(url, 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 function login(t: TestController, url: string, userName: string = "Alice", characterNumber: number = 2) { + t = t + .navigateTo(url) + .typeText('input[name="loginSceneName"]', userName) + .click('button.loginSceneFormSubmit'); + for (let i = 0; i < characterNumber; i++) { + t = t.click('button.selectCharacterButtonRight'); + } -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') + return t.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'); -}); +} diff --git a/tests/tests/variables.ts b/tests/tests/variables.ts index f2ad07b5..ce377368 100644 --- a/tests/tests/variables.ts +++ b/tests/tests/variables.ts @@ -3,7 +3,7 @@ import {assertLogMessage} from "./utils/log"; const fs = require('fs'); const Docker = require('dockerode'); import { Selector } from 'testcafe'; -import {userAlice, userAliceOnPage} from "./utils/roles"; +import {login} from "./utils/roles"; import { findContainer, rebootBack, @@ -32,7 +32,9 @@ test("Test that variables storage works", async (t: TestController) => { //const mainWindow = await t.getCurrentWindow(); - await t.useRole(userAliceOnPage('http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json?somerandomparam=1')) + 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) @@ -48,6 +50,7 @@ test("Test that variables storage works", async (t: TestController) => { .expect(variableInput.value).eql('new value') //.debug() .switchToMainWindow() + //.wait(5000) //.switchToWindow(mainWindow) /* .wait(5000) @@ -58,12 +61,16 @@ test("Test that variables storage works", async (t: TestController) => { // Now, let's kill the reverse proxy to cut the connexion //console.log('Rebooting traefik'); - await rebootTraefik(); + rebootTraefik(); //console.log('Rebooting done'); + // Maybe we should: + // 1: stop Traefik + // 2: detect reconnecting screen + // 3: start Traefik again + await t - .wait(10000) // Note sure why but maybe this will solve problem in CI/CD env .switchToIframe("#cowebsite-buffer iframe") .expect(variableInput.value).eql('new value') @@ -142,19 +149,10 @@ test("Test that variables storage works", async (t: TestController) => { .switchToMainWindow() - /* - const backContainer = await findContainer('back'); - - await stopContainer(backContainer); - - await startContainer(backContainer); -*/ - - t.ctx.passed = true; }).after(async t => { if (!t.ctx.passed) { - console.log("Test failed. Browser logs:") + console.log("Test 'Test that variables storage works' failed. Browser logs:") try { console.log(await t.getBrowserConsoleMessages()); } catch (e) { @@ -174,7 +172,10 @@ test("Test that variables cache in the back don't prevent setting a variable in // 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); + //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 @@ -182,7 +183,9 @@ test("Test that variables cache in the back don't prevent setting a variable in 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); + + 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. @@ -191,7 +194,7 @@ test("Test that variables cache in the back don't prevent setting a variable in t.ctx.passed = true; }).after(async t => { if (!t.ctx.passed) { - console.log("Test failed. Browser logs:") + 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()); } });