Refactoring test cafe tests
- Using "Roles" to log users - Adding seemingly useless import statement but important for code completion
This commit is contained in:
parent
ecb72d0fd1
commit
eac4bb2875
@ -1,19 +1,17 @@
|
|||||||
|
import {assertLogMessage} from "./utils/log";
|
||||||
|
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
import { Selector } from 'testcafe';
|
||||||
|
import {userAlice} from "./utils/roles";
|
||||||
|
|
||||||
fixture `Variables`
|
fixture `Variables`
|
||||||
.page `http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/Cache/variables_tmp.json`;
|
.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.
|
// 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');
|
fs.copyFileSync('../maps/tests/Variables/Cache/variables_cache_1.json', '../maps/tests/Variables/Cache/variables_tmp.json');
|
||||||
|
|
||||||
await t
|
await t.useRole(userAlice);
|
||||||
.typeText('input[name="loginSceneName"]', 'foo')
|
|
||||||
.click('button.loginSceneFormSubmit')
|
|
||||||
.click('button.selectCharacterButtonRight')
|
|
||||||
.click('button.selectCharacterButtonRight')
|
|
||||||
.click('button.selectCharacterSceneFormSubmit')
|
|
||||||
.click('button.letsgo');
|
|
||||||
//.takeScreenshot('before_switch.png');
|
//.takeScreenshot('before_switch.png');
|
||||||
|
|
||||||
// Let's REPLACE the map by a map that has a new variable
|
// 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.resizeWindow(960, 800);
|
||||||
|
|
||||||
await t
|
await t.useRole(userAlice);
|
||||||
.typeText('input[name="loginSceneName"]', 'foo')
|
|
||||||
.click('button.loginSceneFormSubmit')
|
|
||||||
.click('button.selectCharacterButtonRight')
|
|
||||||
.click('button.selectCharacterButtonRight')
|
|
||||||
.click('button.selectCharacterSceneFormSubmit')
|
|
||||||
.click('button.letsgo');
|
|
||||||
//.takeScreenshot('after_switch.png');
|
//.takeScreenshot('after_switch.png');
|
||||||
|
|
||||||
const messages = await t.getBrowserConsoleMessages();
|
|
||||||
|
|
||||||
const logs = messages['log'];
|
|
||||||
|
|
||||||
// Let's check we successfully manage to save the variable value.
|
// Let's check we successfully manage to save the variable value.
|
||||||
await assertLogMessage(t, 'SUCCESS!');
|
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());
|
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<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 < 10);
|
|
||||||
|
|
||||||
await t.expect(logs).contains(message);
|
|
||||||
}
|
|
||||||
|
20
tests/tests/utils/log.ts
Normal file
20
tests/tests/utils/log.ts
Normal file
@ -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<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 < 10);
|
||||||
|
|
||||||
|
await t.expect(logs).contains(message);
|
||||||
|
}
|
20
tests/tests/utils/roles.ts
Normal file
20
tests/tests/utils/roles.ts
Normal file
@ -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');
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user