diff --git a/tests/spectron/bringToFront.spectron.js b/tests/spectron/bringToFront.spectron.js index 4bfe064d..a2167f0d 100644 --- a/tests/spectron/bringToFront.spectron.js +++ b/tests/spectron/bringToFront.spectron.js @@ -1,118 +1,55 @@ const Application = require('./spectronSetup'); -const bluebird = require('bluebird'); -const { isMac, isWindowsOS } = require('../../js/utils/misc'); -const robot = require('robotjs'); - +const specconst = require('./spectronConstants.js'); +const WindowsAction = require('./spectronWindowsActions'); +let windowAction; let app = new Application({}); -function blurBrowserWindow() { - robot.setMouseDelay(200); - robot.moveMouse(0, 100); - robot.mouseClick(); -} - describe('Tests for Bring to front', () => { - 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: specconst.TESTED_HOST, alwaysOnTop: true }); + windowAction = await new WindowsAction(app); done(); - }).catch((err) => { + } catch (err) { done.fail(new Error(`Unable to start application error: ${err}`)); - }); + }; }); - afterAll((done) => { - if (app && app.isRunning()) { - jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; - app.stop().then(() => { + afterAll(async (done) => { + try { + if (app && app.isRunning()) { + jasmine.DEFAULT_TIMEOUT_INTERVAL = await originalTimeout; + await app.stop(); + await webdriver.quit(); done(); - }).catch((err) => { - done(); - }); - } - }); - - it('should launch the app and verify window count', (done) => { - return app.client.waitUntilWindowLoaded().then(() => { - return app.client.getWindowCount().then((count) => { - expect(count === 1).toBeTruthy(); - done(); - }).catch((err) => { - done.fail(new Error(`bringToFront failed in getWindowCount with error: ${err}`)); - }); - }).catch((err) => { - done.fail(new Error(`bringToFront failed in waitUntilWindowLoaded with error: ${err}`)); - }); - }); - - it('should minimize the app and verify if the window isMinimized', (done) => { - return app.browserWindow.minimize().then(() => { - return app.browserWindow.isMinimized().then((isMinimized) => { - expect(isMinimized).toBeTruthy(); - done(); - }).catch((err) => { - done.fail(new Error(`bringToFront failed in isMinimized with error: ${err}`)); - }); - }); - }); - - it('should restore the browser window and verify window focus', (done) => { - bluebird.all([ - blurBrowserWindow, - app.browserWindow.restore, - app.browserWindow.isMinimized, - app.browserWindow.isFocused, - ]).mapSeries((method) => { - return method(); - }).then((results) => { - if (isMac) { - expect(results[2]).toBe(false); - expect(results[3]).toBe(false); } - - if (isWindowsOS) { - expect(results[2]).toBe(false); - expect(results[3]).toBe(true); - } - done(); - }).catch((err) => { - done.fail(new Error(`bringToFront failed to restore with error: ${err}`)); - }); + } catch (err) { + done.fail(new Error(`Failed at post-condition: ${err}`)); + }; }); - it('should minimize and verify if the window isMinimized again', function () { - return app.browserWindow.minimize().then(() => { - return app.browserWindow.isMinimized().then((isMinimized) => { - expect(isMinimized).toBeTruthy(); - }).catch((err) => { - done.fail(new Error(`bringToFront failed to minimize with error: ${err}`)); - }); - }); + it('should show the browser window and verify window focus', async (done) => { + await windowAction.blurBrowserWindow() + await app.browserWindow.minimize(); + let isMinimized = await app.browserWindow.isMinimized(); + await expect(isMinimized).toBe(true); + await app.browserWindow.showInactive(); + let isFocused = await app.browserWindow.isFocused(); + await expect(isFocused).toBe(false); + done(); }); - it('should show the browser window and verify window focus', (done) => { - bluebird.all([ - blurBrowserWindow, - app.browserWindow.showInactive, - app.browserWindow.isFocused - ]).mapSeries((method) => { - return method(); - }).then((results) => { - if (isMac) { - expect(results[2]).toBe(false); - } - - if (isWindowsOS) { - expect(results[2]).toBe(true); - } - done(); - }).catch((err) => { - done.fail(new Error(`bringToFront failed to focus with error: ${err}`)); - }); + it('should restore the browser window and verify window focus', async (done) => { + await windowAction.blurBrowserWindow() + await app.browserWindow.minimize(); + let isMinimized = await app.browserWindow.isMinimized(); + await expect(isMinimized).toBe(true); + await app.browserWindow.restore(); + let isFocused = await app.browserWindow.isFocused(); + await expect(isFocused).toBe(true); + done(); }); -}); \ No newline at end of file +}); diff --git a/tests/spectron/close.spectron.js b/tests/spectron/close.spectron.js index ca49ee58..37b647dd 100644 --- a/tests/spectron/close.spectron.js +++ b/tests/spectron/close.spectron.js @@ -29,37 +29,6 @@ describe('Tests for Close', () => { } }); - it('should launch the app', (done) => { - return app.client.waitUntilWindowLoaded().then(() => { - return app.client.getWindowCount().then((count) => { - expect(count === 1).toBeTruthy(); - done(); - }).catch((err) => { - done.fail(new Error(`close failed in getWindowCount with error: ${err}`)); - }); - }).catch((err) => { - done.fail(new Error(`close failed in waitUntilWindowLoaded with error: ${err}`)); - }); - }); - - it('should check window count', (done) => { - return app.client.getWindowCount().then((count) => { - expect(count === 1).toBeTruthy(); - done(); - }).catch((err) => { - done.fail(new Error(`close failed in getWindowCount with error: ${err}`)); - }); - }); - - it('should check browser window visibility', (done) => { - return app.browserWindow.isVisible().then((isVisible) => { - expect(isVisible).toBeTruthy(); - done(); - }).catch((err) => { - done.fail(new Error(`close failed in isVisible with error: ${err}`)); - }); - }); - it('should close the app', () => { return app.stop(); }); diff --git a/tests/spectron/spectronConstants.js b/tests/spectron/spectronConstants.js index 552928f7..dbe91eaa 100644 --- a/tests/spectron/spectronConstants.js +++ b/tests/spectron/spectronConstants.js @@ -17,7 +17,17 @@ module.exports = { ] } }, - + MENUMAC: { + "root": { + name: "menu", step: 0, items: [ + { name: "Electron", step: 0, items: [{ name: "About Symphony", step: 0 }, { name: "Services", step: 1 }]}, + { name: "Edit", step: 1, items: [{ name: "Undo", step: 0 }, { name: "Redo", step: 1 }, { name: "Cut", step: 2 }, { name: "Copy", step: 3 }, { name: "Paste", step: 4 }, { name: "Paste and Match Style", step: 5 }, { name: "Delete", step: 6 }, { name: "Select All", step: 7 }] }, + { name: "View", step: 2, items: [{ name: "Reload", step: 0 }, { name: "Actual Size", step: 1 }, { name: "Zoom In", step: 2 }, { name: "Zoom Out", step: 3 }, { name: "Toogle Full Screen", step: 4 },{ name: "Minimize on Close", step: 8 }] }, + { name: "Window", step: 3, items: [{ name: "Close", step: 0 }, { name: "Minimize", step: 1 }, { name: "Zoom", step: 2 }]}, + { name: "Help", step: 4, items: [{ name: "Symphony Help", step: 0 }, { name: "Learn More", step: 1 }, { name: "Troubleshooting", step: 2, items: [{ name: "Show Logs in Explorer", step: 0 }] }, { name: "About Symphony", step: 3 }] } + ] + } + }, LOG_FILENAME_PREFIX: "logs_symphony_", USER_A: { username: process.env.USER_A, password: process.env.PASSWORD, name: process.env.USER_A_NAME }, USER_B: { username: process.env.USER_B, password: process.env.PASSWORD, name: process.env.USER_B_NAME }, diff --git a/tests/spectron/spectronInterfaces.js b/tests/spectron/spectronInterfaces.js index b321f46c..4b91f5e8 100644 --- a/tests/spectron/spectronInterfaces.js +++ b/tests/spectron/spectronInterfaces.js @@ -6,6 +6,7 @@ module.exports= { CLOSE_BUTTON: "button#title-bar-close-button", MAIN_MENU_ITEM: "#hamburger-menu-button", SYM_LOGO: "#logo", + MINIMIZE_BTN: "#title-bar-minimize-button", //Sign In SIGN_IN_BUTTON: "//button[@name='signin-submit']", @@ -56,6 +57,7 @@ module.exports= { HEADER_MODULE_NAME: "//header[contains(@class,'module-header gs-draggable')]//span[contains(@class,'aliasable') and normalize-space()='$$']", CLOSE_MODULE: "//button[contains(@class,'close-module')]", CLOSE_MODULES: "(//button[contains(@class,'close-module')])[$$]", + PIN_CHAT_MODS: "(//button[contains(@class,'pin-view')])[$$]", //Popin Popout POPOUT_BUTTON: ".enhanced-pop-out", @@ -76,7 +78,7 @@ module.exports= { INBOX_HEADER: ".inbox-header", //ACP - ACP_LINK: "//button[@class='show-admin-link left-action button-reset']", + ACP_LINK: "//*[contains(@class,'show-admin-link')]", IMG_ADMIN_LOGO: "//img[@src='./img/nav_admin_logo.png']", //LOG OUT @@ -91,4 +93,3 @@ module.exports= { //Symphony Electron API Demo TAG_TEXTBOX: "#tag" }; - diff --git a/tests/spectron/spectronWebActions.js b/tests/spectron/spectronWebActions.js index d122eb9b..3dfc3b07 100644 --- a/tests/spectron/spectronWebActions.js +++ b/tests/spectron/spectronWebActions.js @@ -55,7 +55,7 @@ class WebActions { } async inputText(el, data) { - var obj = await this.getElementByXPath(el); + let obj = await this.getElementByXPath(el); if (obj != null) await this.app.client.setValue(el, data); } @@ -122,6 +122,7 @@ class WebActions { await this.app.client.windowByIndex(j); if (await this.app.client.getText(ui.TOAST_MESSAGE_CONTENT) === message) { show = true; + break; } } if (show) { @@ -134,26 +135,26 @@ class WebActions { await this.app.client.windowByIndex(0); } - async verifyNoToastNotificationShow(message) { - let noShow; - for (let i = 0; i < 10; i++) { - let winCount = await this.app.client.getWindowCount(); - if (winCount > 1) { - for (let j = 1; j < winCount; j++) { - await this.app.client.windowByIndex(j); - if (await this.app.client.getText(ui.TOAST_MESSAGE_CONTENT) !== message) { - noShow = true; - } - else { - noShow = false; - } - } - if (noShow === false) { - break; - } + async verifyNoToastNotificationShow() { + let noShow = false; + let title = ''; + for (let i = 0; i < 5; i++) { + await Utils.sleep(1); + await this.app.client.windowByIndex(1); + title = await this.app.client.getText(ui.TOAST_MESSAGE_CONTENT) + if (title !== '') + { + noShow = true; + break; } - await Utils.sleep(1); } + for (let j = 0; j < 15; j++) { + await Utils.sleep(1); + } + if (title !== '') + { + noShow = true; + } await expect(noShow).toBeTruthy(); await this.app.client.windowByIndex(0); } @@ -184,21 +185,31 @@ class WebActions { async login(user) { await this.inputText(ui.SIGN_IN_EMAIL, user.username); - await this.inputText(ui.SIGN_IN_PASSWORD, user.password); + await this.inputText(ui.SIGN_IN_PASSWORD, user.password); + await this.clickIfElementVisible(ui.SIGN_IN_BUTTON); await this.clickAndWaitElementVisible(ui.SIGN_IN_BUTTON, ui.SETTTING_BUTTON, constants.TIMEOUT_PAGE_LOAD); - await this.waitElementNotVisible(ui.SPINNER); + //await this.waitElementNotVisible(ui.SPINNER); } - async persistToastIM() { + async persistToastIM(isPersistance) { await this.clickAndWaitElementVisible(ui.SETTTING_BUTTON, ui.ALERT_OPTION, constants.TIMEOUT_WAIT_ELEMENT); await this.clickAndWaitElementVisible(ui.ALERT_OPTION, ui.ALERT_TAB, constants.TIMEOUT_WAIT_ELEMENT); - await this.clickAndWaitElementVisible(ui.PERSIS_NOTIFICATION_INPUT_IM, ui.PERSIS_NOTIFICATION_INPUT_IM, constants.TIMEOUT_WAIT_ELEMENT); + let ischeck = await this.app.client.element(ui.PERSIS_NOTIFICATION_INPUT_IM).getAttribute("checked"); + + if (isPersistance === true && (ischeck === false || ischeck === null)) { + await this.clickAndWaitElementVisible(ui.PERSIS_NOTIFICATION_INPUT_IM, ui.PERSIS_NOTIFICATION_INPUT_IM, constants.TIMEOUT_WAIT_ELEMENT); + } + else if (isPersistance === false) { + await this.scrollAndClick(ui.SCROLL_TAB_ACTIVE, ui.PERSIS_NOTIFICATION_INPUT_IM); + + } } async openACP() { await this.clickAndWaitElementVisible(ui.SETTTING_BUTTON, ui.GENERAL_OPTION, constants.TIMEOUT_WAIT_ELEMENT); await this.clickAndWaitElementVisible(ui.GENERAL_OPTION, ui.GENERAL_TAB, constants.TIMEOUT_WAIT_ELEMENT); - await this.clickAndWaitElementVisible(ui.ACP_LINK, ui.IMG_ADMIN_LOGO, constants.TIMEOUT_WAIT_ELEMENT); + await this.clickAndWaitElementVisible(ui.ACP_LINK, ui.IMG_ADMIN_LOGO, constants.TIMEOUT_WAIT_ELEMENT * 10); + } async clickPlusButton() { @@ -206,7 +217,7 @@ class WebActions { } async clickStartChat() { - await this.clickIfElementVisible(ui.START_CHAT); + await this.clickIfElementVisible(ui.START_CHAT, constants.TIMEOUT_WAIT_ELEMENT * 5); } async logout() { @@ -225,7 +236,7 @@ class WebActions { async clickDoneButton() { await this.clickIfElementVisible(ui.CREATE_IM_DONE_BTN); - await this.waitElementVisible(ui.HEADER_MODULE); + await this.waitElementVisible(ui.HEADER_MODULE, constants.TIMEOUT_WAIT_ELEMENT * 5); } async waitElementNotVisible(locator, timeOut = constants.TIMEOUT_WAIT_ELEMENT) { @@ -287,10 +298,10 @@ class WebActions { await windowsActions.windowByIndex(0); } - async verifyPopOutIconDisplay(){ + async verifyPopOutIconDisplay() { await this.mouseOver(ui.PIN_CHAT_MOD); await Utils.sleep(2); //wait popout button clickable - await this.waitElementVisible(ui.POPOUT_BUTTON, constants.TIMEOUT_WAIT_ELEMENT); + await this.waitElementVisible(ui.POPOUT_BUTTON, constants.TIMEOUT_WAIT_ELEMENT * 5); } async clickInboxIcon() { @@ -342,31 +353,31 @@ class WebActions { checked = await this.app.client.isSelected(selector); } } - - async pinChat(){ + + async pinChat() { await this.mouseOver(ui.PIN_CHAT_MOD); await Utils.sleep(2); //wait popout button clickable await this.clickIfElementVisible(ui.PIN_CHAT_MOD); await this.waitElementVisible(ui.PINNED_CHAT_MOD); } - async verifyChatModuleVisible(muduleName){ - let locator = ui.HEADER_MODULE_NAME.replace("$$",muduleName); - await this.waitElementVisible(locator); + async verifyChatModuleVisible(muduleName) { + let locator = ui.HEADER_MODULE_NAME.replace("$$", muduleName); + await this.waitElementVisible(locator, constants.TIMEOUT_WAIT_ELEMENT * 5); } - 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); + for (let i = 1; i <= count; i++) { + let header = ui.HEADER_MODULES.replace("$$", 1); + let closeButton = ui.CLOSE_MODULES.replace("$$", 1); await this.mouseOver(header); await this.clickIfElementVisible(ui.PIN_CHAT_MOD); await this.clickIfElementVisible(closeButton); } } - async getCount(locator){ + async getCount(locator) { let elements = await this.app.client.elements(locator); return elements.value.length; } diff --git a/tests/spectron/spectronWebDriver.js b/tests/spectron/spectronWebDriver.js index 11a2fbfc..c660896a 100644 --- a/tests/spectron/spectronWebDriver.js +++ b/tests/spectron/spectronWebDriver.js @@ -1,6 +1,7 @@ -const { Builder, By, Key, until } = require('selenium-webdriver') +const { Builder, By, Key, until,Actions } = require('selenium-webdriver') require('selenium-webdriver/chrome'); require('chromedriver'); +const Utils = require('./spectronUtils'); var assert = require('assert'); const ui = require('./spectronInterfaces.js'); const specconst = require('./spectronConstants.js'); @@ -256,14 +257,42 @@ class WebDriver { } async sendMessagesAndVerifyToast(messages) { - for (var i = 0; i < messages.length; i++) { - await this.sendMessage(messages[i]).then(async() => + + 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.webAction.verifyToastNotificationShow(messages[i]) - }).catch((err) => { - console.error(`Toast notification is not show: ${err}`); - }); + await this.windowAction.verifyPersistToastNotification(messages[i]); + }); } } + 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); + 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)); + return elements.length; + } + + async mouseOver(locator) { + let el = await this.getElementByXPath(locator); + let builder = await new Actions(this.driver); + builder.moveToElement(el, 20, 20).click().build().perform(); + } } module.exports = WebDriver; diff --git a/tests/spectron/spectronWindowsActions.js b/tests/spectron/spectronWindowsActions.js index c097e5ae..981d325c 100644 --- a/tests/spectron/spectronWindowsActions.js +++ b/tests/spectron/spectronWindowsActions.js @@ -5,6 +5,7 @@ const fs = require('fs'); const WebActions = require('./spectronWebActions.js'); const { isMac, isWindowsOS } = require('../../js/utils/misc'); const ui = require('./spectronInterfaces.js'); +const JSZip = require("jszip"); class WindowsActions { constructor(app) { @@ -81,7 +82,8 @@ class WindowsActions { async clickOutsideWindow() { await this.setPosition(0, 0); let currentSize = await this.getCurrentSize(); - await robot.moveMouse(currentSize[0] + 20, currentSize[1] - 50); + await robot.setMouseDelay(100); + await robot.moveMouse(currentSize[0] + 20, currentSize[1] + 20); await robot.mouseClick(); } @@ -120,6 +122,16 @@ class WindowsActions { return arrStep; } + async openMenuOnMac(arrMenu) { + var arrStep = []; + for (var i = 0; i < arrMenu.length; i++) { + var item = await this.menuSearch(constants.MENUMAC.root, arrMenu[i]); + await arrStep.push(item); + } + await this.actionForMenusOnMac(arrStep); + return arrStep; + } + async actionForMenus(arrMenu) { let webAction = await new WebActions(this.app); await this.app.browserWindow.getBounds().then(async (bounds) => { @@ -145,9 +157,42 @@ 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 + await robot.keyTap('right'); + } + } + await robot.keyTap('enter'); + } + async verifyLogExported() { let expected = false; let path = await Utils.getFolderPath('Downloads'); + this.generateLog(path); let listFiles = Utils.getFiles(path); listFiles.forEach(function (fileName) { if (fileName.indexOf(constants.LOG_FILENAME_PREFIX) > -1) { @@ -167,19 +212,6 @@ class WindowsActions { }) } - async isMinimizedWindows() { - let rminimized = -1; - - await this.app.browserWindow.isMinimized().then(async function (minimized) { - rminimized = constants.MINIMIZED; - }).catch((err) => { - rminimized = constants.QUIT; - return rminimized; - }); - - return rminimized; - } - async selectMinimizeOnClose() { let webAction = await new WebActions(this.app); await this.app.browserWindow.getBounds().then(async (bounds) => { @@ -202,21 +234,6 @@ class WindowsActions { }); } - async menuSearch(element, namevalue) { - if (element.name == namevalue) { - return await element; - } - else if (element.items !== undefined) { - var result; - for (var i = 0; result == null && i < element.items.length; i++) { - result = await this.menuSearch(element.items[i], namevalue); - result; - } - return await result; - } - return await null; - } - async quitApp() { let webAction = await new WebActions(this.app); await this.app.browserWindow.getBounds().then(async (bounds) => { @@ -245,6 +262,7 @@ class WindowsActions { } async verifyMinimizeWindows() { + let isMinimized = await this.app.browserWindow.isMinimized(); await expect(isMinimized).toBeTruthy(); } @@ -263,8 +281,14 @@ class WindowsActions { } async pressCtrlM() { - await robot.keyToggle('m', 'down', ['control']); - await robot.keyToggle('m', 'up', ['control']); + if (!isMac) { + await robot.keyToggle('m', 'down', ['control']); + await robot.keyToggle('m', 'up', ['control']); + } + else { + await robot.keyToggle('m', 'down', ['command']); + await robot.keyToggle('m', 'up', ['command']); + } } async pressF11() { @@ -287,7 +311,7 @@ class WindowsActions { async reload() { await this.app.browserWindow.getBounds().then(async (bounds) => { - await robot.setMouseDelay(100); + await robot.setMouseDelay(50); let x = bounds.x + 95; let y = bounds.y + 200; await robot.moveMouseSmooth(x, y); @@ -302,15 +326,15 @@ class WindowsActions { }); } - async clickNotification(x, y) { - await robot.setMouseDelay(100); + 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(50); + async mouseMoveNotification(x,y) { + await robot.setMouseDelay(500); await robot.moveMouseSmooth(x, y); await robot.moveMouse(x, y); } @@ -326,57 +350,46 @@ class WindowsActions { }); } - async veriryPersistToastNotification(message) { - var i = 0; - while (i < 7) { - await Utils.sleep(1); - await i++; - } - + async verifyPersistToastNotification(message) { + let webAction = await new WebActions(this.app); let currentPosition = await this.getToastNotificationPosition(message); - let curentSize = await this.getToastNotificationSize(message); - await this.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 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); await this.mouseMoveCenter(); } - async verifyNotPersistToastNotification(message) { - let i = 0; - let count = 0; - - while (i < 11) { + async verifyNotPersistToastNotification() { + let i = 0; + while (i < 3) { await Utils.sleep(1); await i++; - } - await this.webAction.verifyNoToastNotificationShow(message); + } + await this.webAction.verifyNoToastNotificationShow(); await this.mouseMoveCenter(); } - async verifyNotCloseToastWhenMouseOver(message) { - + async verifyNotCloseToastWhenMouseOver(message) { var i = 0; - while (i < 6) { + while (i < 3) { await Utils.sleep(1); await i++; } + 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); - await this.webAction.verifyToastNotificationShow(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); + await webAction.verifyToastNotificationShow(message); await this.mouseMoveCenter(); } async windowByIndex(index) { await this.app.client.windowByIndex(index); - } - - async getWindowCount() { - return await this.app.client.getWindowCount(); - } + } async getWindowIndexFromTitle(windowTitle) { let winCount = await this.getWindowCount(); @@ -410,14 +423,20 @@ class WindowsActions { await this.app.browserWindow.minimize(); await this.app.browserWindow.restore(); } + + async closeChromeDriver() + { + Utils.killProcess("chromedriver"); + } - async closeChrome() { - Utils.killProcess("chromedriver.exe"); + async closeChromeDriverOnMac() + { + Utils.killProcessOnMac("Electron"); } async getToastNotificationIndex(message) { for (let i = 0; i < 10; i++) { - let winCount = await this.app.client.getWindowCount(); + let winCount = await this.app.client.getWindowCount() if (winCount > 1) { for (let j = 1; j < winCount; j++) { await this.app.client.windowByIndex(j); @@ -482,7 +501,8 @@ class WindowsActions { async verifyWindowFocus(windowTitle) { let index = await this.getWindowIndexFromTitle(windowTitle); await this.windowByIndex(index); - expect(await this.app.browserWindow.isFocused()).toBeTruthy(); + let isFocused = await this.app.browserWindow.isFocused(); + expect(isFocused === true).toBeTruthy(); await this.windowByIndex(0); } @@ -511,62 +531,15 @@ class WindowsActions { return this.app.isRunning(); } - async getToastNotificationIndex(message) { - for (let i = 0; i < 10; i++) { - let winCount = await this.app.client.getWindowCount(); - if (winCount > 1) { - for (let j = 1; j < winCount; j++) { - await this.app.client.windowByIndex(j); - if (await this.app.client.getText(ui.TOAST_MESSAGE_CONTENT) === message) { - return j; - } - } - } - await Utils.sleep(1); - } - return 0; - } - - async getToastNotificationPosition(message) { - let index = await this.getToastNotificationIndex(message); - await this.windowByIndex(index); - let currentPosition = await this.getCurrentPosition(); - await this.windowByIndex(0); - return currentPosition; - } - - async getToastNotificationSize(message) { - let index = await this.getToastNotificationIndex(message); - await this.windowByIndex(index); - let currentSize = await this.getCurrentSize(); - await this.windowByIndex(0); - return currentSize; - } - - async verifyToastNotificationPosition(message, expectedPosition) { - let screen = await this.app.electron.screen.getPrimaryDisplay(); - let screenWidth = screen.size.width; - let screenHeight = screen.size.height; - let currentPosition = await this.getToastNotificationPosition(message); - let curentSize = await this.getToastNotificationSize(message); - switch (expectedPosition) { - case "lower-right": - expect(currentPosition[0] + curentSize[0]).toEqual(screenWidth); - expect(screenHeight - (currentPosition[1] + curentSize[1])).toBeLessThan(100); - break; - case "upper-right": - expect(currentPosition[0] + curentSize[0]).toEqual(screenWidth); - expect(currentPosition[1]).toEqual(0); - break; - case "upper-left": - expect(currentPosition[0]).toEqual(0); - expect(currentPosition[1]).toEqual(0); - break; - case "lower-left": - expect(currentPosition[0]).toEqual(0); - expect(screenHeight - (currentPosition[1] + curentSize[1])).toBeLessThan(100); - break; - } + 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."); + }); } async doAlwaysOnTopOnMac() { @@ -614,6 +587,12 @@ class WindowsActions { } await robot.keyTap('enter'); } + + async blurBrowserWindow() { + await robot.setMouseDelay(200); + await robot.moveMouse(0, 100); + await robot.mouseClick(); + } } module.exports = WindowsActions;