diff --git a/js/windowMgr.js b/js/windowMgr.js index a461d279..4300242c 100644 --- a/js/windowMgr.js +++ b/js/windowMgr.js @@ -215,7 +215,7 @@ function doCreateMainWindow(initialUrl, initialBounds, isCustomTitleBar) { mainWindow.webContents.send('window-leave-full-screen'); }); - if (initialBounds && !isNodeEnv) { + if (initialBounds) { // maximizes the application if previously maximized if (initialBounds.isMaximized) { mainWindow.maximize(); diff --git a/tests/spectron/full-screen.spectron.js b/tests/spectron/full-screen.spectron.js index c959e152..4e84b60e 100644 --- a/tests/spectron/full-screen.spectron.js +++ b/tests/spectron/full-screen.spectron.js @@ -123,8 +123,8 @@ describe('Tests for Full screen', () => { robot.setMouseDelay(100); let x = bounds.x + 200; let y = bounds.y + 200; - robot.moveMouseSmooth(x, y); - robot.mouseClick(); + robot.moveMouse(x, y); + robot.mouseClick("left"); robot.keyTap('f11'); diff --git a/tests/spectron/resizeWindows.spectron.js b/tests/spectron/resizeWindows.spectron.js index 851d000c..f63a067b 100644 --- a/tests/spectron/resizeWindows.spectron.js +++ b/tests/spectron/resizeWindows.spectron.js @@ -1,44 +1,35 @@ const Application = require('./spectronSetup'); -const robot = require('robotjs'); const {isMac} = require('../../js/utils/misc'); +const WindowsActions = require('./spectronWindowsActions'); let app = new Application({}); -let defaultWidth; -let defaultHeight; +let windowActions; !isMac ? describe('Tests for Resizing windows', () => { 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(); + windowActions = await new WindowsActions(app); done(); - }).catch((err) => { + } catch(err) { done.fail(new Error(`Unable to start application error: ${err}`)); - }); + }; }); - afterAll((done) => { - if (app && app.isRunning()) { - // resize to default size - app.browserWindow.getBounds().then((bounds) => { - let x = bounds.x - (defaultWidth - bounds.width); - let y = bounds.y - (defaultHeight - bounds.height); - robot.moveMouse(bounds.x, bounds.y); - robot.mouseToggle("down"); - robot.dragMouse(x, y); - robot.mouseToggle("up"); - }) - //close app - jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; - app.stop().then(() => { + afterAll(async (done) => { + try { + if (app && app.isRunning()) { + jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; + await app.stop(); done(); - }).catch((err) => { - done(); - }); - } + } + } catch (err) { + done.fail(new Error(`Failed at post-condition: ${err}`)); + }; }); /** @@ -46,24 +37,13 @@ let defaultHeight; * TC-ID: 3028239 * Cover scenarios in AVT-768 */ - it('should be minimized up to 300px', (done) => { - app.browserWindow.getBounds().then((bounds) => { - defaultHeight = bounds.height; - defaultWidth = bounds.width; - let x = bounds.x + bounds.width; - let y = bounds.y + bounds.height; - robot.setMouseDelay(500); - robot.moveMouse(bounds.x, bounds.y); - robot.mouseToggle("down"); - robot.dragMouse(x, y); - robot.mouseToggle("up"); - return app.browserWindow.getBounds().then((bounds) => { - const data = {x: bounds.width, y: bounds.height}; - expect(data).toEqual({x: 300, y: 300}); - done(); - }).catch((err) => { - done.fail(new Error(`failed to minimize window to 300 px with error: ${err}`)); - }) - }); + it('Should be minimized up to 300px', async (done) => { + try { + await windowActions.resizeWindows(0, 0); + expect([ 300, 300 ]).toEqual(await windowActions.getCurrentSize()); + done(); + } catch (err) { + done.fail(new Error(`failed to minimize window to 300 px with error: ${err}`)); + } }); }) : describe.skip(); \ No newline at end of file diff --git a/tests/spectron/saveLayout.spectron.js b/tests/spectron/saveLayout.spectron.js new file mode 100644 index 00000000..cd1baca0 --- /dev/null +++ b/tests/spectron/saveLayout.spectron.js @@ -0,0 +1,74 @@ +const Application = require('./spectronSetup'); +const WindowsActions = require('./spectronWindowsActions'); +const WebActions = require('./spectronWebActions'); +const { isMac } = require('../../js/utils/misc'); + +let app; +let windowActions; +let webActions; + +!isMac ? describe('Tests for saved layout', () => { + + let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; + jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut(); + + beforeAll(async (done) => { + try { + app = await new Application({}).startApplication(); + windowActions = await new WindowsActions(app); + done(); + } catch(err) { + done.fail(new Error(`Unable to start application error: ${err}`)); + }; + }); + + afterAll(async (done) => { + try { + if (app && app.isRunning()) { + jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; + await app.stop(); + done(); + } + } catch (err) { + done.fail(new Error(`Failed at post-condition: ${err}`)); + }; + }); + + /** + * Keep size and position of the windows in previous session + * TC-ID: 2915948 + * Cover scenarios in AVT-914 + */ + it('Keep size and position of the windows in previous session', async (done) => { + try { + var defaultPosition = await windowActions.getCurrentPosition(); + var defaultSize = await windowActions.getCurrentSize(); + + // Size and position of previos session keep after resizing and dragging + await windowActions.setPosition(defaultPosition[0], 20); + await windowActions.setSize(defaultSize[0] - 100, defaultSize[0] - 100); + await windowActions.sleep(1000); // Sleep 1s after resizing + var previousPosition = await windowActions.getCurrentPosition(); + var previousSize = await windowActions.getCurrentSize(); + await app.stop(); + app = await new Application({}).startApplication({defaultSize: false, defaultPosition: false}); + windowActions = await new WindowsActions(app); + webActions = await new WebActions(app); + expect(previousPosition).toEqual(await windowActions.getCurrentPosition()); + expect(previousSize).toEqual(await windowActions.getCurrentSize()); + + // Size and position of previous session keep after maximizing + await webActions.maximizeWindows(); + await windowActions.sleep(1000); // Sleep 1s after resizing + previousSize = await windowActions.getCurrentSize(); + await app.stop(); + app = await new Application({}).startApplication({defaultSize: false, defaultPosition: false}); + windowActions = await new WindowsActions(app); + webActions = await new WebActions(app); + expect(previousSize).toEqual(await windowActions.getCurrentSize()); + done(); + } catch(err) { + done.fail(new Error(`Fail to keep size and position of the windows in previous session with error: ${err}`)); + }; + }); +}) : describe.skip(); diff --git a/tests/spectron/spectronConstants.js b/tests/spectron/spectronConstants.js index 458def36..cc988e5c 100644 --- a/tests/spectron/spectronConstants.js +++ b/tests/spectron/spectronConstants.js @@ -7,4 +7,7 @@ module.exports = { SEARCH_LIBRARY_PATH_MAC: "node_modules/electron/dist/Electron.app/Contents/library", SEARCH_LIBRARY_PATH_WIN: "node_modules/electron/dist/library", -}; \ No newline at end of file + + TESTED_HOST: "https://cip4-qa.symphony.com/", +}; + diff --git a/tests/spectron/spectronInterfaces.js b/tests/spectron/spectronInterfaces.js new file mode 100644 index 00000000..b435d9e1 --- /dev/null +++ b/tests/spectron/spectronInterfaces.js @@ -0,0 +1,8 @@ +module.exports= { + + // Title bar + TITLE_BAR: "#title-bar", + MAXIMIZE_BTN: "#title-bar-maximize-button", + + SYM_LOGO: "#logo" +}; \ No newline at end of file diff --git a/tests/spectron/spectronSetup.js b/tests/spectron/spectronSetup.js index de651a09..478dd55d 100644 --- a/tests/spectron/spectronSetup.js +++ b/tests/spectron/spectronSetup.js @@ -4,6 +4,7 @@ const fs = require('fs'); const { isMac, isWindowsOS } = require('../../js/utils/misc'); const ncp = require('ncp').ncp; const constants = require('./spectronConstants.js'); +const ui = require('./spectronInterfaces.js'); class App { @@ -29,19 +30,35 @@ class App { this.app = new Application(this.options); } - - startApplication(configurations) { - return this.app.start().then((app) => { - if (configurations) - { - if (configurations.alwaysOnTop) { - app.browserWindow.setAlwaysOnTop(true); + + async startApplication(configurations) { + try { + this.app = await this.app.start(); + await this.app.client.waitForVisible(ui.SYM_LOGO, require('./spectronSetup').getTimeOut()); + await this.app.browserWindow.minimize(); + await this.app.browserWindow.restore(); + if (configurations) { + if ((typeof configurations.alwaysOnTop !== "undefined") && (configurations.alwaysOnTop === false)) { + await this.app.browserWindow.setAlwaysOnTop(false); + } else { + await this.app.browserWindow.setAlwaysOnTop(true); + } + if (configurations.testedHost) { + await this.app.client.waitUntilWindowLoaded().url(configurations.testedHost); } } - return app; - }).catch((err) => { + + if ((typeof configurations === "undefined") || (typeof configurations.defaultSize === "undefined") || (configurations.defaultSize === true)) { + await this.app.browserWindow.setSize(900, 900); + } + if ((typeof configurations === "undefined") || (typeof configurations.defaultPosition === "undefined") || (configurations.defaultPosition === true)) { + await this.app.browserWindow.center(); + } + + return this.app; + } catch (err) { throw new Error("Unable to start application " + err); - }); + }; } static getAppPath() { diff --git a/tests/spectron/spectronWebActions.js b/tests/spectron/spectronWebActions.js new file mode 100644 index 00000000..a04098d4 --- /dev/null +++ b/tests/spectron/spectronWebActions.js @@ -0,0 +1,20 @@ +const ui = require('./spectronInterfaces.js'); + +class WebActions { + constructor(app) { + this.app = app; + } + + async clickMaximizeButton(){ + await this.app.client.waitForVisible(ui.MAXIMIZE_BTN, 10000).click(ui.MAXIMIZE_BTN); + } + + async maximizeWindows() { + await this.clickMaximizeButton(); + await this.app.browserWindow.isMaximized().then(function (maximized) { + expect(maximized).toBeTruthy(); + }) + } +} + +module.exports = WebActions; diff --git a/tests/spectron/spectronWindowsActions.js b/tests/spectron/spectronWindowsActions.js new file mode 100644 index 00000000..89425ad6 --- /dev/null +++ b/tests/spectron/spectronWindowsActions.js @@ -0,0 +1,54 @@ +const robot = require('robotjs'); + +class WindowsActions { + constructor(app) { + this.app = app; + } + + async getCurrentSize() { + return this.app.browserWindow.getSize(); + } + + async setSize(width, height) { + await this.app.browserWindow.setSize(width, height); + } + + async resizeWindows(width, height) { + await this.app.browserWindow.getBounds().then((bounds) => { + let x = bounds.x + (bounds.width - width); + let y = bounds.y + (bounds.height - height); + robot.setMouseDelay(500); + robot.moveMouse(bounds.x, bounds.y); + robot.mouseToggle("down"); + robot.dragMouse(x, y); + robot.mouseToggle("up"); + }) + } + + async getCurrentPosition() { + return this.app.browserWindow.getPosition(); + } + + async setPosition(x, y) { + await this.app.browserWindow.setPosition(x, y); + } + + async dragWindows(x, y) { + await this.app.browserWindow.getBounds().then((bounds) => { + robot.setMouseDelay(500); + robot.moveMouse(bounds.x + 200, bounds.y + 10); + robot.mouseToggle("down"); + robot.moveMouse(bounds.x + 205, bounds.y + 10); // Workaround to make this keyword works properly, refer: https://github.com/octalmage/robotjs/issues/389 + robot.dragMouse(x + 205, y + 10); + robot.mouseToggle("up"); + }) + } + + async sleep(ms){ + return new Promise(resolve=>{ + setTimeout(resolve,ms) + }) + } +} + +module.exports = WindowsActions; diff --git a/tests/spectron/zoom-in-zoom-out.spectron.js b/tests/spectron/zoom-in-zoom-out.spectron.js index f2efb3c0..54ee8e03 100644 --- a/tests/spectron/zoom-in-zoom-out.spectron.js +++ b/tests/spectron/zoom-in-zoom-out.spectron.js @@ -41,6 +41,16 @@ describe('Tests for Zoom in and Zoom out', () => { } afterAll((done) => { + // Get it back normal size + if (!isMac) { + for (let i = 0; i < 4; i++) { + robot.keyToggle('+', 'down', ['control', 'shift']); + } + robot.keyToggle('+', 'up'); + robot.keyToggle('control', 'up'); + robot.keyToggle('shift', 'up'); + } + if (app && app.isRunning()) { jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; app.client.getWindowCount().then((count) => { @@ -124,7 +134,7 @@ describe('Tests for Zoom in and Zoom out', () => { robot.setMouseDelay(100); let x = bounds.x + 200; let y = bounds.y + 200; - robot.moveMouseSmooth(x, y); + robot.moveMouse(x, y); robot.mouseClick(); robot.keyToggle('0', 'down', ['control']); @@ -174,7 +184,7 @@ describe('Tests for Zoom in and Zoom out', () => { robot.setMouseDelay(100); let x = bounds.x + 200; let y = bounds.y + 200; - robot.moveMouseSmooth(x, y); + robot.moveMouse(x, y); robot.mouseClick(); robot.keyToggle('0', 'down', ['control']);