This commit is contained in:
thaisym1912 2018-09-06 11:51:05 +07:00 committed by Vishwas Shashidhar
parent 4d98f59deb
commit ce5b6a8409
8 changed files with 108 additions and 253 deletions

View File

@ -89,7 +89,7 @@
"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",
@ -128,6 +128,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

@ -2,35 +2,36 @@ const Application = require('./spectronSetup');
const WindowsActions = require('./spectronWindowsActions');
const WebActions = require('./spectronWebActions');
const Utils = require('./spectronUtils');
const {isMac} = require('../../js/utils/misc');
const { isMac } = require('../../js/utils/misc');
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) => {
try {
app = await new Application({}).startApplication({alwaysOnTop: false});
app = await new Application({}).startApplication({ alwaysOnTop: false });
windowActions = await new WindowsActions(app);
webActions = await new WebActions(app);
done();
} catch(err) {
} catch (err) {
done.fail(new Error(`Unable to start application error: ${err}`));
};
});
afterAll(async (done) => {
try {
await Utils.killProcess("notepad.exe");
await Utils.killProcess("mspaint.exe");
await windowActions.openMenu(["Window","Always on Top"]);
if (isMac) {
await Utils.killProcess("Notes");
await Utils.killProcess("Reminders");
} else {
await Utils.killProcess("notepad.exe");
await Utils.killProcess("mspaint.exe");
}
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) {
} 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,15 +1,25 @@
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) {
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) {
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) {
@ -42,8 +52,8 @@ class Utils {
}
static execPromise(command) {
return new Promise(function(resolve, reject) {
childProcess.exec(command, (error, stdout, stderr) => {
return new Promise(function (resolve, reject) {
childProcess.exec(command, (error, stdout, stderr) => {
resolve(stdout.trim());
});
});

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

@ -34,7 +34,7 @@ class WindowsActions {
async isElectronProcessRunning() {
let ret = false;
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) {
ret = true;
}
@ -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);
@ -265,7 +268,7 @@ class WindowsActions {
}
async pressF11() {
await robot.keyTap('f11');
await robot.keyTap('f11');
}
async pressCtrlR() {
@ -309,25 +312,25 @@ class WindowsActions {
});
}
async clickNotification(x,y) {
await robot.setMouseDelay(100);
async clickNotification(x, y) {
await robot.setMouseDelay(100);
await robot.moveMouseSmooth(x, y);
await robot.moveMouse(x, y);
await robot.mouseClick();
await robot.mouseClick();
}
async mouseMoveNotification(x,y) {
await robot.setMouseDelay(50);
async mouseMoveNotification(x, y) {
await robot.setMouseDelay(50);
await robot.moveMouseSmooth(x, y);
await robot.moveMouse(x, y);
await robot.moveMouse(x, y);
}
async mouseMoveCenter() {
let screen = await this.app.electron.screen.getAllDisplays();
await this.app.browserWindow.getBounds().then(async (bounds) => {
await robot.setMouseDelay(50);
let x = screen[0].bounds.width/2;
let y = screen[0].bounds.height/2;
let x = screen[0].bounds.width / 2;
let y = screen[0].bounds.height / 2;
await robot.moveMouseSmooth(x, y);
await robot.moveMouse(x, y);
});
@ -343,9 +346,9 @@ class WindowsActions {
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 x = await (currentPosition[0] + curentSize[0] / 2);
let y = await (currentPosition[1] + curentSize[1] / 2);
await this.clickNotification(x, y);
await this.mouseMoveCenter();
}
@ -362,21 +365,21 @@ class WindowsActions {
}
async verifyNotCloseToastWhenMouseOver(message) {
var i = 0;
while (i < 6) {
await Utils.sleep(1);
await i++;
}
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 this.webAction.verifyToastNotificationShow(message);
await this.mouseMoveCenter();
}
async windowByIndex(index) {
await this.app.client.windowByIndex(index);
}
@ -417,12 +420,11 @@ class WindowsActions {
await this.app.browserWindow.minimize();
await this.app.browserWindow.restore();
}
async closeChrome()
{
async closeChrome() {
Utils.killProcess("chromedriver.exe");
}
async getToastNotificationIndex(message) {
for (let i = 0; i < 10; i++) {
let winCount = await this.app.client.getWindowCount();
@ -478,14 +480,14 @@ class WindowsActions {
expect(currentPosition[0]).toEqual(0);
expect(screenHeight - (currentPosition[1] + curentSize[1])).toBeLessThan(100);
break;
}
}
await this.windowByIndex(0);
return 0;
}
}
async getWindowCount() {
return await this.app.client.getWindowCount();
}
}
async verifyWindowFocus(windowTitle) {
let index = await this.getWindowIndexFromTitle(windowTitle);
@ -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;