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": {
"bluebird": "3.5.1",
"browserify": "16.2.2",
"chromedriver": "2.40.0",
"chromedriver": "2.41.0",
"cross-env": "5.2.0",
"electron": "3.0.0-beta.8",
"electron-builder": "20.28.1",
"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-rebuild": "1.7.3",
"eslint": "5.0.1",
@@ -115,6 +115,7 @@
"lodash.isequal": "4.5.0",
"lodash.omit": "4.5.0",
"lodash.pick": "4.4.0",
"node-osascript": "2.1.0",
"ref": "1.3.5",
"shell-path": "2.1.0",
"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

@@ -8,9 +8,7 @@ let app;
let windowActions;
let webActions;
!isMac ? describe('Tests for always on top with mult-apps are opened', () => {
let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
describe('Tests for always on top with mult-apps are opened', () => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut();
beforeAll(async (done) => {
@@ -26,11 +24,14 @@ let webActions;
afterAll(async (done) => {
try {
if (isMac) {
await Utils.killProcess("Notes");
await Utils.killProcess("Reminders");
} else {
await Utils.killProcess("notepad.exe");
await Utils.killProcess("mspaint.exe");
await windowActions.openMenu(["Window","Always on Top"]);
}
if (app && app.isRunning()) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
await app.stop();
done();
}
@@ -46,13 +47,19 @@ let webActions;
*/
it('Verify Always on Top options when multiple applications are opened', async (done) => {
try {
await windowActions.openMenu(["Window","Always on Top"]);
await windowActions.setAlwaysOnTop(true);
await webActions.minimizeWindows();
await Utils.openAppInMaximize("C:\\Windows\\notepad.exe");
await Utils.openAppInMaximize("C:\\Windows\\system32\\mspaint.exe");
if (isMac) {
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.clickOutsideWindow();
await windowActions.verifyWindowsOnTop();
await windowActions.verifyWindowsOnTop(true);
//Close and open app again, make sure it's always on top
await app.stop();
@@ -60,10 +67,10 @@ let webActions;
windowActions = await new WindowsActions(app);
webActions = await new WebActions(app);
await windowActions.clickOutsideWindow();
await windowActions.verifyWindowsOnTop();
await windowActions.verifyWindowsOnTop(true);
done();
} catch (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",
MAXIMIZE_BTN: "#title-bar-maximize-button",
MINIMIZE_BTN: "#title-bar-minimize-button",
CLOSE_BUTTON: "button#title-bar-close-button",
MAIN_MENU_ITEM: "#hamburger-menu-button",
SYM_LOGO: "#logo",

View File

@@ -22,11 +22,6 @@ class App {
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);
}

View File

@@ -1,16 +1,26 @@
const childProcess = require('child_process');
const path = require('path');
const fs = require('fs');
const { isMac } = require('../../js/utils/misc');
class Utils {
static async openAppInMaximize(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) {
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) {
return new Promise(resolve => {

View File

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

View File

@@ -76,20 +76,22 @@ class WindowsActions {
async showWindow() {
await this.app.browserWindow.restore();
await this.app.browserWindow.setAlwaysOnTop(true);
}
async clickOutsideWindow() {
await this.setPosition(0, 0);
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();
}
async verifyWindowsOnTop() {
await this.app.browserWindow.isAlwaysOnTop().then(function (isAlwaysOnTop) {
expect(isAlwaysOnTop).toBeTruthy();
})
async verifyWindowsOnTop(value) {
let isAlwaysOnTop = await this.app.browserWindow.isAlwaysOnTop();
if (value) {
await expect(isAlwaysOnTop).toBeTruthy();
} else {
await expect(isAlwaysOnTop).toBeFalsy();
}
}
async menuSearch(element, namevalue) {
@@ -108,6 +110,7 @@ class WindowsActions {
}
async openMenu(arrMenu) {
await Utils.sleep(3);
var arrStep = [];
for (var i = 0; i < arrMenu.length; i++) {
var item = await this.menuSearch(constants.MENU.root, arrMenu[i]);
@@ -120,7 +123,7 @@ class WindowsActions {
async actionForMenus(arrMenu) {
let webAction = await new WebActions(this.app);
await this.app.browserWindow.getBounds().then(async (bounds) => {
await robot.setMouseDelay(100);
await robot.setMouseDelay(500);
let x = bounds.x + 95;
let y = bounds.y + 35;
await robot.moveMouseSmooth(x, y);
@@ -418,8 +421,7 @@ class WindowsActions {
await this.app.browserWindow.restore();
}
async closeChrome()
{
async closeChrome() {
Utils.killProcess("chromedriver.exe");
}
@@ -576,6 +578,34 @@ class WindowsActions {
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;