This commit is contained in:
Bruno Windels 2019-10-09 17:51:50 +02:00
parent 3e971e4880
commit 2d848bba29
25 changed files with 84 additions and 100 deletions

View file

@ -21,10 +21,9 @@ module.exports = class LogBuffer {
const result = eventMapper(arg); const result = eventMapper(arg);
if (reduceAsync) { if (reduceAsync) {
result.then((r) => this.buffer += r); result.then((r) => this.buffer += r);
} } else {
else {
this.buffer += result; this.buffer += result;
} }
}); });
} }
} };

View file

@ -59,4 +59,4 @@ module.exports = class Logger {
this.muted = false; this.muted = false;
return this; return this;
} }
} };

View file

@ -57,13 +57,13 @@ module.exports = class RestSessionCreator {
`-u ${username}`, `-u ${username}`,
`-p ${password}`, `-p ${password}`,
'--no-admin', '--no-admin',
this.hsUrl this.hsUrl,
]; ];
const registerCmd = `./register_new_matrix_user ${registerArgs.join(' ')}`; const registerCmd = `./register_new_matrix_user ${registerArgs.join(' ')}`;
const allCmds = [ const allCmds = [
`cd ${this.synapseSubdir}`, `cd ${this.synapseSubdir}`,
". ./activate", ". ./activate",
registerCmd registerCmd,
].join(' && '); ].join(' && ');
await execAsync(allCmds, {cwd: this.cwd, encoding: 'utf-8'}); await execAsync(allCmds, {cwd: this.cwd, encoding: 'utf-8'});
@ -74,9 +74,9 @@ module.exports = class RestSessionCreator {
"type": "m.login.password", "type": "m.login.password",
"identifier": { "identifier": {
"type": "m.id.user", "type": "m.id.user",
"user": username "user": username,
}, },
"password": password "password": password,
}; };
const url = `${this.hsUrl}/_matrix/client/r0/login`; const url = `${this.hsUrl}/_matrix/client/r0/login`;
const responseBody = await request.post({url, json: true, body: requestBody}); const responseBody = await request.post({url, json: true, body: requestBody});
@ -88,4 +88,4 @@ module.exports = class RestSessionCreator {
hsUrl: this.hsUrl, hsUrl: this.hsUrl,
}; };
} }
} };

View file

