Merge branch 'master' of github.com:symphonyoss/SymphonyElectron

This commit is contained in:
Vishwas Shashidhar
2018-09-06 11:45:17 +05:30
8 changed files with 109 additions and 254 deletions

View File

@@ -77,12 +77,12 @@
"devDependencies": { "devDependencies": {
"bluebird": "3.5.1", "bluebird": "3.5.1",
"browserify": "16.2.2", "browserify": "16.2.2",
"chromedriver": "2.40.0", "chromedriver": "2.41.0",
"cross-env": "5.2.0", "cross-env": "5.2.0",
"electron": "3.0.0-beta.8", "electron": "3.0.0-beta.8",
"electron-builder": "20.28.1", "electron-builder": "20.28.1",
"electron-builder-squirrel-windows": "12.3.0", "electron-builder-squirrel-windows": "12.3.0",
"electron-chromedriver": "2.0.0", "electron-chromedriver": "3.0.0-beta.1",
"electron-packager": "12.1.0", "electron-packager": "12.1.0",
"electron-rebuild": "1.7.3", "electron-rebuild": "1.7.3",
"eslint": "5.0.1", "eslint": "5.0.1",
@@ -115,6 +115,7 @@
"lodash.isequal": "4.5.0", "lodash.isequal": "4.5.0",
"lodash.omit": "4.5.0", "lodash.omit": "4.5.0",
"lodash.pick": "4.4.0", "lodash.pick": "4.4.0",
"node-osascript": "2.1.0",
"ref": "1.3.5", "ref": "1.3.5",
"shell-path": "2.1.0", "shell-path": "2.1.0",
"winreg": "1.2.4" "winreg": "1.2.4"

View File

@@ -1,190 +0,0 @@
const Application = require('./spectronSetup');
const {isMac} = require('../../js/utils/misc.js');
const robot = require('robotjs');
let app = new Application({});
let configPath;
let mIsAlwaysOnTop;
describe('Tests for Always on top', () => {
let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut();
beforeAll((done) => {
return app.startApplication({alwaysOnTop: false}).then((startedApp) => {
app = startedApp;
getConfigPath().then((config) => {
configPath = config;
done();
}).catch((err) => {
done.fail(new Error(`Unable to start application error: ${err}`));
});
}).catch((err) => {
done.fail(new Error(`Unable to start application error: ${err}`));
});
});
function getConfigPath() {
return new Promise(function (resolve, reject) {
app.client.addCommand('getUserDataPath', function () {
return this.execute(function () {
return require('electron').remote.app.getPath('userData');
})
});
app.client.getUserDataPath().then((userConfigPath) => {
resolve(userConfigPath.value)
}).catch((err) => {
reject(err);
});
});
}
afterAll((done) => {
if (app && app.isRunning()) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
app.stop().then(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
done();
}).catch((err) => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
done.fail(new Error(`alwaysOnTop failed in afterAll with error: ${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) => {
done.fail(new Error(`alwaysOnTop 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(`alwaysOnTop 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(`alwaysOnTop failed in isVisible with error: ${err}`));
});
});
it('should bring the app to front in windows', (done) => {
if (!isMac) {
app.browserWindow.focus();
app.browserWindow.restore();
app.browserWindow.setAlwaysOnTop(true).then(() => {
app.browserWindow.isAlwaysOnTop().then((isOnTop) => {
app.browserWindow.getBounds().then((bounds) => {
robot.setMouseDelay(200);
app.browserWindow.restore().then(() => {
let x = bounds.x + 95;
let y = bounds.y + 35;
robot.moveMouseSmooth(x, y);
robot.mouseClick();
robot.setKeyboardDelay(200);
for (let i = 0; i < 4
; i++) {
robot.keyTap('down');
}
robot.keyTap('enter');
expect(isOnTop).toBeTruthy();
done();
})
});
});
}).catch((err) => {
done.fail(new Error(`alwaysOnTop failed in setAlwaysOnTop with error: ${err}`));
});
} else {
done();
}
});
it('should check is always on top', (done) => {
return Application.readConfig(configPath).then((userData) => {
return app.browserWindow.isAlwaysOnTop().then((isAlwaysOnTop) => {
mIsAlwaysOnTop = isAlwaysOnTop;
if (userData.alwaysOnTop) {
expect(isAlwaysOnTop).toBeTruthy();
done();
} else {
expect(isAlwaysOnTop).toBeFalsy();
done();
}
done();
});
}).catch((err) => {
done.fail(new Error(`alwaysOnTop failed in readConfig with error: ${err}`));
});
});
it('should toggle the always on top property to true', (done) => {
if (isMac) {
robot.setMouseDelay(200);
robot.moveMouse(190, 0);
robot.mouseClick();
// Key tap 7 times as "Always on Top" is in the
// 7th position under view menu item
for (let i = 0; i < 7; i++) {
robot.keyTap('down');
}
robot.keyTap('enter');
done();
} else {
app.browserWindow.getBounds().then((bounds) => {
app.browserWindow.focus();
robot.setMouseDelay(200);
app.browserWindow.restore().then(() => {
let x = bounds.x + 95;
let y = bounds.y + 35;
robot.moveMouseSmooth(x, y);
robot.mouseClick();
// Key tap 4 times as "Always on Top" is in the
// 4th position under window menu item
for (let i = 0; i < 4; i++) {
robot.keyTap('down');
}
robot.keyTap('enter');
done();
});
}).catch((err) => {
done.fail(new Error(`alwaysOnTop failed in getBounds with error: ${err}`));
});
}
});
it('should check is always on top to be true', (done) => {
if (!mIsAlwaysOnTop) {
return app.browserWindow.isAlwaysOnTop().then((isAlwaysOnTop) => {
expect(isAlwaysOnTop).toBeTruthy();
done();
}).catch((err) => {
done.fail(new Error(`alwaysOnTop failed in isAlwaysOnTop with error: ${err}`));
});
} else {
return app.browserWindow.isAlwaysOnTop().then((isAlwaysOnTop) => {
expect(isAlwaysOnTop).toBeFalsy();
done();
}).catch((err) => {
done.fail(new Error(`alwaysOnTop failed in isAlwaysOnTop with error: ${err}`));
});
}
});
});

View File

@@ -2,35 +2,36 @@ const Application = require('./spectronSetup');
const WindowsActions = require('./spectronWindowsActions'); const WindowsActions = require('./spectronWindowsActions');
const WebActions = require('./spectronWebActions'); const WebActions = require('./spectronWebActions');
const Utils = require('./spectronUtils'); const Utils = require('./spectronUtils');
const {isMac} = require('../../js/utils/misc'); const { isMac } = require('../../js/utils/misc');
let app; let app;
let windowActions; let windowActions;
let webActions; let webActions;
!isMac ? describe('Tests for always on top with mult-apps are opened', () => { describe('Tests for always on top with mult-apps are opened', () => {
let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut(); jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut();
beforeAll(async (done) => { beforeAll(async (done) => {
try { try {
app = await new Application({}).startApplication({alwaysOnTop: false}); app = await new Application({}).startApplication({ alwaysOnTop: false });
windowActions = await new WindowsActions(app); windowActions = await new WindowsActions(app);
webActions = await new WebActions(app); webActions = await new WebActions(app);
done(); done();
} catch(err) { } catch (err) {
done.fail(new Error(`Unable to start application error: ${err}`)); done.fail(new Error(`Unable to start application error: ${err}`));
}; };
}); });
afterAll(async (done) => { afterAll(async (done) => {
try { try {
await Utils.killProcess("notepad.exe"); if (isMac) {
await Utils.killProcess("mspaint.exe"); await Utils.killProcess("Notes");
await windowActions.openMenu(["Window","Always on Top"]); await Utils.killProcess("Reminders");
} else {
await Utils.killProcess("notepad.exe");
await Utils.killProcess("mspaint.exe");
}
if (app && app.isRunning()) { if (app && app.isRunning()) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
await app.stop(); await app.stop();
done(); done();
} }
@@ -46,13 +47,19 @@ let webActions;
*/ */
it('Verify Always on Top options when multiple applications are opened', async (done) => { it('Verify Always on Top options when multiple applications are opened', async (done) => {
try { try {
await windowActions.openMenu(["Window","Always on Top"]); await windowActions.setAlwaysOnTop(true);
await webActions.minimizeWindows(); await webActions.minimizeWindows();
await Utils.openAppInMaximize("C:\\Windows\\notepad.exe"); if (isMac) {
await Utils.openAppInMaximize("C:\\Windows\\system32\\mspaint.exe"); await Utils.openAppInMaximize("Notes");
await Utils.openAppInMaximize("Reminders");
await Utils.sleep(10);
} else {
await Utils.openAppInMaximize("notepad.exe");
await Utils.openAppInMaximize("mspaint.exe");
}
await windowActions.showWindow(); await windowActions.showWindow();
await windowActions.clickOutsideWindow(); await windowActions.clickOutsideWindow();
await windowActions.verifyWindowsOnTop(); await windowActions.verifyWindowsOnTop(true);
//Close and open app again, make sure it's always on top //Close and open app again, make sure it's always on top
await app.stop(); await app.stop();
@@ -60,10 +67,10 @@ let webActions;
windowActions = await new WindowsActions(app); windowActions = await new WindowsActions(app);
webActions = await new WebActions(app); webActions = await new WebActions(app);
await windowActions.clickOutsideWindow(); await windowActions.clickOutsideWindow();
await windowActions.verifyWindowsOnTop(); await windowActions.verifyWindowsOnTop(true);
done(); done();
} catch(err) { } catch (err) {
done.fail(new Error(`Fail to keep Always on Top options when multiple applications are opened with error: ${err}`)); done.fail(new Error(`Fail to keep Always on Top options when multiple applications are opened with error: ${err}`));
}; };
}); });
}): describe.skip(); });

View File

@@ -2,6 +2,7 @@ module.exports= {
// Title bar // Title bar
TITLE_BAR: "#title-bar", TITLE_BAR: "#title-bar",
MAXIMIZE_BTN: "#title-bar-maximize-button", MAXIMIZE_BTN: "#title-bar-maximize-button",
MINIMIZE_BTN: "#title-bar-minimize-button",
CLOSE_BUTTON: "button#title-bar-close-button", CLOSE_BUTTON: "button#title-bar-close-button",
MAIN_MENU_ITEM: "#hamburger-menu-button", MAIN_MENU_ITEM: "#hamburger-menu-button",
SYM_LOGO: "#logo", SYM_LOGO: "#logo",

View File

@@ -22,11 +22,6 @@ class App {
App.copyLibraries(constants.SEARCH_LIBRARY_PATH_MAC); App.copyLibraries(constants.SEARCH_LIBRARY_PATH_MAC);
} }
if (isWindowsOS) {
App.copyConfigPath(constants.ELECTRON_GLOBAL_CONFIG_PATH_WIN);
//App.copyLibraries(constants.SEARCH_LIBRARY_PATH_WIN);
}
this.app = new Application(this.options); this.app = new Application(this.options);
} }

View File

@@ -1,15 +1,25 @@
const childProcess = require('child_process'); const childProcess = require('child_process');
const path = require('path'); const path = require('path');
const fs = require('fs'); const fs = require('fs');
const { isMac } = require('../../js/utils/misc');
class Utils { class Utils {
static async openAppInMaximize(appPath) { static async openAppInMaximize(appPath) {
await childProcess.exec('start /MAX ' + appPath); if (isMac) {
const osascript = require('node-osascript');
await osascript.execute('if application "' + appPath + '" is running then \n do shell script ("pkill -9 ' + appPath + '*") \n end if \n delay 5 \n tell application "' + appPath + '" \n activate \n tell window 1 \n set zoomed to true \n end tell \n end tell');
} else {
await childProcess.exec('start /MAX ' + appPath);
}
} }
static async killProcess(processName) { static async killProcess(processName) {
await childProcess.exec('taskkill /f /t /im ' + processName); if (isMac) {
const osascript = require('node-osascript');
await osascript.execute('if application "' + processName + '" is running then \n do shell script ("pkill -9 ' + processName + '*") \n end if \n delay 5');
} else {
await childProcess.exec('taskkill /f /t /im ' + processName);
}
} }
static async sleep(second) { static async sleep(second) {
@@ -42,8 +52,8 @@ class Utils {
} }
static execPromise(command) { static execPromise(command) {
return new Promise(function(resolve, reject) { return new Promise(function (resolve, reject) {
childProcess.exec(command, (error, stdout, stderr) => { childProcess.exec(command, (error, stdout, stderr) => {
resolve(stdout.trim()); resolve(stdout.trim());
}); });
}); });

View File

@@ -2,6 +2,7 @@ const ui = require('./spectronInterfaces.js');
const constants = require('./spectronConstants.js'); const constants = require('./spectronConstants.js');
const Utils = require('./spectronUtils'); const Utils = require('./spectronUtils');
const WindowsActions = require('./spectronWindowsActions'); const WindowsActions = require('./spectronWindowsActions');
const { isMac } = require('../../js/utils/misc');
class WebActions { class WebActions {
constructor(app) { constructor(app) {
@@ -24,10 +25,10 @@ class WebActions {
} }
async minimizeWindows() { async minimizeWindows() {
await this.clickMinimizeButton(); await this.app.browserWindow.minimize();
await this.app.browserWindow.isMinimized().then(function (isMinimized) { await this.app.browserWindow.isMinimized().then(function (isMinimized) {
expect(isMinimized).toBeTruthy(); expect(isMinimized).toBeTruthy();
}) });
} }
async minimizeWindowByClick() { async minimizeWindowByClick() {

View File

@@ -34,7 +34,7 @@ class WindowsActions {
async isElectronProcessRunning() { async isElectronProcessRunning() {
let ret = false; let ret = false;
if (isWindowsOS) { if (isWindowsOS) {
let result = await Utils.execPromise("tasklist | find /i \"electron.exe\""); let result = await Utils.execPromise("tasklist | find /i \"electron.exe\"");
if (result && result.indexOf('electron.exe') > -1) { if (result && result.indexOf('electron.exe') > -1) {
ret = true; ret = true;
} }
@@ -76,20 +76,22 @@ class WindowsActions {
async showWindow() { async showWindow() {
await this.app.browserWindow.restore(); await this.app.browserWindow.restore();
await this.app.browserWindow.setAlwaysOnTop(true);
} }
async clickOutsideWindow() { async clickOutsideWindow() {
await this.setPosition(0, 0); await this.setPosition(0, 0);
let currentSize = await this.getCurrentSize(); let currentSize = await this.getCurrentSize();
await robot.moveMouse(currentSize[0] + 20, currentSize[1] + 20); await robot.moveMouse(currentSize[0] + 20, currentSize[1] - 50);
await robot.mouseClick(); await robot.mouseClick();
} }
async verifyWindowsOnTop() { async verifyWindowsOnTop(value) {
await this.app.browserWindow.isAlwaysOnTop().then(function (isAlwaysOnTop) { let isAlwaysOnTop = await this.app.browserWindow.isAlwaysOnTop();
expect(isAlwaysOnTop).toBeTruthy(); if (value) {
}) await expect(isAlwaysOnTop).toBeTruthy();
} else {
await expect(isAlwaysOnTop).toBeFalsy();
}
} }
async menuSearch(element, namevalue) { async menuSearch(element, namevalue) {
@@ -108,6 +110,7 @@ class WindowsActions {
} }
async openMenu(arrMenu) { async openMenu(arrMenu) {
await Utils.sleep(3);
var arrStep = []; var arrStep = [];
for (var i = 0; i < arrMenu.length; i++) { for (var i = 0; i < arrMenu.length; i++) {
var item = await this.menuSearch(constants.MENU.root, arrMenu[i]); var item = await this.menuSearch(constants.MENU.root, arrMenu[i]);
@@ -120,7 +123,7 @@ class WindowsActions {
async actionForMenus(arrMenu) { async actionForMenus(arrMenu) {
let webAction = await new WebActions(this.app); let webAction = await new WebActions(this.app);
await this.app.browserWindow.getBounds().then(async (bounds) => { await this.app.browserWindow.getBounds().then(async (bounds) => {
await robot.setMouseDelay(100); await robot.setMouseDelay(500);
let x = bounds.x + 95; let x = bounds.x + 95;
let y = bounds.y + 35; let y = bounds.y + 35;
await robot.moveMouseSmooth(x, y); await robot.moveMouseSmooth(x, y);
@@ -265,7 +268,7 @@ class WindowsActions {
} }
async pressF11() { async pressF11() {
await robot.keyTap('f11'); await robot.keyTap('f11');
} }
async pressCtrlR() { async pressCtrlR() {
@@ -309,25 +312,25 @@ class WindowsActions {
}); });
} }
async clickNotification(x,y) { async clickNotification(x, y) {
await robot.setMouseDelay(100); await robot.setMouseDelay(100);
await robot.moveMouseSmooth(x, y); await robot.moveMouseSmooth(x, y);
await robot.moveMouse(x, y); await robot.moveMouse(x, y);
await robot.mouseClick(); await robot.mouseClick();
} }
async mouseMoveNotification(x,y) { async mouseMoveNotification(x, y) {
await robot.setMouseDelay(50); await robot.setMouseDelay(50);
await robot.moveMouseSmooth(x, y); await robot.moveMouseSmooth(x, y);
await robot.moveMouse(x, y); await robot.moveMouse(x, y);
} }
async mouseMoveCenter() { async mouseMoveCenter() {
let screen = await this.app.electron.screen.getAllDisplays(); let screen = await this.app.electron.screen.getAllDisplays();
await this.app.browserWindow.getBounds().then(async (bounds) => { await this.app.browserWindow.getBounds().then(async (bounds) => {
await robot.setMouseDelay(50); await robot.setMouseDelay(50);
let x = screen[0].bounds.width/2; let x = screen[0].bounds.width / 2;
let y = screen[0].bounds.height/2; let y = screen[0].bounds.height / 2;
await robot.moveMouseSmooth(x, y); await robot.moveMouseSmooth(x, y);
await robot.moveMouse(x, y); await robot.moveMouse(x, y);
}); });
@@ -343,9 +346,9 @@ class WindowsActions {
let currentPosition = await this.getToastNotificationPosition(message); let currentPosition = await this.getToastNotificationPosition(message);
let curentSize = await this.getToastNotificationSize(message); let curentSize = await this.getToastNotificationSize(message);
await this.webAction.verifyToastNotificationShow(message); await this.webAction.verifyToastNotificationShow(message);
let x = await (currentPosition[0] + curentSize[0]/2); let x = await (currentPosition[0] + curentSize[0] / 2);
let y = await (currentPosition[1] + curentSize[1]/2); let y = await (currentPosition[1] + curentSize[1] / 2);
await this.clickNotification(x,y); await this.clickNotification(x, y);
await this.mouseMoveCenter(); await this.mouseMoveCenter();
} }
@@ -362,21 +365,21 @@ class WindowsActions {
} }
async verifyNotCloseToastWhenMouseOver(message) { async verifyNotCloseToastWhenMouseOver(message) {
var i = 0; var i = 0;
while (i < 6) { while (i < 6) {
await Utils.sleep(1); await Utils.sleep(1);
await i++; await i++;
} }
let currentPosition = await this.getToastNotificationPosition(message); let currentPosition = await this.getToastNotificationPosition(message);
let curentSize = await this.getToastNotificationSize(message); let curentSize = await this.getToastNotificationSize(message);
let x = await (currentPosition[0] + curentSize[0]/2); let x = await (currentPosition[0] + curentSize[0] / 2);
let y = await (currentPosition[1] + curentSize[1]/2); let y = await (currentPosition[1] + curentSize[1] / 2);
await this.mouseMoveNotification(x,y); await this.mouseMoveNotification(x, y);
await this.webAction.verifyToastNotificationShow(message); await this.webAction.verifyToastNotificationShow(message);
await this.mouseMoveCenter(); await this.mouseMoveCenter();
} }
async windowByIndex(index) { async windowByIndex(index) {
await this.app.client.windowByIndex(index); await this.app.client.windowByIndex(index);
} }
@@ -417,12 +420,11 @@ class WindowsActions {
await this.app.browserWindow.minimize(); await this.app.browserWindow.minimize();
await this.app.browserWindow.restore(); await this.app.browserWindow.restore();
} }
async closeChrome() async closeChrome() {
{
Utils.killProcess("chromedriver.exe"); Utils.killProcess("chromedriver.exe");
} }
async getToastNotificationIndex(message) { async getToastNotificationIndex(message) {
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
let winCount = await this.app.client.getWindowCount(); let winCount = await this.app.client.getWindowCount();
@@ -478,14 +480,14 @@ class WindowsActions {
expect(currentPosition[0]).toEqual(0); expect(currentPosition[0]).toEqual(0);
expect(screenHeight - (currentPosition[1] + curentSize[1])).toBeLessThan(100); expect(screenHeight - (currentPosition[1] + curentSize[1])).toBeLessThan(100);
break; break;
} }
await this.windowByIndex(0); await this.windowByIndex(0);
return 0; return 0;
} }
async getWindowCount() { async getWindowCount() {
return await this.app.client.getWindowCount(); return await this.app.client.getWindowCount();
} }
async verifyWindowFocus(windowTitle) { async verifyWindowFocus(windowTitle) {
let index = await this.getWindowIndexFromTitle(windowTitle); let index = await this.getWindowIndexFromTitle(windowTitle);
@@ -576,6 +578,34 @@ class WindowsActions {
break; break;
} }
} }
async doAlwaysOnTopOnMac() {
await robot.setMouseDelay(500);
await robot.moveMouse(190, 0);
await robot.mouseClick();
// Key tap 7 times as "Always on Top" is in the
// 7th position under view menu item
for (let i = 0; i < 7; i++) {
await robot.keyTap('down');
}
await robot.keyTap('enter');
}
async setAlwaysOnTop(value) {
if (isMac) {
await this.doAlwaysOnTopOnMac();
} else {
await this.openMenu(["Window", "Always on Top"]);
}
let isAlwaysOnTop = await this.app.browserWindow.isAlwaysOnTop();
if (value !== isAlwaysOnTop) {
if (isMac) {
await this.doAlwaysOnTopOnMac();
} else {
await this.openMenu(["Window", "Always on Top"]);
}
}
}
} }
module.exports = WindowsActions; module.exports = WindowsActions;