move step logging to tests, DRY; put test scenario in separate file, less globals

This commit is contained in:
Bruno Windels 2018-08-07 17:58:58 +02:00
parent 5fe3861190
commit 4e7df2126b
6 changed files with 90 additions and 63 deletions

View file

@ -17,6 +17,7 @@ limitations under the License.
const assert = require('assert');
module.exports = async function createRoom(session, roomName) {
session.log.step(`creates room ${roomName}`);
//TODO: brittle selector
const createRoomButton = await session.waitAndQuerySelector('.mx_RoleButton[aria-label="Create new room"]');
await createRoomButton.click();
@ -28,4 +29,5 @@ module.exports = async function createRoom(session, roomName) {
await createButton.click();
await session.waitForSelector('.mx_MessageComposer');
session.log.done();
}

View file

@ -17,6 +17,7 @@ limitations under the License.
const assert = require('assert');
module.exports = async function join(session, roomName) {
session.log.step(`joins room ${roomName}`);
//TODO: brittle selector
const directoryButton = await session.waitAndQuerySelector('.mx_RoleButton[aria-label="Room directory"]');
await directoryButton.click();
@ -31,4 +32,5 @@ module.exports = async function join(session, roomName) {
await joinLink.click();
await session.waitForSelector('.mx_MessageComposer');
session.log.done();
}

View file

@ -16,7 +16,8 @@ limitations under the License.
const assert = require('assert');
module.exports = async function acceptServerNoticesInviteAndConsent(session, name) {
module.exports = async function acceptServerNoticesInviteAndConsent(session, noticesName) {
session.log.step(`accepts "${noticesName}" invite and accepting terms & conditions`);
//TODO: brittle selector
const invitesHandles = await session.waitAndQueryAll('.mx_RoomTile_name.mx_RoomTile_invite');
const invitesWithText = await Promise.all(invitesHandles.map(async (inviteHandle) => {
@ -24,7 +25,7 @@ module.exports = async function acceptServerNoticesInviteAndConsent(session, nam
return {inviteHandle, text};
}));
const inviteHandle = invitesWithText.find(({inviteHandle, text}) => {
return text.trim() === name;
return text.trim() === noticesName;
}).inviteHandle;
await inviteHandle.click();
@ -40,4 +41,5 @@ module.exports = async function acceptServerNoticesInviteAndConsent(session, nam
const acceptButton = await termsPage.$('input[type=submit]');
await acceptButton.click();
await session.delay(500); //TODO yuck, timers
}
session.log.done();
}

View file

@ -18,6 +18,7 @@ const acceptTerms = require('./consent');
const assert = require('assert');
module.exports = async function signup(session, username, password, homeserver) {
session.log.step("signs up");
await session.goto(session.riotUrl('/#/register'));
//click 'Custom server' radio button
if (homeserver) {
@ -64,4 +65,5 @@ module.exports = async function signup(session, username, password, homeserver)
const url = session.page.url();
assert.strictEqual(url, session.riotUrl('/#/home'));
session.log.done();
}