@ -14,9 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
const request = require('request-promise-native');
const RestRoom = require('./room');
const {approveConsent} = require('./consent');
const Logger = require('../logger'); const Logger = require('../logger');
module.exports = class RestMultiSession { module.exports = class RestMultiSession {
@ -31,7 +28,7 @@ module.exports = class RestMultiSession {
pop(userName) { pop(userName) {
const idx = this.sessions.findIndex((s) => s.userName() === userName); const idx = this.sessions.findIndex((s) => s.userName() === userName);
if(idx === -1) { if (idx === -1) {
throw new Error(`user ${userName} not found`); throw new Error(`user ${userName} not found`);
} }
const session = this.sessions.splice(idx, 1)[0]; const session = this.sessions.splice(idx, 1)[0];
@ -39,7 +36,7 @@ module.exports = class RestMultiSession {
} }
async setDisplayName(fn) { async setDisplayName(fn) {
this.log.step("set their display name") this.log.step("set their display name");
await Promise.all(this.sessions.map(async (s) => { await Promise.all(this.sessions.map(async (s) => {
s.log.mute(); s.log.mute();
await s.setDisplayName(fn(s)); await s.setDisplayName(fn(s));
@ -49,10 +46,10 @@ module.exports = class RestMultiSession {
} }
async join(roomIdOrAlias) { async join(roomIdOrAlias) {
this.log.step(`join ${roomIdOrAlias}`) this.log.step(`join ${roomIdOrAlias}`);
const rooms = await Promise.all(this.sessions.map(async (s) => { const rooms = await Promise.all(this.sessions.map(async (s) => {
s.log.mute(); s.log.mute();
const room = await s.join(roomIdOrAlias); const room = await s.join(roomIdOrAlias);
s.log.unmute(); s.log.unmute();
return room; return room;
})); }));
@ -64,7 +61,7 @@ module.exports = class RestMultiSession {
const rooms = this.sessions.map(s => s.room(roomIdOrAlias)); const rooms = this.sessions.map(s => s.room(roomIdOrAlias));
return new RestMultiRoom(rooms, roomIdOrAlias, this.log); return new RestMultiRoom(rooms, roomIdOrAlias, this.log);
} }
} };
class RestMultiRoom { class RestMultiRoom {
constructor(rooms, roomIdOrAlias, log) { constructor(rooms, roomIdOrAlias, log) {
@ -74,7 +71,7 @@ class RestMultiRoom {
} }
async talk(message) { async talk(message) {
this.log.step(`say "${message}" in ${this.roomIdOrAlias}`) this.log.step(`say "${message}" in ${this.roomIdOrAlias}`);
await Promise.all(this.rooms.map(async (r) => { await Promise.all(this.rooms.map(async (r) => {
r.log.mute(); r.log.mute();
await r.talk(message); await r.talk(message);
@ -84,7 +81,7 @@ class RestMultiRoom {
} }
async leave() { async leave() {
this.log.step(`leave ${this.roomIdOrAlias}`) this.log.step(`leave ${this.roomIdOrAlias}`);
await Promise.all(this.rooms.map(async (r) => { await Promise.all(this.rooms.map(async (r) => {
r.log.mute(); r.log.mute();
await r.leave(); await r.leave();

View file

@ -25,18 +25,18 @@ module.exports = class RestRoom {
} }
async talk(message) { async talk(message) {
this.log.step(`says "${message}" in ${this._roomId}`) this.log.step(`says "${message}" in ${this._roomId}`);
const txId = uuidv4(); const txId = uuidv4();
await this.session._put(`/rooms/${this._roomId}/send/m.room.message/${txId}`, { await this.session._put(`/rooms/${this._roomId}/send/m.room.message/${txId}`, {
"msgtype": "m.text", "msgtype": "m.text",
"body": message "body": message,
}); });
this.log.done(); this.log.done();
return txId; return txId;
} }
async leave() { async leave() {
this.log.step(`leaves ${this._roomId}`) this.log.step(`leaves ${this._roomId}`);
await this.session._post(`/rooms/${this._roomId}/leave`); await this.session._post(`/rooms/${this._roomId}/leave`);
this.log.done(); this.log.done();
} }
@ -44,4 +44,4 @@ module.exports = class RestRoom {
roomId() { roomId() {
return this._roomId; return this._roomId;
} }
} };

View file

@ -43,17 +43,17 @@ module.exports = class RestSession {
this.log.step(`sets their display name to ${displayName}`); this.log.step(`sets their display name to ${displayName}`);
this._displayName = displayName; this._displayName = displayName;
await this._put(`/profile/${this._credentials.userId}/displayname`, { await this._put(`/profile/${this._credentials.userId}/displayname`, {
displayname: displayName displayname: displayName,
}); });
this.log.done(); this.log.done();
} }
async join(roomIdOrAlias) { async join(roomIdOrAlias) {
this.log.step(`joins ${roomIdOrAlias}`); this.log.step(`joins ${roomIdOrAlias}`);
const {room_id} = await this._post(`/join/${encodeURIComponent(roomIdOrAlias)}`); const roomId = await this._post(`/join/${encodeURIComponent(roomIdOrAlias)}`).room_id;
this.log.done(); this.log.done();
const room = new RestRoom(this, room_id, this.log); const room = new RestRoom(this, roomId, this.log);
this._rooms[room_id] = room; this._rooms[roomId] = room;
this._rooms[roomIdOrAlias] = room; this._rooms[roomIdOrAlias] = room;
return room; return room;
} }
@ -86,9 +86,9 @@ module.exports = class RestSession {
body.topic = options.topic; body.topic = options.topic;
} }
const {room_id} = await this._post(`/createRoom`, body); const roomId = await this._post(`/createRoom`, body).room_id;
this.log.done(); this.log.done();
return new RestRoom(this, room_id, this.log); return new RestRoom(this, roomId, this.log);
} }
_post(csApiPath, body) { _post(csApiPath, body) {
@ -105,23 +105,22 @@ module.exports = class RestSession {
url: `${this._credentials.hsUrl}/_matrix/client/r0${csApiPath}`, url: `${this._credentials.hsUrl}/_matrix/client/r0${csApiPath}`,
method, method,
headers: { headers: {
"Authorization": `Bearer ${this._credentials.accessToken}` "Authorization": `Bearer ${this._credentials.accessToken}`,
}, },
json: true, json: true,
body body,
}); });
return responseBody; return responseBody;
} catch (err) {
} catch(err) {
const responseBody = err.response.body; const responseBody = err.response.body;
if (responseBody.errcode === 'M_CONSENT_NOT_GIVEN') { if (responseBody.errcode === 'M_CONSENT_NOT_GIVEN') {
await approveConsent(responseBody.consent_uri); await approveConsent(responseBody.consent_uri);
return this._request(method, csApiPath, body); return this._request(method, csApiPath, body);
} else if(responseBody && responseBody.error) { } else if (responseBody && responseBody.error) {
throw new Error(`${method} ${csApiPath}: ${responseBody.error}`); throw new Error(`${method} ${csApiPath}: ${responseBody.error}`);
} else { } else {
throw new Error(`${method} ${csApiPath}: ${err.response.statusCode}`); throw new Error(`${method} ${csApiPath}: ${err.response.statusCode}`);
} }
} }
} }
} };

View file

@ -42,7 +42,7 @@ module.exports = async function scenario(createSession, restCreator) {
console.log("create REST users:"); console.log("create REST users:");
const charlies = await createRestUsers(restCreator); const charlies = await createRestUsers(restCreator);
await lazyLoadingScenarios(alice, bob, charlies); await lazyLoadingScenarios(alice, bob, charlies);
} };
async function createRestUsers(restCreator) { async function createRestUsers(restCreator) {
const usernames = range(1, 10).map((i) => `charly-${i}`); const usernames = range(1, 10).map((i) => `charly-${i}`);

View file

@ -30,7 +30,7 @@ module.exports = async function roomDirectoryScenarios(alice, bob) {
const bobMessage = "hi Alice!"; const bobMessage = "hi Alice!";
await sendMessage(bob, bobMessage); await sendMessage(bob, bobMessage);
await receiveMessage(alice, {sender: "bob", body: bobMessage}); await receiveMessage(alice, {sender: "bob", body: bobMessage});
const aliceMessage = "hi Bob, welcome!" const aliceMessage = "hi Bob, welcome!";
await sendMessage(alice, aliceMessage); await sendMessage(alice, aliceMessage);
await receiveMessage(bob, {sender: "alice", body: aliceMessage}); await receiveMessage(bob, {sender: "alice", body: aliceMessage});
} };

View file

@ -14,10 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
const {delay} = require('../util');
const {acceptDialogMaybe} = require('../usecases/dialog');
const join = require('../usecases/join');
const sendMessage = require('../usecases/send-message'); const sendMessage = require('../usecases/send-message');
const acceptInvite = require('../usecases/accept-invite'); const acceptInvite = require('../usecases/accept-invite');
const invite = require('../usecases/invite'); const invite = require('../usecases/invite');
@ -43,10 +39,10 @@ module.exports = async function e2eEncryptionScenarios(alice, bob) {
const [bobSas, aliceSas] = await Promise.all([bobSasPromise, aliceSasPromise]); const [bobSas, aliceSas] = await Promise.all([bobSasPromise, aliceSasPromise]);
assert.deepEqual(bobSas, aliceSas); assert.deepEqual(bobSas, aliceSas);
bob.log.done(`done (match for ${bobSas.join(", ")})`); bob.log.done(`done (match for ${bobSas.join(", ")})`);
const aliceMessage = "Guess what I just heard?!" const aliceMessage = "Guess what I just heard?!";
await sendMessage(alice, aliceMessage); await sendMessage(alice, aliceMessage);
await receiveMessage(bob, {sender: "alice", body: aliceMessage, encrypted: true}); await receiveMessage(bob, {sender: "alice", body: aliceMessage, encrypted: true});
const bobMessage = "You've got to tell me!"; const bobMessage = "You've got to tell me!";
await sendMessage(bob, bobMessage); await sendMessage(bob, bobMessage);
await receiveMessage(alice, {sender: "bob", body: bobMessage, encrypted: true}); await receiveMessage(alice, {sender: "bob", body: bobMessage, encrypted: true});
} };

View file

@ -20,12 +20,11 @@ const join = require('../usecases/join');
const sendMessage = require('../usecases/send-message'); const sendMessage = require('../usecases/send-message');
const { const {
checkTimelineContains, checkTimelineContains,
scrollToTimelineTop scrollToTimelineTop,
} = require('../usecases/timeline'); } = require('../usecases/timeline');
const {createRoom} = require('../usecases/create-room'); const {createRoom} = require('../usecases/create-room');
const {getMembersInMemberlist} = require('../usecases/memberlist'); const {getMembersInMemberlist} = require('../usecases/memberlist');
const changeRoomSettings = require('../usecases/room-settings'); const changeRoomSettings = require('../usecases/room-settings');
const {enableLazyLoading} = require('../usecases/settings');
const assert = require('assert'); const assert = require('assert');
module.exports = async function lazyLoadingScenarios(alice, bob, charlies) { module.exports = async function lazyLoadingScenarios(alice, bob, charlies) {
@ -43,7 +42,7 @@ module.exports = async function lazyLoadingScenarios(alice, bob, charlies) {
await delay(1000); await delay(1000);
await checkMemberListLacksCharlies(alice, charlies); await checkMemberListLacksCharlies(alice, charlies);
await checkMemberListLacksCharlies(bob, charlies); await checkMemberListLacksCharlies(bob, charlies);
} };
const room = "Lazy Loading Test"; const room = "Lazy Loading Test";
const alias = "#lltest:localhost"; const alias = "#lltest:localhost";
@ -60,7 +59,7 @@ async function setupRoomWithBobAliceAndCharlies(alice, bob, charlies) {
await charlyMembers.talk(charlyMsg1); await charlyMembers.talk(charlyMsg1);
await charlyMembers.talk(charlyMsg2); await charlyMembers.talk(charlyMsg2);
bob.log.step("sends 20 messages").mute(); bob.log.step("sends 20 messages").mute();
for(let i = 20; i >= 1; --i) { for (let i = 20; i >= 1; --i) {
await sendMessage(bob, `I will only say this ${i} time(s)!`); await sendMessage(bob, `I will only say this ${i} time(s)!`);
} }
bob.log.unmute().done(); bob.log.unmute().done();
@ -112,7 +111,7 @@ async function joinCharliesWhileAliceIsOffline(alice, charly6to10) {
const members6to10 = await charly6to10.join(alias); const members6to10 = await charly6to10.join(alias);
const member6 = members6to10.rooms[0]; const member6 = members6to10.rooms[0];
member6.log.step("sends 20 messages").mute(); member6.log.step("sends 20 messages").mute();
for(let i = 20; i >= 1; --i) { for (let i = 20; i >= 1; --i) {
await member6.talk("where is charly?"); await member6.talk("where is charly?");
} }
member6.log.unmute().done(); member6.log.unmute().done();

View file

@ -42,7 +42,7 @@ module.exports = class RiotSession {
const page = await browser.newPage(); const page = await browser.newPage();
await page.setViewport({ await page.setViewport({
width: 1280, width: 1280,
height: 800 height: 800,
}); });
if (throttleCpuFactor !== 1) { if (throttleCpuFactor !== 1) {
const client = await page.target().createCDPSession(); const client = await page.target().createCDPSession();
@ -55,8 +55,8 @@ module.exports = class RiotSession {
async tryGetInnertext(selector) { async tryGetInnertext(selector) {
const field = await this.page.$(selector); const field = await this.page.$(selector);
if (field != null) { if (field != null) {
const text_handle = await field.getProperty('innerText'); const textHandle = await field.getProperty('innerText');
return await text_handle.jsonValue(); return await textHandle.jsonValue();
} }
return null; return null;
} }
@ -70,7 +70,7 @@ module.exports = class RiotSession {
return this.getElementProperty(field, 'innerText'); return this.getElementProperty(field, 'innerText');
} }
getOuterHTML(element_handle) { getOuterHTML(field) {
return this.getElementProperty(field, 'outerHTML'); return this.getElementProperty(field, 'outerHTML');
} }
@ -97,12 +97,12 @@ module.exports = class RiotSession {
return { return {
logs() { logs() {
return buffer; return buffer;
} },
} };
} }
async printElements(label, elements) { async printElements(label, elements) {
console.log(label, await Promise.all(elements.map(getOuterHTML))); console.log(label, await Promise.all(elements.map(this.getOuterHTML)));
} }
async replaceInputText(input, text) { async replaceInputText(input, text) {
@ -210,7 +210,7 @@ module.exports = class RiotSession {
async poll(callback, interval = 100) { async poll(callback, interval = 100) {
const timeout = DEFAULT_TIMEOUT; const timeout = DEFAULT_TIMEOUT;
let waited = 0; let waited = 0;
while(waited < timeout) { while (waited < timeout) {
await this.delay(interval); await this.delay(interval);
waited += interval; waited += interval;
if (await callback()) { if (await callback()) {
@ -219,4 +219,4 @@ module.exports = class RiotSession {
} }
return false; return false;
} }
} };

View file

@ -14,9 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
const assert = require('assert');
const {acceptDialogMaybe} = require('./dialog');
module.exports = async function acceptInvite(session, name) { module.exports = async function acceptInvite(session, name) {
session.log.step(`accepts "${name}" invite`); session.log.step(`accepts "${name}" invite`);
//TODO: brittle selector //TODO: brittle selector
@ -35,4 +32,4 @@ module.exports = async function acceptInvite(session, name) {
await acceptInvitationLink.click(); await acceptInvitationLink.click();
session.log.done(); session.log.done();
} };

View file

@ -14,8 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
const assert = require('assert');
async function openRoomDirectory(session) { async function openRoomDirectory(session) {
const roomDirectoryButton = await session.query('.mx_LeftPanel_explore .mx_AccessibleButton'); const roomDirectoryButton = await session.query('.mx_LeftPanel_explore .mx_AccessibleButton');
await roomDirectoryButton.click(); await roomDirectoryButton.click();

View file

@ -33,7 +33,7 @@ async function acceptDialogMaybe(session, expectedTitle) {
let primaryButton = null; let primaryButton = null;
try { try {
primaryButton = await session.query(".mx_Dialog .mx_Dialog_primary"); primaryButton = await session.query(".mx_Dialog .mx_Dialog_primary");
} catch(err) { } catch (err) {
return false; return false;
} }
if (expectedTitle) { if (expectedTitle) {

View file

@ -14,8 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
const assert = require('assert');
module.exports = async function invite(session, userId) { module.exports = async function invite(session, userId) {
session.log.step(`invites "${userId}" to room`); session.log.step(`invites "${userId}" to room`);
await session.delay(1000); await session.delay(1000);
@ -27,4 +25,4 @@ module.exports = async function invite(session, userId) {
const confirmButton = await session.query(".mx_Dialog_primary"); const confirmButton = await session.query(".mx_Dialog_primary");
await confirmButton.click(); await confirmButton.click();
session.log.done(); session.log.done();
} };

View file

@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
const assert = require('assert');
const {openRoomDirectory} = require('./create-room'); const {openRoomDirectory} = require('./create-room');
module.exports = async function join(session, roomName) { module.exports = async function join(session, roomName) {
@ -27,4 +26,4 @@ module.exports = async function join(session, roomName) {
await joinFirstLink.click(); await joinFirstLink.click();
await session.query('.mx_MessageComposer'); await session.query('.mx_MessageComposer');
session.log.done(); session.log.done();
} };

View file

@ -22,7 +22,7 @@ async function openMemberInfo(session, name) {
return m.displayName === name; return m.displayName === name;
}).map((m) => m.label)[0]; }).map((m) => m.label)[0];
await matchingLabel.click(); await matchingLabel.click();
}; }
module.exports.openMemberInfo = openMemberInfo; module.exports.openMemberInfo = openMemberInfo;
@ -39,10 +39,11 @@ module.exports.verifyDeviceForUser = async function(session, name, expectedDevic
// expect "Verify device" dialog and click "Begin Verification" // expect "Verify device" dialog and click "Begin Verification"
const dialogHeader = await session.innerText(await session.query(".mx_Dialog .mx_Dialog_title")); const dialogHeader = await session.innerText(await session.query(".mx_Dialog .mx_Dialog_title"));
assert(dialogHeader, "Verify device"); assert(dialogHeader, "Verify device");
const beginVerificationButton = await session.query(".mx_Dialog .mx_Dialog_primary") const beginVerificationButton = await session.query(".mx_Dialog .mx_Dialog_primary");
await beginVerificationButton.click(); await beginVerificationButton.click();
// get emoji SAS labels // get emoji SAS labels
const sasLabelElements = await session.queryAll(".mx_VerificationShowSas .mx_VerificationShowSas_emojiSas .mx_VerificationShowSas_emojiSas_label"); const sasLabelElements = await session.queryAll(
".mx_VerificationShowSas .mx_VerificationShowSas_emojiSas .mx_VerificationShowSas_emojiSas_label");
const sasLabels = await Promise.all(sasLabelElements.map(e => session.innerText(e))); const sasLabels = await Promise.all(sasLabelElements.map(e => session.innerText(e)));
console.log("my sas labels", sasLabels); console.log("my sas labels", sasLabels);
@ -58,7 +59,7 @@ module.exports.verifyDeviceForUser = async function(session, name, expectedDevic
const closeMemberInfo = await session.query(".mx_MemberInfo_cancel"); const closeMemberInfo = await session.query(".mx_MemberInfo_cancel");
await closeMemberInfo.click(); await closeMemberInfo.click();
session.log.done(); session.log.done();
} };
async function getMembersInMemberlist(session) { async function getMembersInMemberlist(session) {
const memberNameElements = await session.queryAll(".mx_MemberList .mx_EntityTile_name"); const memberNameElements = await session.queryAll(".mx_MemberList .mx_EntityTile_name");

View file

@ -96,4 +96,4 @@ module.exports = async function changeRoomSettings(session, settings) {
await closeButton.click(); await closeButton.click();
session.log.endGroup(); session.log.endGroup();
} };

View file

@ -31,4 +31,4 @@ module.exports = async function sendMessage(session, message) {
// wait for the message to appear sent // wait for the message to appear sent
await session.query(".mx_EventTile_last:not(.mx_EventTile_sending)"); await session.query(".mx_EventTile_last:not(.mx_EventTile_sending)");
session.log.done(); session.log.done();
} };

View file

@ -22,7 +22,8 @@ async function openSettings(session, section) {
const settingsItem = await session.query(".mx_TopLeftMenu_icon_settings"); const settingsItem = await session.query(".mx_TopLeftMenu_icon_settings");
await settingsItem.click(); await settingsItem.click();
if (section) { if (section) {
const sectionButton = await session.query(`.mx_UserSettingsDialog .mx_TabbedView_tabLabels .mx_UserSettingsDialog_${section}Icon`); const sectionButton = await session.query(
`.mx_UserSettingsDialog .mx_TabbedView_tabLabels .mx_UserSettingsDialog_${section}Icon`);
await sectionButton.click(); await sectionButton.click();
} }
} }
@ -37,7 +38,7 @@ module.exports.enableLazyLoading = async function(session) {
const closeButton = await session.query(".mx_RoomHeader_cancelButton"); const closeButton = await session.query(".mx_RoomHeader_cancelButton");
await closeButton.click(); await closeButton.click();
session.log.done(); session.log.done();
} };
module.exports.getE2EDeviceFromSettings = async function(session) { module.exports.getE2EDeviceFromSettings = async function(session) {
session.log.step(`gets e2e device/key from settings`); session.log.step(`gets e2e device/key from settings`);
@ -50,4 +51,4 @@ module.exports.getE2EDeviceFromSettings = async function(session) {
await closeButton.click(); await closeButton.click();
session.log.done(); session.log.done();
return {id, key}; return {id, key};
} };

View file

@ -60,8 +60,8 @@ module.exports = async function signup(session, username, password, homeserver)
// Password validation is async, wait for it to complete before submit // Password validation is async, wait for it to complete before submit
await session.query(".mx_Field_valid #mx_RegistrationForm_password"); await session.query(".mx_Field_valid #mx_RegistrationForm_password");
//check no errors //check no errors
const error_text = await session.tryGetInnertext('.mx_Login_error'); const errorText = await session.tryGetInnertext('.mx_Login_error');
assert.strictEqual(!!error_text, false); assert.strictEqual(!!errorText, false);
//submit form //submit form
//await page.screenshot({path: "beforesubmit.png", fullPage: true}); //await page.screenshot({path: "beforesubmit.png", fullPage: true});
await registerButton.click(); await registerButton.click();
@ -87,4 +87,4 @@ module.exports = async function signup(session, username, password, homeserver)
}); });
assert(foundHomeUrl); assert(foundHomeUrl);
session.log.done(); session.log.done();
} };

View file

@ -36,11 +36,11 @@ module.exports.scrollToTimelineTop = async function(session) {
} else { } else {
await new Promise((resolve) => setTimeout(resolve, 50)); await new Promise((resolve) => setTimeout(resolve, 50));
} }
} while (!timedOut) } while (!timedOut);
}); });
}) });
session.log.done(); session.log.done();
} };
module.exports.receiveMessage = async function(session, expectedMessage) { module.exports.receiveMessage = async function(session, expectedMessage) {
session.log.step(`receives message "${expectedMessage.body}" from ${expectedMessage.sender}`); session.log.step(`receives message "${expectedMessage.body}" from ${expectedMessage.sender}`);
@ -56,7 +56,7 @@ module.exports.receiveMessage = async function(session, expectedMessage) {
await session.poll(async () => { await session.poll(async () => {
try { try {
lastMessage = await getLastMessage(); lastMessage = await getLastMessage();
} catch(err) { } catch (err) {
return false; return false;
} }
// stop polling when found the expected message // stop polling when found the expected message
@ -66,10 +66,10 @@ module.exports.receiveMessage = async function(session, expectedMessage) {
}); });
assertMessage(lastMessage, expectedMessage); assertMessage(lastMessage, expectedMessage);
session.log.done(); session.log.done();
} };
module.exports.checkTimelineContains = async function (session, expectedMessages, sendersDescription) { module.exports.checkTimelineContains = async function(session, expectedMessages, sendersDescription) {
session.log.step(`checks timeline contains ${expectedMessages.length} ` + session.log.step(`checks timeline contains ${expectedMessages.length} ` +
`given messages${sendersDescription ? ` from ${sendersDescription}`:""}`); `given messages${sendersDescription ? ` from ${sendersDescription}`:""}`);
const eventTiles = await getAllEventTiles(session); const eventTiles = await getAllEventTiles(session);
@ -94,14 +94,14 @@ module.exports.checkTimelineContains = async function (session, expectedMessages
}); });
try { try {
assertMessage(foundMessage, expectedMessage); assertMessage(foundMessage, expectedMessage);
} catch(err) { } catch (err) {
console.log("timelineMessages", timelineMessages); console.log("timelineMessages", timelineMessages);
throw err; throw err;
} }
}); });
session.log.done(); session.log.done();
} };
function assertMessage(foundMessage, expectedMessage) { function assertMessage(foundMessage, expectedMessage) {
assert(foundMessage, `message ${JSON.stringify(expectedMessage)} not found in timeline`); assert(foundMessage, `message ${JSON.stringify(expectedMessage)} not found in timeline`);

View file

@ -31,7 +31,8 @@ async function startVerification(session, name) {
} }
async function getSasCodes(session) { async function getSasCodes(session) {
const sasLabelElements = await session.queryAll(".mx_VerificationShowSas .mx_VerificationShowSas_emojiSas .mx_VerificationShowSas_emojiSas_label"); const sasLabelElements = await session.queryAll(
".mx_VerificationShowSas .mx_VerificationShowSas_emojiSas .mx_VerificationShowSas_emojiSas_label");
const sasLabels = await Promise.all(sasLabelElements.map(e => session.innerText(e))); const sasLabels = await Promise.all(sasLabelElements.map(e => session.innerText(e)));
return sasLabels; return sasLabels;
} }

View file

@ -20,8 +20,8 @@ module.exports.range = function(start, amount, step = 1) {
r.push(start + (i * step)); r.push(start + (i * step));
} }
return r; return r;
} };
module.exports.delay = function(ms) { module.exports.delay = function(ms) {
return new Promise((resolve) => setTimeout(resolve, ms)); return new Promise((resolve) => setTimeout(resolve, ms));
} };

