mirror of https://github.com/vector-im/riot-web
move step logging to tests, DRY; put test scenario in separate file, less globals
parent
5fe3861190
commit
4e7df2126b
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
Copyright 2018 New Vector Ltd
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
const signup = require('./tests/signup');
|
||||||
|
const join = require('./tests/join');
|
||||||
|
const createRoom = require('./tests/create-room');
|
||||||
|
const acceptServerNoticesInviteAndConsent = require('./tests/server-notices-consent');
|
||||||
|
|
||||||
|
module.exports = async function scenario(createSession) {
|
||||||
|
async function createUser(username) {
|
||||||
|
const session = await createSession(username);
|
||||||
|
await signup(session, session.username, 'testtest');
|
||||||
|
const noticesName = "Server Notices";
|
||||||
|
await acceptServerNoticesInviteAndConsent(session, noticesName);
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
|
const alice = await createUser("alice");
|
||||||
|
const bob = await createUser("bob");
|
||||||
|
const room = 'test';
|
||||||
|
await createRoom(alice, room);
|
||||||
|
// await join(bob, room);
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
module.exports = async function createRoom(session, roomName) {
|
module.exports = async function createRoom(session, roomName) {
|
||||||
|
session.log.step(`creates room ${roomName}`);
|
||||||
//TODO: brittle selector
|
//TODO: brittle selector
|
||||||
const createRoomButton = await session.waitAndQuerySelector('.mx_RoleButton[aria-label="Create new room"]');
|
const createRoomButton = await session.waitAndQuerySelector('.mx_RoleButton[aria-label="Create new room"]');
|
||||||
await createRoomButton.click();
|
await createRoomButton.click();
|
||||||
|
@ -28,4 +29,5 @@ module.exports = async function createRoom(session, roomName) {
|
||||||
await createButton.click();
|
await createButton.click();
|
||||||
|
|
||||||
await session.waitForSelector('.mx_MessageComposer');
|
await session.waitForSelector('.mx_MessageComposer');
|
||||||
|
session.log.done();
|
||||||
}
|
}
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
module.exports = async function join(session, roomName) {
|
module.exports = async function join(session, roomName) {
|
||||||
|
session.log.step(`joins room ${roomName}`);
|
||||||
//TODO: brittle selector
|
//TODO: brittle selector
|
||||||
const directoryButton = await session.waitAndQuerySelector('.mx_RoleButton[aria-label="Room directory"]');
|
const directoryButton = await session.waitAndQuerySelector('.mx_RoleButton[aria-label="Room directory"]');
|
||||||
await directoryButton.click();
|
await directoryButton.click();
|
||||||
|
@ -31,4 +32,5 @@ module.exports = async function join(session, roomName) {
|
||||||
await joinLink.click();
|
await joinLink.click();
|
||||||
|
|
||||||
await session.waitForSelector('.mx_MessageComposer');
|
await session.waitForSelector('.mx_MessageComposer');
|
||||||
|
session.log.done();
|
||||||
}
|
}
|
|
@ -16,7 +16,8 @@ limitations under the License.
|
||||||
|
|
||||||
const assert = require('assert');
|
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
|
//TODO: brittle selector
|
||||||
const invitesHandles = await session.waitAndQueryAll('.mx_RoomTile_name.mx_RoomTile_invite');
|
const invitesHandles = await session.waitAndQueryAll('.mx_RoomTile_name.mx_RoomTile_invite');
|
||||||
const invitesWithText = await Promise.all(invitesHandles.map(async (inviteHandle) => {
|
const invitesWithText = await Promise.all(invitesHandles.map(async (inviteHandle) => {
|
||||||
|
@ -24,7 +25,7 @@ module.exports = async function acceptServerNoticesInviteAndConsent(session, nam
|
||||||
return {inviteHandle, text};
|
return {inviteHandle, text};
|
||||||
}));
|
}));
|
||||||
const inviteHandle = invitesWithText.find(({inviteHandle, text}) => {
|
const inviteHandle = invitesWithText.find(({inviteHandle, text}) => {
|
||||||
return text.trim() === name;
|
return text.trim() === noticesName;
|
||||||
}).inviteHandle;
|
}).inviteHandle;
|
||||||
|
|
||||||
await inviteHandle.click();
|
await inviteHandle.click();
|
||||||
|
@ -40,4 +41,5 @@ module.exports = async function acceptServerNoticesInviteAndConsent(session, nam
|
||||||
const acceptButton = await termsPage.$('input[type=submit]');
|
const acceptButton = await termsPage.$('input[type=submit]');
|
||||||
await acceptButton.click();
|
await acceptButton.click();
|
||||||
await session.delay(500); //TODO yuck, timers
|
await session.delay(500); //TODO yuck, timers
|
||||||
|
session.log.done();
|
||||||
}
|
}
|
|
@ -18,6 +18,7 @@ const acceptTerms = require('./consent');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
module.exports = async function signup(session, username, password, homeserver) {
|
module.exports = async function signup(session, username, password, homeserver) {
|
||||||
|
session.log.step("signs up");
|
||||||
await session.goto(session.riotUrl('/#/register'));
|
await session.goto(session.riotUrl('/#/register'));
|
||||||
//click 'Custom server' radio button
|
//click 'Custom server' radio button
|
||||||
if (homeserver) {
|
if (homeserver) {
|
||||||
|
@ -64,4 +65,5 @@ module.exports = async function signup(session, username, password, homeserver)
|
||||||
|
|
||||||
const url = session.page.url();
|
const url = session.page.url();
|
||||||
assert.strictEqual(url, session.riotUrl('/#/home'));
|
assert.strictEqual(url, session.riotUrl('/#/home'));
|
||||||
|
session.log.done();
|
||||||
}
|
}
|
||||||
|
|
74
start.js
74
start.js
|
@ -16,33 +16,13 @@ limitations under the License.
|
||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const RiotSession = require('./src/session');
|
const RiotSession = require('./src/session');
|
||||||
|
const scenario = require('./src/scenario');
|
||||||
|
|
||||||
const signup = require('./src/tests/signup');
|
|
||||||
const join = require('./src/tests/join');
|
|
||||||
const createRoom = require('./src/tests/create-room');
|
|
||||||
const acceptServerNoticesInviteAndConsent = require('./src/tests/server-notices-consent');
|
|
||||||
|
|
||||||
const homeserver = 'http://localhost:8008';
|
|
||||||
const riotserver = 'http://localhost:5000';
|
const riotserver = 'http://localhost:5000';
|
||||||
|
|
||||||
let sessions = [];
|
|
||||||
|
|
||||||
async function createUser(username, options, riotserver) {
|
|
||||||
const session = await RiotSession.create(username, options, riotserver);
|
|
||||||
sessions.push(session);
|
|
||||||
|
|
||||||
session.log.step("signs up");
|
|
||||||
await signup(session, session.username, 'testtest');
|
|
||||||
session.log.done();
|
|
||||||
|
|
||||||
const noticesName = "Server Notices";
|
|
||||||
session.log.step(`accepts "${noticesName}" invite and accepting terms & conditions`);
|
|
||||||
await acceptServerNoticesInviteAndConsent(session, noticesName);
|
|
||||||
session.log.done();
|
|
||||||
return session;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function runTests() {
|
async function runTests() {
|
||||||
|
let sessions = [];
|
||||||
|
|
||||||
console.log("running tests ...");
|
console.log("running tests ...");
|
||||||
const options = {};
|
const options = {};
|
||||||
if (process.env.CHROME_PATH) {
|
if (process.env.CHROME_PATH) {
|
||||||
|
@ -51,30 +31,18 @@ async function runTests() {
|
||||||
options.executablePath = path;
|
options.executablePath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
const alice = await createUser("alice", options, riotserver);
|
async function createSession(username) {
|
||||||
const bob = await createUser("bob", options, riotserver);
|
const session = await RiotSession.create(username, options, riotserver);
|
||||||
|
sessions.push(session);
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
const room = 'test';
|
let failure = false;
|
||||||
alice.log.step(`creates room ${room}`);
|
try {
|
||||||
await createRoom(alice, room);
|
await scenario(createSession);
|
||||||
alice.log.done();
|
} catch(err) {
|
||||||
|
|
||||||
bob.log.step(`joins room ${room}`);
|
|
||||||
await createRoom(bob, room);
|
|
||||||
bob.log.done();
|
|
||||||
|
|
||||||
|
|
||||||
await alice.close();
|
|
||||||
await bob.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
function onSuccess() {
|
|
||||||
console.log('all tests finished successfully');
|
|
||||||
}
|
|
||||||
|
|
||||||
async function onFailure(err) {
|
|
||||||
console.log('failure: ', err);
|
console.log('failure: ', err);
|
||||||
for(var i = 0; i < sessions.length; ++i) {
|
for(let i = 0; i < sessions.length; ++i) {
|
||||||
const session = sessions[i];
|
const session = sessions[i];
|
||||||
documentHtml = await session.page.content();
|
documentHtml = await session.page.content();
|
||||||
console.log(`---------------- START OF ${session.username} LOGS ----------------`);
|
console.log(`---------------- START OF ${session.username} LOGS ----------------`);
|
||||||
|
@ -86,8 +54,22 @@ async function onFailure(err) {
|
||||||
console.log(documentHtml);
|
console.log(documentHtml);
|
||||||
console.log(`---------------- END OF ${session.username} LOGS ----------------`);
|
console.log(`---------------- END OF ${session.username} LOGS ----------------`);
|
||||||
}
|
}
|
||||||
|
failure = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(let i = 0; i < sessions.length; ++i) {
|
||||||
|
const session = sessions[i];
|
||||||
|
await session.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failure) {
|
||||||
process.exit(-1);
|
process.exit(-1);
|
||||||
|
} else {
|
||||||
|
console.log('all tests finished successfully');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
runTests().then(onSuccess, onFailure);
|
runTests().catch(function(err) {
|
||||||
|
console.log(err);
|
||||||
|
process.exit(-1);
|
||||||
|
});
|
Loading…
Reference in New Issue