From aaa5ee1a25b7d698214a55df594c1aad50ce6294 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 7 Aug 2018 18:21:53 +0200 Subject: [PATCH] more consistent naming on session methods --- src/session.js | 21 ++++++++++++--------- src/tests/consent.js | 2 +- src/tests/create-room.js | 8 ++++---- src/tests/join.js | 8 ++++---- src/tests/room-settings.js | 21 +++++++++++++++++++++ src/tests/server-notices-consent.js | 4 ++-- src/tests/signup.js | 16 ++++++++-------- 7 files changed, 52 insertions(+), 28 deletions(-) create mode 100644 src/tests/room-settings.js diff --git a/src/session.js b/src/session.js index 5b0f78ccd3..d82c90d4d9 100644 --- a/src/session.js +++ b/src/session.js @@ -129,15 +129,22 @@ module.exports = class RiotSession { await input.type(text); } - // TODO: rename to waitAndQuery(Single)? - async waitAndQuerySelector(selector, timeout = 500) { + query(selector) { + return this.page.$(selector); + } + + async waitAndQuery(selector, timeout = 500) { 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) { await this.page.waitForSelector(selector, {visible: true, timeout}); - return await this.page.$$(selector); + return await this.queryAll(selector); } waitForNewPage(timeout = 500) { @@ -157,15 +164,11 @@ module.exports = class RiotSession { }); } - waitForSelector(selector) { - return this.page.waitForSelector(selector); - } - goto(url) { return this.page.goto(url); } - riotUrl(path) { + url(path) { return this.riotserver + path; } diff --git a/src/tests/consent.js b/src/tests/consent.js index 09026a3082..cd3d51c1b6 100644 --- a/src/tests/consent.js +++ b/src/tests/consent.js @@ -17,7 +17,7 @@ limitations under the License. const assert = require('assert'); 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(); await reviewTermsButton.click(); const termsPage = await termsPagePromise; diff --git a/src/tests/create-room.js b/src/tests/create-room.js index eff92baf83..8f5b5c9e85 100644 --- a/src/tests/create-room.js +++ b/src/tests/create-room.js @@ -19,15 +19,15 @@ 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"]'); + const createRoomButton = await session.waitAndQuery('.mx_RoleButton[aria-label="Create new room"]'); await createRoomButton.click(); - const roomNameInput = await session.waitAndQuerySelector('.mx_CreateRoomDialog_input'); + const roomNameInput = await session.waitAndQuery('.mx_CreateRoomDialog_input'); 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 session.waitForSelector('.mx_MessageComposer'); + await session.waitAndQuery('.mx_MessageComposer'); session.log.done(); } \ No newline at end of file diff --git a/src/tests/join.js b/src/tests/join.js index 72d4fe10cf..0577b7a8b6 100644 --- a/src/tests/join.js +++ b/src/tests/join.js @@ -19,16 +19,16 @@ 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"]'); + const directoryButton = await session.waitAndQuery('.mx_RoleButton[aria-label="Room directory"]'); await directoryButton.click(); - const roomInput = await session.waitAndQuerySelector('.mx_DirectorySearchBox_input'); + const roomInput = await session.waitAndQuery('.mx_DirectorySearchBox_input'); 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(); - const joinLink = await session.waitAndQuerySelector('.mx_RoomPreviewBar_join_text a'); + const joinLink = await session.waitAndQuery('.mx_RoomPreviewBar_join_text a'); await joinLink.click(); await session.waitForSelector('.mx_MessageComposer'); diff --git a/src/tests/room-settings.js b/src/tests/room-settings.js new file mode 100644 index 0000000000..70d84de10f --- /dev/null +++ b/src/tests/room-settings.js @@ -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 +} \ No newline at end of file diff --git a/src/tests/server-notices-consent.js b/src/tests/server-notices-consent.js index 53a318a169..d52588f962 100644 --- a/src/tests/server-notices-consent.js +++ b/src/tests/server-notices-consent.js @@ -30,10 +30,10 @@ module.exports = async function acceptServerNoticesInviteAndConsent(session, not 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(); - const consentLink = await session.waitAndQuerySelector(".mx_EventTile_body a", 1000); + const consentLink = await session.waitAndQuery(".mx_EventTile_body a", 1000); const termsPagePromise = session.waitForNewPage(); await consentLink.click(); diff --git a/src/tests/signup.js b/src/tests/signup.js index 6b3f06c12c..434083cbb6 100644 --- a/src/tests/signup.js +++ b/src/tests/signup.js @@ -19,16 +19,16 @@ const assert = require('assert'); module.exports = async function signup(session, username, password, homeserver) { session.log.step("signs up"); - await session.goto(session.riotUrl('/#/register')); + await session.goto(session.url('/#/register')); //click 'Custom server' radio button if (homeserver) { - const advancedRadioButton = await session.waitAndQuerySelector('#advanced'); + const advancedRadioButton = await session.waitAndQuery('#advanced'); await advancedRadioButton.click(); } // 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 - const loginFields = await session.page.$$('.mx_Login_field'); + const loginFields = await session.queryAll('.mx_Login_field'); assert.strictEqual(loginFields.length, 7); const usernameField = loginFields[2]; 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(passwordRepeatField, password); if (homeserver) { - await session.waitForSelector('.mx_ServerConfig', {visible: true, timeout: 500}); + await session.waitAndQuery('.mx_ServerConfig'); await session.replaceInputText(hsurlField, homeserver); } //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); /// focus on the button to make sure error validation /// 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(); //check no errors 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(); //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(); //wait for registration to finish so the hash gets set //onhashchange better? await session.delay(2000); const url = session.page.url(); - assert.strictEqual(url, session.riotUrl('/#/home')); + assert.strictEqual(url, session.url('/#/home')); session.log.done(); }