more consistent naming on session methods
This commit is contained in:
parent
4e7df2126b
commit
aaa5ee1a25
7 changed files with 52 additions and 28 deletions
|
@ -129,15 +129,22 @@ module.exports = class RiotSession {
|
||||||
await input.type(text);
|
await input.type(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: rename to waitAndQuery(Single)?
|
query(selector) {
|
||||||
async waitAndQuerySelector(selector, timeout = 500) {
|
return this.page.$(selector);
|
||||||
|
}
|
||||||
|
|
||||||
|
async waitAndQuery(selector, timeout = 500) {
|
||||||
await this.page.waitForSelector(selector, {visible: true, timeout});
|
await this.page.waitForSelector(selector, {visible: true, timeout});
|
||||||
return await this.page.$(selector);
|
return await this.query(selector);
|
||||||
|
}
|
||||||
|
|
||||||
|
queryAll(selector) {
|
||||||
|
return this.page.$$(selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
async waitAndQueryAll(selector, timeout = 500) {
|
async waitAndQueryAll(selector, timeout = 500) {
|
||||||
await this.page.waitForSelector(selector, {visible: true, timeout});
|
await this.page.waitForSelector(selector, {visible: true, timeout});
|
||||||
return await this.page.$$(selector);
|
return await this.queryAll(selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
waitForNewPage(timeout = 500) {
|
waitForNewPage(timeout = 500) {
|
||||||
|
@ -157,15 +164,11 @@ module.exports = class RiotSession {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
waitForSelector(selector) {
|
|
||||||
return this.page.waitForSelector(selector);
|
|
||||||
}
|
|
||||||
|
|
||||||
goto(url) {
|
goto(url) {
|
||||||
return this.page.goto(url);
|
return this.page.goto(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
riotUrl(path) {
|
url(path) {
|
||||||
return this.riotserver + path;
|
return this.riotserver + path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
module.exports = async function acceptTerms(session) {
|
module.exports = async function acceptTerms(session) {
|
||||||
const reviewTermsButton = await session.waitAndQuerySelector('.mx_QuestionDialog button.mx_Dialog_primary', 5000);
|
const reviewTermsButton = await session.waitAndQuery('.mx_QuestionDialog button.mx_Dialog_primary', 5000);
|
||||||
const termsPagePromise = session.waitForNewPage();
|
const termsPagePromise = session.waitForNewPage();
|
||||||
await reviewTermsButton.click();
|
await reviewTermsButton.click();
|
||||||
const termsPage = await termsPagePromise;
|
const termsPage = await termsPagePromise;
|
||||||
|
|
|
@ -19,15 +19,15 @@ const assert = require('assert');
|
||||||
module.exports = async function createRoom(session, roomName) {
|
module.exports = async function createRoom(session, roomName) {
|
||||||
session.log.step(`creates room ${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.waitAndQuery('.mx_RoleButton[aria-label="Create new room"]');
|
||||||
await createRoomButton.click();
|
await createRoomButton.click();
|
||||||
|
|
||||||
const roomNameInput = await session.waitAndQuerySelector('.mx_CreateRoomDialog_input');
|
const roomNameInput = await session.waitAndQuery('.mx_CreateRoomDialog_input');
|
||||||
await session.replaceInputText(roomNameInput, roomName);
|
await session.replaceInputText(roomNameInput, roomName);
|
||||||
|
|
||||||
const createButton = await session.waitAndQuerySelector('.mx_Dialog_primary');
|
const createButton = await session.waitAndQuery('.mx_Dialog_primary');
|
||||||
await createButton.click();
|
await createButton.click();
|
||||||
|
|
||||||
await session.waitForSelector('.mx_MessageComposer');
|
await session.waitAndQuery('.mx_MessageComposer');
|
||||||
session.log.done();
|
session.log.done();
|
||||||
}
|
}
|
|
@ -19,16 +19,16 @@ const assert = require('assert');
|
||||||
module.exports = async function join(session, roomName) {
|
module.exports = async function join(session, roomName) {
|
||||||
session.log.step(`joins room ${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.waitAndQuery('.mx_RoleButton[aria-label="Room directory"]');
|
||||||
await directoryButton.click();
|
await directoryButton.click();
|
||||||
|
|
||||||
const roomInput = await session.waitAndQuerySelector('.mx_DirectorySearchBox_input');
|
const roomInput = await session.waitAndQuery('.mx_DirectorySearchBox_input');
|
||||||
await session.replaceInputText(roomInput, roomName);
|
await session.replaceInputText(roomInput, roomName);
|
||||||
|
|
||||||
const firstRoomLabel = await session.waitAndQuerySelector('.mx_RoomDirectory_table .mx_RoomDirectory_name:first-child');
|
const firstRoomLabel = await session.waitAndQuery('.mx_RoomDirectory_table .mx_RoomDirectory_name:first-child');
|
||||||
await firstRoomLabel.click();
|
await firstRoomLabel.click();
|
||||||
|
|
||||||
const joinLink = await session.waitAndQuerySelector('.mx_RoomPreviewBar_join_text a');
|
const joinLink = await session.waitAndQuery('.mx_RoomPreviewBar_join_text a');
|
||||||
await joinLink.click();
|
await joinLink.click();
|
||||||
|
|
||||||
await session.waitForSelector('.mx_MessageComposer');
|
await session.waitForSelector('.mx_MessageComposer');
|
||||||
|
|
21
src/tests/room-settings.js
Normal file
21
src/tests/room-settings.js
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
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 assert = require('assert');
|
||||||
|
|
||||||
|
module.exports = async function changeRoomSettings(session, settings) {
|
||||||
|
session.waitFor
|
||||||
|
}
|
|
@ -30,10 +30,10 @@ module.exports = async function acceptServerNoticesInviteAndConsent(session, not
|
||||||
|
|
||||||
await inviteHandle.click();
|
await inviteHandle.click();
|
||||||
|
|
||||||
const acceptInvitationLink = await session.waitAndQuerySelector(".mx_RoomPreviewBar_join_text a:first-child");
|
const acceptInvitationLink = await session.waitAndQuery(".mx_RoomPreviewBar_join_text a:first-child");
|
||||||
await acceptInvitationLink.click();
|
await acceptInvitationLink.click();
|
||||||
|
|
||||||
const consentLink = await session.waitAndQuerySelector(".mx_EventTile_body a", 1000);
|
const consentLink = await session.waitAndQuery(".mx_EventTile_body a", 1000);
|
||||||
|
|
||||||
const termsPagePromise = session.waitForNewPage();
|
const termsPagePromise = session.waitForNewPage();
|
||||||
await consentLink.click();
|
await consentLink.click();
|
||||||
|
|
|
@ -19,16 +19,16 @@ 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");
|
session.log.step("signs up");
|
||||||
await session.goto(session.riotUrl('/#/register'));
|
await session.goto(session.url('/#/register'));
|
||||||
//click 'Custom server' radio button
|
//click 'Custom server' radio button
|
||||||
if (homeserver) {
|
if (homeserver) {
|
||||||
const advancedRadioButton = await session.waitAndQuerySelector('#advanced');
|
const advancedRadioButton = await session.waitAndQuery('#advanced');
|
||||||
await advancedRadioButton.click();
|
await advancedRadioButton.click();
|
||||||
}
|
}
|
||||||
// wait until register button is visible
|
// wait until register button is visible
|
||||||
await session.waitForSelector('.mx_Login_submit[value=Register]', {visible: true, timeout: 500});
|
await session.waitAndQuery('.mx_Login_submit[value=Register]');
|
||||||
//fill out form
|
//fill out form
|
||||||
const loginFields = await session.page.$$('.mx_Login_field');
|
const loginFields = await session.queryAll('.mx_Login_field');
|
||||||
assert.strictEqual(loginFields.length, 7);
|
assert.strictEqual(loginFields.length, 7);
|
||||||
const usernameField = loginFields[2];
|
const usernameField = loginFields[2];
|
||||||
const passwordField = loginFields[3];
|
const passwordField = loginFields[3];
|
||||||
|
@ -38,7 +38,7 @@ module.exports = async function signup(session, username, password, homeserver)
|
||||||
await session.replaceInputText(passwordField, password);
|
await session.replaceInputText(passwordField, password);
|
||||||
await session.replaceInputText(passwordRepeatField, password);
|
await session.replaceInputText(passwordRepeatField, password);
|
||||||
if (homeserver) {
|
if (homeserver) {
|
||||||
await session.waitForSelector('.mx_ServerConfig', {visible: true, timeout: 500});
|
await session.waitAndQuery('.mx_ServerConfig');
|
||||||
await session.replaceInputText(hsurlField, homeserver);
|
await session.replaceInputText(hsurlField, homeserver);
|
||||||
}
|
}
|
||||||
//wait over a second because Registration/ServerConfig have a 1000ms
|
//wait over a second because Registration/ServerConfig have a 1000ms
|
||||||
|
@ -47,7 +47,7 @@ module.exports = async function signup(session, username, password, homeserver)
|
||||||
await session.delay(1200);
|
await session.delay(1200);
|
||||||
/// focus on the button to make sure error validation
|
/// focus on the button to make sure error validation
|
||||||
/// has happened before checking the form is good to go
|
/// has happened before checking the form is good to go
|
||||||
const registerButton = await session.page.$('.mx_Login_submit');
|
const registerButton = await session.query('.mx_Login_submit');
|
||||||
await registerButton.focus();
|
await registerButton.focus();
|
||||||
//check no errors
|
//check no errors
|
||||||
const error_text = await session.tryGetInnertext('.mx_Login_error');
|
const error_text = await session.tryGetInnertext('.mx_Login_error');
|
||||||
|
@ -57,13 +57,13 @@ module.exports = async function signup(session, username, password, homeserver)
|
||||||
await registerButton.click();
|
await registerButton.click();
|
||||||
|
|
||||||
//confirm dialog saying you cant log back in without e-mail
|
//confirm dialog saying you cant log back in without e-mail
|
||||||
const continueButton = await session.waitAndQuerySelector('.mx_QuestionDialog button.mx_Dialog_primary');
|
const continueButton = await session.waitAndQuery('.mx_QuestionDialog button.mx_Dialog_primary');
|
||||||
await continueButton.click();
|
await continueButton.click();
|
||||||
//wait for registration to finish so the hash gets set
|
//wait for registration to finish so the hash gets set
|
||||||
//onhashchange better?
|
//onhashchange better?
|
||||||
await session.delay(2000);
|
await session.delay(2000);
|
||||||
|
|
||||||
const url = session.page.url();
|
const url = session.page.url();
|
||||||
assert.strictEqual(url, session.riotUrl('/#/home'));
|
assert.strictEqual(url, session.url('/#/home'));
|
||||||
session.log.done();
|
session.log.done();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue