From 7a4b87f7438665f0e88ece6e04a414c640527ea6 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 19 Dec 2017 14:42:54 +0100 Subject: [PATCH] Fix popup issues --- test/e2e/page_objects/embedStream.js | 21 +++++------------- test/e2e/utils/SortedWindowHandler.js | 32 +++++++++++---------------- 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/test/e2e/page_objects/embedStream.js b/test/e2e/page_objects/embedStream.js index 1cecad2a3..0a31745e4 100644 --- a/test/e2e/page_objects/embedStream.js +++ b/test/e2e/page_objects/embedStream.js @@ -62,24 +62,12 @@ module.exports = { // Focusing on the Login PopUp windowHandler.windowHandles((handles) => { this.api.switchWindow(handles[1]); - }); - const popup = this.api.page.popup().ready(); - callback(popup); + const popup = this.api.page.popup().ready(); + callback(popup); - // 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]); + // Focus on the Embed Window. + windowHandler.pop(); // For some reasons firefox does not automatically load auth after login. // https://www.browserstack.com/automate/builds/37650cb4e66c6edce0ba0800a1c1b7e7f74bf991/sessions/7a4e9da69b0f9ecdf8b7fa9150639e47b1532cb0#automate_button @@ -89,6 +77,7 @@ module.exports = { this.parent.switchToIframe(); } }); + return this; }, logout() { diff --git a/test/e2e/utils/SortedWindowHandler.js b/test/e2e/utils/SortedWindowHandler.js index cb8195978..a23f71506 100644 --- a/test/e2e/utils/SortedWindowHandler.js +++ b/test/e2e/utils/SortedWindowHandler.js @@ -25,28 +25,14 @@ class SortedWindowHandler { */ windowHandles(callback) { this.client.windowHandles((result) => { - if (Array.isArray(result.value)) { - this.handles = this.handles.filter((handle) => { - for (let i = 0; i < result.value.length; i++) { - if (result.value[i] === handle) { - return true; - } - } - return false; - }); - } else { - this.handles = []; + if (result.value.message) { + throw new Error(result.value.message); } - const remaining = result.value.filter((handle) => { - for (let i = 0; i < this.handles.length; i++) { - if (this.handles[i] === handle) { - return false; - } - } - return true; - }); + this.handles = this.handles.filter((handle) => result.value.includes(handle)); + const remaining = result.value.filter((handle) => !this.handles.includes(handle)); + if (remaining.length === 1) { this.handles.push(remaining[0]); } @@ -56,6 +42,14 @@ class SortedWindowHandler { callback(this.handles); }); } + + /** + * Switch to main window handle and remove latest handle. + */ + pop() { + this.client.switchWindow(this.handles[0]); + this.handles.splice(-1, 1); + } } module.exports = SortedWindowHandler;