View file

@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
const assert = require('assert');
const RiotSession = require('./src/session'); const RiotSession = require('./src/session');
const scenario = require('./src/scenario'); const scenario = require('./src/scenario');
const RestSessionCreator = require('./src/rest/creator'); const RestSessionCreator = require('./src/rest/creator');
@ -35,7 +34,7 @@ program
const hsUrl = 'http://localhost:5005'; const hsUrl = 'http://localhost:5005';
async function runTests() { async function runTests() {
let sessions = []; const sessions = [];
const options = { const options = {
slowMo: program.slowMo ? 20 : undefined, slowMo: program.slowMo ? 20 : undefined,
devtools: program.devTools, devtools: program.devTools,
@ -54,7 +53,7 @@ async function runTests() {
const restCreator = new RestSessionCreator( const restCreator = new RestSessionCreator(
'synapse/installations/consent/env/bin', 'synapse/installations/consent/env/bin',
hsUrl, hsUrl,
__dirname __dirname,
); );
async function createSession(username) { async function createSession(username) {
@ -66,7 +65,7 @@ async function runTests() {
let failure = false; let failure = false;
try { try {
await scenario(createSession, restCreator); await scenario(createSession, restCreator);
} catch(err) { } catch (err) {
failure = true; failure = true;
console.log('failure: ', err); console.log('failure: ', err);
if (program.logDirectory) { if (program.logDirectory) {
@ -90,15 +89,15 @@ async function runTests() {
} }
async function writeLogs(sessions, dir) { async function writeLogs(sessions, dir) {
let logs = ""; const logs = "";
for(let i = 0; i < sessions.length; ++i) { for (let i = 0; i < sessions.length; ++i) {
const session = sessions[i]; const session = sessions[i];
const userLogDir = `${dir}/${session.username}`; const userLogDir = `${dir}/${session.username}`;
fs.mkdirSync(userLogDir); fs.mkdirSync(userLogDir);
const consoleLogName = `${userLogDir}/console.log`; const consoleLogName = `${userLogDir}/console.log`;
const networkLogName = `${userLogDir}/network.log`; const networkLogName = `${userLogDir}/network.log`;
const appHtmlName = `${userLogDir}/app.html`; const appHtmlName = `${userLogDir}/app.html`;
documentHtml = await session.page.content(); const documentHtml = await session.page.content();
fs.writeFileSync(appHtmlName, documentHtml); fs.writeFileSync(appHtmlName, documentHtml);
fs.writeFileSync(networkLogName, session.networkLogs()); fs.writeFileSync(networkLogName, session.networkLogs());
fs.writeFileSync(consoleLogName, session.consoleLogs()); fs.writeFileSync(consoleLogName, session.consoleLogs());