diff --git a/test/e2e/page_objects/admin.js b/test/e2e/page_objects/admin.js index e83e7b7df..36baaa3cb 100644 --- a/test/e2e/page_objects/admin.js +++ b/test/e2e/page_objects/admin.js @@ -7,19 +7,14 @@ module.exports = { return this .waitForElementVisible('body'); }, - login(user = {}) { + login(user) { this - .navigate() .waitForElementVisible('@loginLayout') .waitForElementVisible('@signInForm') .setValue('@emailInput', user.email) .setValue('@passwordInput', user.password) .waitForElementVisible('@signInButton') - .click('@signInButton'); - - this.api.pause(3000); - - this + .click('@signInButton') .waitForElementVisible('@moderationContainer'); }, }], diff --git a/test/e2e/page_objects/embedStream.js b/test/e2e/page_objects/embedStream.js index e31d5d72e..5b649fecb 100644 --- a/test/e2e/page_objects/embedStream.js +++ b/test/e2e/page_objects/embedStream.js @@ -3,11 +3,28 @@ const SortedWindowHandler = require('../utils/SortedWindowHandler'); module.exports = { commands: [{ - navigateToAsset(asset) { + ready: function() { + this.switchToIframe(); + this.expect.section('@comments').to.be.present; + return this.section.comments; + }, + goToProfileSection: function() { + this.waitForElementVisible('@profileTabButton'); + this.click('@profileTabButton'); + this.expect.section('@profile').to.be.present; + return this.section.profile; + }, + goToCommentsSection: function() { + this.waitForElementVisible('@commentsTabButton'); + this.click('@commentsTabButton'); + this.expect.section('@comments').to.be.present; + return this.section.comments; + }, + navigateToAsset: function(asset) { this.api.url(`${this.api.launchUrl}/assets/title/${asset}`); return this; }, - getEmbedSection() { + switchToIframe: function() { this.waitForElementVisible('@iframe'); // Pause a bit to let iframe initialize in the hope that it'll @@ -15,98 +32,66 @@ module.exports = { this.api.pause(200); this.api.frame(iframeId); - this.expect.section('@embed').to.be.present; - return this.section.embed; + return this; }, - login(user = {}) { - const embed = this - .navigate() - .getEmbedSection(); - - const windowHandler = new SortedWindowHandler(this); - - embed - .waitForElementVisible('@signInButton') - .click('@signInButton'); - - // Wait for window to be created - // https://www.browserstack.com/automate/builds/1ceccf4efb4683b7feb890f45a32b5922b40ed3f/sessions/17b1a79682bef2498cb0be86eac317a08c976b0a#automate_button - this.api.pause(200); - - // Focusing on the Login PopUp - windowHandler.windowHandles((handles) => { - this.api.switchWindow(handles[1]); - }); - - const login = this.api.page.login(); - - login - .waitForElementVisible('@registerButton') - .click('@registerButton') - .setValue('@emailInput', user.email) - .setValue('@usernameInput', user.username) - .setValue('@passwordInput', user.password) - .setValue('@confirmPasswordInput', user.password) - .waitForElementVisible('@signUpButton') - .click('@signUpButton') - .waitForElementVisible('@signIn') - .waitForElementVisible('@loginButton') - .click('@loginButton'); - - // Give a tiny bit of time to let popup close. - this.api.pause(50); - - if (this.api.capabilities.browserName === 'MicrosoftEdge') { - - // More time for edge. - // https://www.browserstack.com/automate/builds/1ceccf4efb4683b7feb890f45a32b5922b40ed3f/sessions/7393dbfda8387e43b6d5851f359b0c07db414973 - this.api.pause(1000); - } - - // Focusing on the Embed Window - windowHandler.windowHandles((handles) => { - this.api.switchWindow(handles[0]); - }); - }, - logout() { - const embed = this - .navigate() - .getEmbedSection(); - - embed - .waitForElementVisible('@commentsTabButton') - .click('@commentsTabButton') - .waitForElementVisible('@logoutButton') - .click('@logoutButton'); - } }], url: function() { return this.api.launchUrl; }, elements: { iframe: `#${iframeId}`, + commentsTabButton: '.talk-embed-stream-comments-tab > button', + profileTabButton: '.talk-embed-stream-profile-tab > button', + banDialog: '.talk-ban-user-dialog', + banDialogConfirmButton: '.talk-ban-user-dialog-button-confirm', }, sections: { - embed: { + comments: { commands: [{ - getProfileSection() { - this.waitForElementVisible('@profileTabButton'); - this.click('@profileTabButton'); - this.expect.section('@profile').to.be.present; - return this.section.profile; + openLoginPopup(callback) { + const windowHandler = new SortedWindowHandler(this.api); + + this + .waitForElementVisible('@signInButton') + .click('@signInButton'); + + // Wait for window to be created + // https://www.browserstack.com/automate/builds/1ceccf4efb4683b7feb890f45a32b5922b40ed3f/sessions/17b1a79682bef2498cb0be86eac317a08c976b0a#automate_button + this.api.pause(200); + + // Focusing on the Login PopUp + windowHandler.windowHandles((handles) => { + this.api.switchWindow(handles[1]); + }); + + const login = this.api.page.login().ready(); + callback(login); + + // Give a tiny bit of time to let popup close. + this.api.pause(50); + + if (this.api.capabilities.browserName === 'MicrosoftEdge') { + + // More time for edge. + // https://www.browserstack.com/automate/builds/1ceccf4efb4683b7feb890f45a32b5922b40ed3f/sessions/7393dbfda8387e43b6d5851f359b0c07db414973 + this.api.pause(1000); + } + + // Focusing on the Embed Window + windowHandler.windowHandles((handles) => { + this.api.switchWindow(handles[0]); + this.api.page.embedStream().switchToIframe(); + }); }, - getCommentsSection() { - this.waitForElementVisible('@commentsTabButton'); - this.click('@commentsTabButton'); - this.expect.section('@comments').to.be.present; - return this.section.comments; + logout() { + this + .waitForElementVisible('@logoutButton') + .click('@logoutButton'); }, }], - selector: '#talk-embed-stream-container', + selector: '.talk-embed-stream-comments-tab-pane', elements: { logoutButton: '.talk-stream-userbox-logout', - commentsTabButton: '.talk-embed-stream-comments-tab > button', - profileTabButton: '.talk-embed-stream-profile-tab > button', signInButton: '#coralSignInButton', commentBoxTextarea: '#commentText', commentBoxPostButton: '.talk-plugin-commentbox-button', @@ -117,8 +102,6 @@ module.exports = { restrictedMessageBox: '.talk-restricted-message-box', suspendedAccountInput: '.talk-suspended-account-username-input', suspendedAccountSubmitButton: '.talk-suspended-account-submit-button', - banDialog: '.talk-ban-user-dialog', - banDialogConfirmButton: '.talk-ban-user-dialog-button-confirm', }, sections: { flag: { @@ -138,20 +121,16 @@ module.exports = { banButton: '.talk-plugin-moderation-actions-ban', }, }, - profile: { - selector: '.talk-embed-stream-profile-tab-pane', - elements: { - notLoggedIn: '.talk-embed-stream-not-logged-in', - myCommentHistory: '.talk-my-profile-comment-history', - myCommentHistoryReactions: '.talk-my-profile-comment-history .comment-summary .comment-summary-reactions', - myCommentHistoryReactionCount: '.talk-my-profile-comment-history .comment-summary .comment-summary-reactions .comment-summary-reaction-count', - myCommentHistoryComment: '.talk-my-profile-comment-history .my-comment-body', - }, - }, - comments: { - selector: '.talk-embed-stream-comments-tab-pane', - elements: {}, - }, + }, + }, + profile: { + selector: '.talk-embed-stream-profile-tab-pane', + elements: { + notLoggedIn: '.talk-embed-stream-not-logged-in', + myCommentHistory: '.talk-my-profile-comment-history', + myCommentHistoryReactions: '.talk-my-profile-comment-history .comment-summary .comment-summary-reactions', + myCommentHistoryReactionCount: '.talk-my-profile-comment-history .comment-summary .comment-summary-reactions .comment-summary-reaction-count', + myCommentHistoryComment: '.talk-my-profile-comment-history .my-comment-body', }, }, }, diff --git a/test/e2e/page_objects/login.js b/test/e2e/page_objects/login.js index 1abc40aa8..89b071e9a 100644 --- a/test/e2e/page_objects/login.js +++ b/test/e2e/page_objects/login.js @@ -1,4 +1,32 @@ module.exports = { + commands: [{ + ready() { + return this + .waitForElementVisible('body'); + }, + login(user) { + this + .setValue('@emailInput', user.email) + .setValue('@passwordInput', user.password) + .waitForElementVisible('@signIn') + .waitForElementVisible('@loginButton') + .click('@loginButton'); + }, + register(user) { + this + .waitForElementVisible('@registerButton') + .click('@registerButton') + .setValue('@emailInput', user.email) + .setValue('@usernameInput', user.username) + .setValue('@passwordInput', user.password) + .setValue('@confirmPasswordInput', user.password) + .waitForElementVisible('@signUpButton') + .click('@signUpButton') + .waitForElementVisible('@signIn') + .waitForElementVisible('@loginButton') + .click('@loginButton'); + }, + }], elements: { registerButton: '#coralRegister', signInButton: '#coralSignInButton', diff --git a/test/e2e/specs/02_admin.js b/test/e2e/specs/02_admin.js index 1f56ef2b8..4973f24ab 100644 --- a/test/e2e/specs/02_admin.js +++ b/test/e2e/specs/02_admin.js @@ -10,22 +10,14 @@ module.exports = { adminPage .navigate() - .waitForElementVisible('@loginLayout') - .waitForElementVisible('@signInForm') - .setValue('@emailInput', admin.email) - .setValue('@passwordInput', admin.password) - .waitForElementVisible('@signInButton') - .click('@signInButton'); - - adminPage - .waitForElementVisible('@moderationContainer'); + .ready() + .login(admin); }, 'Admin goes to Stories': (client) => { const adminPage = client.page.admin(); adminPage - .navigate() .waitForElementVisible('@drawerButton') .click('@drawerButton') .waitForElementVisible('@storiesDrawerNav') @@ -40,7 +32,6 @@ module.exports = { const adminPage = client.page.admin(); adminPage - .navigate() .waitForElementVisible('@drawerButton') .click('@drawerButton') .waitForElementVisible('@communityDrawerNav') diff --git a/test/e2e/specs/03_embedStream.js b/test/e2e/specs/03_embedStream.js index a12b9820f..f4c1b94b6 100644 --- a/test/e2e/specs/03_embedStream.js +++ b/test/e2e/specs/03_embedStream.js @@ -7,46 +7,43 @@ module.exports = { embedStream .navigateToAsset(asset) .assert.title(asset) - .getEmbedSection(); + .ready(); }, 'creates an user and user logs in': (client) => { const {testData: {user}} = client.globals; const embedStream = client.page.embedStream(); - embedStream - .login(user); + // Go back to default asset. + const comments = + embedStream + .navigate() + .ready(); + + comments + .openLoginPopup((login) => { + login.register(user); + }); }, 'user posts a comment': (client) => { - const embedStream = client.page.embedStream(); + const comments = client.page.embedStream().section.comments; const {testData: {comment}} = client.globals; - const embed = embedStream - .navigate() - .getEmbedSection(); - - embed + comments .waitForElementVisible('@commentBoxTextarea') .setValue('@commentBoxTextarea', comment.body) .waitForElementVisible('@commentBoxPostButton') .click('@commentBoxPostButton') .waitForElementVisible('@firstCommentContent') .getText('@firstCommentContent', (result) => { - embed.assert.equal(result.value, comment.body); + comments.assert.equal(result.value, comment.body); }); }, 'signed in user sees comment history': (client) => { - const embedStream = client.page.embedStream(); + const profile = client.page.embedStream().goToProfileSection(); const {testData: {comment}} = client.globals; - const embed = embedStream - .navigate() - .getEmbedSection(); - - const profile = embed - .getProfileSection(); - profile .waitForElementVisible('@myCommentHistory') .waitForElementVisible('@myCommentHistoryComment') @@ -55,14 +52,7 @@ module.exports = { }); }, 'user sees replies and reactions to comments': (client) => { - const embedStream = client.page.embedStream(); - - const embed = embedStream - .navigate() - .getEmbedSection(); - - const profile = embed - .getProfileSection(); + const profile = client.page.embedStream().section.profile; profile .waitForElementVisible('@myCommentHistory') @@ -74,17 +64,12 @@ module.exports = { }, 'user goes to the stream and replies and reacts to comment': (client) => { const embedStream = client.page.embedStream(); - - const embed = embedStream - .navigate() - .getEmbedSection(); - - embed + const comments = embedStream.goToCommentsSection(); + comments .waitForElementVisible('@respectButton') .click('@respectButton'); - const profile = embed - .getProfileSection(); + const profile = embedStream.goToProfileSection(); profile .waitForElementVisible('@myCommentHistory') @@ -96,26 +81,14 @@ module.exports = { }, 'user logs out': (client) => { const embedStream = client.page.embedStream(); + const comments = embedStream.goToCommentsSection(); - const embed = embedStream - .navigate() - .getEmbedSection(); - - embed - .waitForElementVisible('@commentsTabButton') - .click('@commentsTabButton') - .waitForElementVisible('@logoutButton') - .click('@logoutButton'); + comments + .logout(); }, 'not logged in user clicks my profile tab': (client) => { const embedStream = client.page.embedStream(); - - const embed = embedStream - .navigate() - .getEmbedSection(); - - const profile = embed - .getProfileSection(); + const profile = embedStream.goToProfileSection(); profile .assert.visible('@notLoggedIn'); diff --git a/test/e2e/specs/04_userStatus.js b/test/e2e/specs/04_userStatus.js index 46a87a2d1..eeb7be6fd 100644 --- a/test/e2e/specs/04_userStatus.js +++ b/test/e2e/specs/04_userStatus.js @@ -5,32 +5,22 @@ module.exports = { adminPage .navigate() - .waitForElementVisible('@loginLayout') - .waitForElementVisible('@signInForm') - .setValue('@emailInput', admin.email) - .setValue('@passwordInput', admin.password) - .waitForElementVisible('@signInButton') - .click('@signInButton'); - - client.pause(3000); - - adminPage - .waitForElementVisible('@moderationContainer'); + .ready() + .login(admin); }, 'admin flags user\'s username as offensive': (client) => { const embedStream = client.page.embedStream(); - const flagSection = client.page.embedStream().section.embed.section.flag; - const embed = embedStream + const comments = embedStream .navigate() - .getEmbedSection(); + .ready(); - embed + comments .waitForElementVisible('@firstComment') .waitForElementVisible('@flagButton') .click('@flagButton'); - flagSection + comments.section.flag .waitForElementVisible('@flagUsernameRadio') .click('@flagUsernameRadio') .waitForElementVisible('@continueButton') @@ -54,14 +44,14 @@ module.exports = { }, 'admin rejects the user flag': (client) => { const community = client.page.adminCommunity(); - + community .waitForElementVisible('@flaggedUserRejectButton') .click('@flaggedUserRejectButton'); }, 'admin suspends the user': (client) => { const community = client.page.adminCommunity(); - + community .waitForElementVisible('@usernameDialog') .waitForElementVisible('@usernameDialogButtons') @@ -84,56 +74,24 @@ module.exports = { const {testData: {user}} = client.globals; const embedStream = client.page.embedStream(); - const embed = embedStream + embedStream .navigate() - .getEmbedSection(); - - embed - .waitForElementVisible('@signInButton') - .click('@signInButton'); - - client.pause(3000); - - // Focusing on the Login PopUp - client.windowHandles((result) => { - const handle = result.value[1]; - client.switchWindow(handle); - }); - - const login = client.page.login(); - - login - .setValue('@emailInput', user.email) - .setValue('@passwordInput', user.password) - .waitForElementVisible('@signIn') - .waitForElementVisible('@loginButton') - .click('@loginButton'); - - // Focusing on the Embed Window - client.windowHandles((result) => { - const handle = result.value[0]; - client.switchWindow(handle); - }); + .ready() + .openLoginPopup((popup) => popup.login(user)); }, 'user account is suspended, should see restricted message box': (client) => { const embedStream = client.page.embedStream(); + const comments = embedStream.section.comments; - const embed = embedStream - .navigate() - .getEmbedSection(); - - embed + comments .waitForElementVisible('@restrictedMessageBox'); }, 'user picks another username': (client) => { - const {testData: {user}} = client.globals; const embedStream = client.page.embedStream(); - - const embed = embedStream - .navigate() - .getEmbedSection(); + const comments = embedStream.section.comments; + const {testData: {user}} = client.globals; - embed + comments .waitForElementVisible('@suspendedAccountInput') .setValue('@suspendedAccountInput', `${user.username}-alternative`) .waitForElementVisible('@suspendedAccountSubmitButton') @@ -141,16 +99,13 @@ module.exports = { }, 'user should not be able to comment': (client) => { const embedStream = client.page.embedStream(); - - const embed = embedStream - .navigate() - .getEmbedSection(); + const comments = embedStream.section.comments; - embed + comments .waitForElementNotPresent('@commentBoxTextarea') .waitForElementNotPresent('@commentBoxPostButton'); }, after: (client) => { - client.end(); + client.end(); } }; diff --git a/test/e2e/specs/05_banUser.js b/test/e2e/specs/05_banUser.js index 8e5e33cd0..9d20a5305 100644 --- a/test/e2e/specs/05_banUser.js +++ b/test/e2e/specs/05_banUser.js @@ -4,6 +4,8 @@ module.exports = { const {testData: {admin}} = client.globals; adminPage + .navigate() + .ready() .login(admin); }, 'navigate to the embed stream': (client) => { @@ -11,52 +13,50 @@ module.exports = { embedStream .navigate() - .getEmbedSection(); + .ready(); }, 'admin bans user': (client) => { - const embed = client.page.embedStream().section.embed; - const modSection = client.page.embedStream().section.embed.section.mod; + const embedStream = client.page.embedStream(); + const comments = embedStream.section.comments; - modSection + comments.section.mod .waitForElementVisible('@arrow') .click('@arrow') .waitForElementVisible('@menu') .waitForElementVisible('@banButton') .click('@banButton'); - embed + embedStream .waitForElementVisible('@banDialog') .waitForElementVisible('@banDialogConfirmButton') .click('@banDialogConfirmButton') .waitForElementNotVisible('@banDialog'); }, 'admin logs out': (client) => { - const embedStream = client.page.embedStream(); + const comments = client.page.embedStream().section.comments; - embedStream + comments .logout(); }, 'user logs in': (client) => { const {testData: {user}} = client.globals; - const embedStream = client.page.embedStream(); + const comments = client.page.embedStream().section.comments; - embedStream - .login(user); + comments + .openLoginPopup((popup) => popup.login(user)); }, 'user account is banned, should see restricted message box': (client) => { const embedStream = client.page.embedStream(); + const comments = embedStream.section.comments; - const embed = embedStream - .navigate() - .getEmbedSection(); - - embed + comments .waitForElementVisible('@restrictedMessageBox'); }, 'user logs out': (client) => { const embedStream = client.page.embedStream(); + const comments = embedStream.section.comments; - embedStream + comments .logout(); }, 'admin logs in (2)': (client) => { @@ -64,11 +64,13 @@ module.exports = { const {testData: {admin}} = client.globals; adminPage + .navigate() + .ready() .login(admin); }, 'admin goes to community': (client) => { const community = client.page.adminCommunity(); - + community .goToPeople(); },