From 87d6c20ad9897b931b7f4d049c34f08caafea73a Mon Sep 17 00:00:00 2001 From: thaisym1912 <33540170+thaisym1912@users.noreply.github.com> Date: Mon, 10 Sep 2018 14:17:49 +0700 Subject: [PATCH] AVT-1145 [Spectron] Review and update the existing tests in closePopOutsOnReload.spectron (#498) * Updated AVT-1145 --- .../alwaysOnTopWithMultApps.spectron.js | 4 +- tests/spectron/badgeCount.spectron.js | 9 +- .../spectron/closePopOutsOnReload.spectron.js | 124 +++++--------- tests/spectron/popOuts.spectron.js | 99 ----------- tests/spectron/spectronInterfaces.js | 1 + tests/spectron/spectronWebActions.js | 7 +- tests/spectron/spectronWebDriver.js | 39 ++--- tests/spectron/spectronWindowsActions.js | 155 +++++++++++------- 8 files changed, 160 insertions(+), 278 deletions(-) delete mode 100644 tests/spectron/popOuts.spectron.js diff --git a/tests/spectron/alwaysOnTopWithMultApps.spectron.js b/tests/spectron/alwaysOnTopWithMultApps.spectron.js index 825c8f38..cb2c77ac 100644 --- a/tests/spectron/alwaysOnTopWithMultApps.spectron.js +++ b/tests/spectron/alwaysOnTopWithMultApps.spectron.js @@ -52,7 +52,7 @@ describe('Tests for always on top with mult-apps are opened', () => { if (isMac) { await Utils.openAppInMaximize("Notes"); await Utils.openAppInMaximize("Reminders"); - await Utils.sleep(10); + await Utils.sleep(10); //Sleep 10secs for waiting app opening completely. } else { await Utils.openAppInMaximize("notepad.exe"); await Utils.openAppInMaximize("mspaint.exe"); @@ -60,7 +60,7 @@ describe('Tests for always on top with mult-apps are opened', () => { await windowActions.showWindow(); await windowActions.clickOutsideWindow(); await windowActions.verifyWindowsOnTop(true); - + //Close and open app again, make sure it's always on top await app.stop(); app = await new Application({}).startApplication(); diff --git a/tests/spectron/badgeCount.spectron.js b/tests/spectron/badgeCount.spectron.js index b1346e13..56b55345 100644 --- a/tests/spectron/badgeCount.spectron.js +++ b/tests/spectron/badgeCount.spectron.js @@ -1,6 +1,5 @@ const Application = require('./spectronSetup'); const WebDriver = require('./spectronWebDriver'); -const { isMac } = require('../../js/utils/misc.js'); const Utils = require('./spectronUtils'); let app = new Application({ startTimeout: Application.getTimeOut(), @@ -10,10 +9,10 @@ let webdriver = new WebDriver({ browser: 'chrome' }); const WindowsAction = require('./spectronWindowsActions'); const WebActions = require('./spectronWebActions'); const specconst = require('./spectronConstants.js'); - +const {isWindowsOS } = require('../../js/utils/misc'); let webActions, windowAction; -!isMac ? describe('Test for Badge Count on MAC', () => { +!isWindowsOS ? describe('Test for Badge Count on MAC', () => { jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut(); let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; beforeAll(async (done) => { @@ -38,8 +37,9 @@ let webActions, windowAction; done.fail(new Error(`Failed at post-condition: ${err}`)); }; }); + /** - * Show 1 in tray icon when unread message = 1 + * Show 1 in tray icon when unread message = 1 (Support MAC only) * TC-ID: 2906586 * Cover scenarios in AVT-1095 */ @@ -60,5 +60,4 @@ let webActions, windowAction; done.fail(new Error(`Show 1 in tray icon with error: ${err}`)); } }); - }) : describe.skip(); diff --git a/tests/spectron/closePopOutsOnReload.spectron.js b/tests/spectron/closePopOutsOnReload.spectron.js index 845cd0b5..58134cba 100644 --- a/tests/spectron/closePopOutsOnReload.spectron.js +++ b/tests/spectron/closePopOutsOnReload.spectron.js @@ -1,90 +1,54 @@ const Application = require('./spectronSetup'); +const WebActions = require('./spectronWebActions'); +const WindowsActions = require('./spectronWindowsActions'); +const constants = require('./spectronConstants.js'); const path = require('path'); - -let app = new Application({}); +const ui = require('./spectronInterfaces.js'); +const Utils = require('./spectronUtils.js'); +let app, windowsActions; describe('Tests for pop outs reload scenario', () => { + jasmine.DEFAULT_TIMEOUT_INTERVAL = constants.TIMEOUT_TEST_SUITE; - let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; - jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut(); - - beforeAll((done) => { - return app.startApplication().then((startedApp) => { - app = startedApp; + beforeAll(async (done) => { + try { + app = await new Application({}).startApplication({ testedHost: constants.TESTED_HOST, alwaysOnTop: true }); + webActions = await new WebActions(app); + windowsActions = await new WindowsActions(app); done(); - }).catch((err) => { - console.error(`Unable to start application: ${err}`); - expect(err).toBeNull(); + } catch (err) { + await windowsActions.stopApp(); + done.fail(new Error(`Unable to start application error: ${err}`)); + }; + }); + + afterAll(async (done) => { + try { + await windowsActions.stopApp(); done(); - }); + } catch (err) { + done.fail(new Error(`Failed at post-condition: ${err}`)); + }; }); - afterAll((done) => { - if (app && app.isRunning()) { - jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; - app.stop().then(() => { - done(); - }).catch((err) => { - done(); - }); - } + it('Pop-up should be closed when main window is reloaded', async (done) => { + try { + if (await windowsActions.isAppRunning()) { + await webActions.navigateURL('file:///' + path.join(__dirname, '..', '..', 'demo/index.html')); + await windowsActions.bringToFront("Symphony"); + await webActions.clickIfElementVisible(ui.OPEN_WINDOW_BUTTON); + await windowsActions.verifyPopOutWindowAppear("Test pop-out window"); + await windowsActions.windowByIndex(1); + await webActions.clickIfElementVisible(ui.OPEN_WINDOW_BUTTON); + await windowsActions.verifyPopOutWindowAppear("Child pop-out window"); + await windowsActions.windowByIndex(0); + await windowsActions.windowReload(); + await Utils.sleep(2); + await windowsActions.verifyWindowCount(1); + } + done(); + } catch (err) { + done.fail(new Error(`Fail to verify pop-up closed when main window is reloaded: ${err}`)); + }; }); - - it('should launch the app', (done) => { - return app.client.waitUntilWindowLoaded().then(() => { - return app.client.getWindowCount().then((count) => { - expect(count === 1).toBeTruthy(); - done(); - }).catch((err) => { - expect(err).toBeNull(); - }); - }).catch((err) => { - expect(err).toBeNull(); - }); - }); - - it('should load the demo page', () => { - return app.client.url('file:///' + path.join(__dirname, '..', '..', 'demo/index.html')); - }); - - it('should open a new window and verify', function (done) { - app.client.waitForExist('#open-win', 2000); - app.client.moveToObject('#open-win', 10, 10); - app.client.leftClick('#open-win', 10, 10); - - setTimeout(() => { - app.client.getWindowCount().then((count) => { - expect(count === 2).toBeTruthy(); - done(); - }); - }, 2000); - }); - - it('should open a child window from pop-out and verify', function (done) { - return app.client.windowByIndex(1).then(() => { - app.client.waitForExist('#open-win', 2000); - app.client.moveToObject('#open-win', 10, 10); - app.client.leftClick('#open-win', 10, 10); - - setTimeout(() => { - app.client.getWindowCount().then((count) => { - expect(count === 3).toBeTruthy(); - done(); - }); - }, 2000); - }); - }); - - it('should close pop-out window when main window is reloaded', function (done) { - return app.client.windowByIndex(0).then(() => { - app.browserWindow.reload(); - - setTimeout(() => { - app.client.getWindowCount().then((count) => { - expect(count === 1).toBeTruthy(); - done(); - }); - }, 2000); - }); - }); -}); \ No newline at end of file +}); diff --git a/tests/spectron/popOuts.spectron.js b/tests/spectron/popOuts.spectron.js deleted file mode 100644 index 44dd65ff..00000000 --- a/tests/spectron/popOuts.spectron.js +++ /dev/null @@ -1,99 +0,0 @@ -const Application = require('./spectronSetup'); -const path = require('path'); - -let app = new Application({}); - -describe('Tests for pop outs', () => { - - let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; - jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut(); - - beforeAll((done) => { - return app.startApplication().then((startedApp) => { - app = startedApp; - done(); - }).catch((err) => { - console.error(`Unable to start application: ${err}`); - expect(err).toBeNull(); - done(); - }); - }); - - afterAll((done) => { - if (app && app.isRunning()) { - jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; - app.stop().then(() => { - done(); - }).catch((err) => { - done(); - }); - } - }); - - it('should launch the app', (done) => { - return app.client.waitUntilWindowLoaded().then(() => { - return app.client.getWindowCount().then((count) => { - expect(count === 1).toBeTruthy(); - done(); - }).catch((err) => { - expect(err).toBeNull(); - }); - }).catch((err) => { - expect(err).toBeNull(); - }); - }); - - it('should load the demo page', () => { - return app.client.url('file:///' + path.join(__dirname, '..', '..', 'demo/index.html')); - }); - - it('should open a new window and verify', function (done) { - app.client.waitForExist('#open-win', 2000); - app.client.moveToObject('#open-win', 10, 10); - app.client.leftClick('#open-win', 10, 10); - - setTimeout(() => { - app.client.getWindowCount().then((count) => { - expect(count === 2).toBeTruthy(); - done(); - }); - }, 2000); - }); - - it('should click on the external link and verify window', function () { - return app.client.windowByIndex(1).then(() => { - app.client.waitForExist('#open-in-browser', 2000); - app.client.moveToObject('#open-in-browser', 10, 10); - app.client.leftClick('#open-in-browser', 10, 10); - - return app.client.getWindowCount().then((count) => { - expect(count === 2).toBeTruthy(); - }); - }); - }); - - it('should open a child window from pop-out and verify', function (done) { - app.client.waitForExist('#open-win', 2000); - app.client.moveToObject('#open-win', 10, 10); - app.client.leftClick('#open-win', 10, 10); - - setTimeout(() => { - app.client.getWindowCount().then((count) => { - expect(count === 3).toBeTruthy(); - done(); - }); - }, 2000); - }); - - it('should click on the external link in a child pop-out without creating a window', function () { - return app.client.windowByIndex(2).then(() => { - app.client.waitForExist('#open-in-browser', 2000); - app.client.moveToObject('#open-in-browser', 10, 10); - app.client.leftClick('#open-in-browser', 10, 10); - - return app.client.getWindowCount().then((count) => { - expect(count === 3).toBeTruthy(); - }); - }); - }); -}); \ No newline at end of file diff --git a/tests/spectron/spectronInterfaces.js b/tests/spectron/spectronInterfaces.js index 53b8bf1c..dc2bcf79 100644 --- a/tests/spectron/spectronInterfaces.js +++ b/tests/spectron/spectronInterfaces.js @@ -92,6 +92,7 @@ module.exports= { //Symphony Electron API Demo GET_VERSION_BUTTON: "#get-version", + OPEN_WINDOW_BUTTON: "#open-win", //Symphony Electron API Demo TAG_TEXTBOX: "#tag" diff --git a/tests/spectron/spectronWebActions.js b/tests/spectron/spectronWebActions.js index 1abac31e..1cb0dbd9 100644 --- a/tests/spectron/spectronWebActions.js +++ b/tests/spectron/spectronWebActions.js @@ -328,8 +328,7 @@ class WebActions { async logintoAdmin(user) { await this.inputText(ui.SIGN_IN_EMAIL, user.username); await this.inputText(ui.SIGN_IN_PASSWORD, user.password); - await this.clickAndWaitElementVisible(ui.SIGN_IN_BUTTON, ui.IMG_ADMIN_LOGO, constants.TIMEOUT_WAIT_ELEMENT * 5); - + await this.clickAndWaitElementVisible(ui.SIGN_IN_BUTTON, ui.IMG_ADMIN_LOGO, constants.TIMEOUT_PAGE_LOAD); } async openNotificationPosition() { @@ -435,10 +434,6 @@ class WebActions { await expect(values[ 3 ]).toBe(buildNumber); await expect(values[ 4 ]).toBe(SEARCH_API_VERSION); } - - async navigateURL(url) { - return this.app.client.url(url); - } } module.exports = WebActions; diff --git a/tests/spectron/spectronWebDriver.js b/tests/spectron/spectronWebDriver.js index c660896a..c6d8c77d 100644 --- a/tests/spectron/spectronWebDriver.js +++ b/tests/spectron/spectronWebDriver.js @@ -1,4 +1,4 @@ -const { Builder, By, Key, until,Actions } = require('selenium-webdriver') +const { Builder, By, Key, until, Actions } = require('selenium-webdriver') require('selenium-webdriver/chrome'); require('chromedriver'); const Utils = require('./spectronUtils'); @@ -41,7 +41,7 @@ class WebDriver { ) await this.driver.wait(until.elementIsVisible(el), timeout); } - + async waitElementVisibleAndGet(xpath) { const el = await this.driver.wait( until.elementLocated(By.xpath(xpath)), @@ -130,11 +130,6 @@ class WebDriver { await el.click(); } - async clickDoneButton() { - var el = await this.getElementByXPath(ui.CREATE_IM_DONE_BTN); - await el.click(); - } - async clickDoneButton() { var el = await this.getElementByXPath(ui.CREATE_IM_DONE_BTN); await el.click(); @@ -257,41 +252,39 @@ class WebDriver { } async sendMessagesAndVerifyToast(messages) { - - for (var i = 0; i < messages.length; i++) { + for (var i = 0; i < messages.length; i++) { await this.webActions.clickPlusButton(); - await this.windowAction.pressCtrlM(); - await this.sendMessage(messages[i]).then(async ()=> - { + await this.windowAction.pressCtrlM(); + await this.sendMessage(messages[i]).then(async () => { await this.windowAction.verifyPersistToastNotification(messages[i]); - }); + }); } } - async closeAllGridModules(){ + async closeAllGridModules() { let count = await this.getCount(ui.HEADER_MODULE); - for (let i=1; i<= count; i++){ - let header = ui.HEADER_MODULES.replace("$$",1); - let closeButton = ui.CLOSE_MODULES.replace("$$",1); - let pinButton = ui.PIN_CHAT_MODS.replace("$$",1); - await this.clickIfElementVisible(header); + for (let i = 1; i <= count; i++) { + let header = ui.HEADER_MODULES.replace("$$", 1); + let closeButton = ui.CLOSE_MODULES.replace("$$", 1); + let pinButton = ui.PIN_CHAT_MODS.replace("$$", 1); + await this.clickIfElementVisible(header); await this.clickIfElementVisible(pinButton); await this.clickIfElementVisible(closeButton); } } - + async clickIfElementVisible(selector) { let el = await this.getElementByXPath(selector); await el.click(); } - async getCount(locator){ - let elements = await this.driver.findElements(By.xpath(locator)); + async getCount(locator) { + let elements = await this.driver.findElements(By.xpath(locator)); return elements.length; } async mouseOver(locator) { let el = await this.getElementByXPath(locator); - let builder = await new Actions(this.driver); + let builder = await new Actions(this.driver); builder.moveToElement(el, 20, 20).click().build().perform(); } } diff --git a/tests/spectron/spectronWindowsActions.js b/tests/spectron/spectronWindowsActions.js index 7c3e328c..515d97cd 100644 --- a/tests/spectron/spectronWindowsActions.js +++ b/tests/spectron/spectronWindowsActions.js @@ -82,7 +82,7 @@ class WindowsActions { async clickOutsideWindow() { await this.setPosition(0, 0); let currentSize = await this.getCurrentSize(); - await robot.setMouseDelay(100); + await robot.setMouseDelay(100); await robot.moveMouse(currentSize[0] + 20, currentSize[1] + 20); await robot.mouseClick(); } @@ -158,35 +158,33 @@ class WindowsActions { } async actionForMenusOnMac(arrMenu) { - let webAction = await new WebActions(this.app); - await robot.setMouseDelay(2000); - let x = 5; - let y = 5; - await robot.moveMouseSmooth(x, y); - await robot.moveMouse(x, y); - await robot.mouseClick(); - await robot.setKeyboardDelay(100); - for (var i = 0; i < arrMenu.length; i++) { - if (i==0) - { - for (var s = 0; s < arrMenu[i].step; s++) { - - await robot.keyTap('right'); - } - } - else - { - for (var s = 0; s < arrMenu[i].step; s++) { - - await robot.keyTap('down'); - } - } - if (arrMenu.length > 1 && i != arrMenu.length - 1) { - //handle right keygen + let webAction = await new WebActions(this.app); + await robot.setMouseDelay(2000); + let x = 5; + let y = 5; + await robot.moveMouseSmooth(x, y); + await robot.moveMouse(x, y); + await robot.mouseClick(); + await robot.setKeyboardDelay(100); + for (var i = 0; i < arrMenu.length; i++) { + if (i == 0) { + for (var s = 0; s < arrMenu[i].step; s++) { + await robot.keyTap('right'); } } - await robot.keyTap('enter'); + else { + for (var s = 0; s < arrMenu[i].step; s++) { + + await robot.keyTap('down'); + } + } + if (arrMenu.length > 1 && i != arrMenu.length - 1) { + //handle right keygen + await robot.keyTap('right'); + } + } + await robot.keyTap('enter'); } async verifyLogExported() { @@ -262,7 +260,7 @@ class WindowsActions { } async verifyMinimizeWindows() { - + let isMinimized = await this.app.browserWindow.isMinimized(); await expect(isMinimized).toBeTruthy(); } @@ -326,15 +324,15 @@ class WindowsActions { }); } - async clickNotification(x,y) { - await robot.setMouseDelay(500); + async clickNotification(x, y) { + await robot.setMouseDelay(500); await robot.moveMouseSmooth(x, y); await robot.moveMouse(x, y); await robot.mouseClick(); } - async mouseMoveNotification(x,y) { - await robot.setMouseDelay(500); + async mouseMoveNotification(x, y) { + await robot.setMouseDelay(500); await robot.moveMouseSmooth(x, y); await robot.moveMouse(x, y); } @@ -350,28 +348,28 @@ class WindowsActions { }); } - async verifyPersistToastNotification(message) { + async verifyPersistToastNotification(message) { let webAction = await new WebActions(this.app); let currentPosition = await this.getToastNotificationPosition(message); - let curentSize = await this.getToastNotificationSize(message); + let curentSize = await this.getToastNotificationSize(message); await webAction.verifyToastNotificationShow(message); - let x = await (currentPosition[0] + curentSize[0]/2); - let y = await (currentPosition[1] + curentSize[1]/2); - await this.clickNotification(x,y); + let x = await (currentPosition[0] + curentSize[0] / 2); + let y = await (currentPosition[1] + curentSize[1] / 2); + await this.clickNotification(x, y); await this.mouseMoveCenter(); } async verifyNotPersistToastNotification() { - let i = 0; + let i = 0; while (i < 3) { await Utils.sleep(1); await i++; - } - await this.webAction.verifyNoToastNotificationShow(); + } + await this.webAction.verifyNoToastNotificationShow(); await this.mouseMoveCenter(); } - async verifyNotCloseToastWhenMouseOver(message) { + async verifyNotCloseToastWhenMouseOver(message) { var i = 0; while (i < 3) { await Utils.sleep(1); @@ -379,17 +377,17 @@ class WindowsActions { } let webAction = await new WebActions(this.app); let currentPosition = await this.getToastNotificationPosition(message); - let curentSize = await this.getToastNotificationSize(message); - let x = await (currentPosition[0] + curentSize[0]/2); - let y = await (currentPosition[1] + curentSize[1]/2); - await this.mouseMoveNotification(x,y); + let curentSize = await this.getToastNotificationSize(message); + let x = await (currentPosition[0] + curentSize[0] / 2); + let y = await (currentPosition[1] + curentSize[1] / 2); + await this.mouseMoveNotification(x, y); await webAction.verifyToastNotificationShow(message); await this.mouseMoveCenter(); } async windowByIndex(index) { await this.app.client.windowByIndex(index); - } + } async getWindowIndexFromTitle(windowTitle) { let winCount = await this.getWindowCount(); @@ -423,14 +421,12 @@ class WindowsActions { await this.app.browserWindow.minimize(); await this.app.browserWindow.restore(); } - - async closeChromeDriver() - { + + async closeChromeDriver() { Utils.killProcess("chromedriver"); } - async closeChromeDriverOnMac() - { + async closeChromeDriverOnMac() { Utils.killProcessOnMac("Electron"); } @@ -501,7 +497,7 @@ class WindowsActions { async verifyWindowFocus(windowTitle) { let index = await this.getWindowIndexFromTitle(windowTitle); await this.windowByIndex(index); - let isFocused = await this.app.browserWindow.isFocused(); + let isFocused = await this.app.browserWindow.isFocused(); expect(isFocused === true).toBeTruthy(); await this.windowByIndex(0); } @@ -527,20 +523,28 @@ class WindowsActions { await this.app.stop(); } } - + async isAppRunning() { return this.app.isRunning(); } - async generateLog(downloadsPath) - { - let zip = new JSZip(); + async generateLog(downloadsPath) { + let zip = new JSZip(); zip.file("Hello.txt", "Hello World\n"); - zip.generateNodeStream({type:'nodebuffer',streamFiles:true}) - .pipe(fs.createWriteStream(downloadsPath+'/logs_symphony_1.zip')) - .on('finish', function () { - console.log("logs_symphony written."); - }); + zip.generateNodeStream({ type: 'nodebuffer', streamFiles: true }) + .pipe(fs.createWriteStream(downloadsPath + '/logs_symphony_1.zip')) + .on('finish', function () { + console.log("logs_symphony written."); + }); + } + + async windowReload() { + await this.app.browserWindow.reload(); + } + + async verifyWindowCount(expected) { + let count = await this.app.client.getWindowCount() + await expect(count === expected).toBeTruthy(); } async doAlwaysOnTopOnMac() { @@ -570,7 +574,7 @@ class WindowsActions { } } } - + async verifyAppFullScreen() { let actual = await this.app.browserWindow.isFullScreen(); await expect(actual).toBeTruthy(); @@ -594,6 +598,31 @@ class WindowsActions { await robot.moveMouse(0, 100); await robot.mouseClick(); } + + async resetBadgeCount() { + await this.app.electron.remote.app.setBadgeCount(0); + } + + async getBadgeCount() { + let count = await this.app.electron.remote.app.getBadgeCount(); + return count; + } + + async verifyCurrentBadgeCount(number) { + let expected = false; + var i = 0; + var count = await this.getBadgeCount(); + while (i < 5) { + if (count == number) { + expected = true; + break; + } + await Utils.sleep(1); + count = await this.getBadgeCount(); + await i++; + } + await expect(expected).toBeTruthy(); + } } -module.exports = WindowsActions; +module.exports = WindowsActions; \ No newline at end of file