2018-08-01 00:04:45 +07:00
|
|
|
const robot = require('robotjs');
|
2018-08-01 16:13:57 +07:00
|
|
|
const constants = require('./spectronConstants.js');
|
2018-08-02 17:23:46 +07:00
|
|
|
const Utils = require('./spectronUtils.js');
|
|
|
|
|
const fs = require('fs');
|
2018-08-01 21:50:48 +07:00
|
|
|
const WebActions = require('./spectronWebActions.js')
|
2018-08-01 16:13:57 +07:00
|
|
|
|
2018-08-01 00:04:45 +07:00
|
|
|
class WindowsActions {
|
|
|
|
|
constructor(app) {
|
|
|
|
|
this.app = app;
|
2018-08-01 21:50:48 +07:00
|
|
|
this.webAction = new WebActions(app);
|
2018-08-01 00:04:45 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2018-08-13 15:54:04 +07:00
|
|
|
// Plus 2 pixels to make sure this function works well on MAC
|
|
|
|
|
robot.moveMouse(bounds.x + 2, bounds.y + 2);
|
2018-08-01 00:04:45 +07:00
|
|
|
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");
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-13 15:54:55 +07:00
|
|
|
async showWindow() {
|
2018-08-07 19:49:42 +07:00
|
|
|
await this.app.browserWindow.restore();
|
|
|
|
|
await this.app.browserWindow.setAlwaysOnTop(true);
|
2018-08-01 21:50:48 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async clickOutsideWindow() {
|
|
|
|
|
await this.setPosition(0, 0);
|
2018-08-13 15:54:55 +07:00
|
|
|
let currentSize = await this.getCurrentSize();
|
2018-08-01 21:50:48 +07:00
|
|
|
await robot.moveMouse(currentSize[0] + 20, currentSize[1] + 20);
|
|
|
|
|
await robot.mouseClick();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async verifyWindowsOnTop() {
|
|
|
|
|
await this.app.browserWindow.isAlwaysOnTop().then(function (isAlwaysOnTop) {
|
|
|
|
|
expect(isAlwaysOnTop).toBeTruthy();
|
2018-08-01 00:04:45 +07:00
|
|
|
})
|
2018-08-13 15:54:55 +07:00
|
|
|
}
|
2018-08-02 17:23:46 +07:00
|
|
|
|
|
|
|
|
async verifyLogExported() {
|
|
|
|
|
let expected = false;
|
|
|
|
|
let path = await Utils.getFolderPath('Downloads');
|
2018-08-13 15:54:55 +07:00
|
|
|
let listFiles = Utils.getFiles(path);
|
2018-08-02 17:23:46 +07:00
|
|
|
listFiles.forEach(function (fileName) {
|
|
|
|
|
if (fileName.indexOf(constants.LOG_FILENAME_PREFIX) > -1) {
|
|
|
|
|
expected = true;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
await expect(expected).toBeTruthy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async deleteAllLogFiles() {
|
|
|
|
|
let path = await Utils.getFolderPath('Downloads');
|
2018-08-13 15:54:55 +07:00
|
|
|
let listFiles = Utils.getFiles(path);
|
2018-08-02 17:23:46 +07:00
|
|
|
await listFiles.forEach(function (fileName) {
|
|
|
|
|
if (fileName.indexOf(constants.LOG_FILENAME_PREFIX) > -1) {
|
|
|
|
|
fs.unlinkSync(path.concat("\\", fileName));
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
2018-08-01 16:13:57 +07:00
|
|
|
|
2018-08-07 19:49:42 +07:00
|
|
|
async verifyMinimizeWindows() {
|
|
|
|
|
await this.app.browserWindow.isMinimized().then(async function (minimized) {
|
|
|
|
|
await expect(minimized).toBeTruthy();
|
|
|
|
|
}).catch((err) => {
|
|
|
|
|
console.log(err.name);
|
|
|
|
|
});;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-01 16:13:57 +07:00
|
|
|
async selectMinimizeOnClose() {
|
|
|
|
|
await this.app.browserWindow.getBounds().then(async (bounds) => {
|
|
|
|
|
await robot.setMouseDelay(100);
|
|
|
|
|
let x = bounds.x + 95;
|
|
|
|
|
let y = bounds.y + 35;
|
|
|
|
|
await robot.moveMouseSmooth(x, y);
|
|
|
|
|
await robot.moveMouse(x, y);
|
|
|
|
|
await robot.mouseClick();
|
|
|
|
|
await this.webAction.openApplicationMenuByClick();
|
|
|
|
|
await robot.setKeyboardDelay(1000);
|
|
|
|
|
await robot.keyTap('enter');
|
|
|
|
|
await robot.keyTap('down');
|
|
|
|
|
await robot.keyTap('down');
|
|
|
|
|
await robot.keyTap('right');
|
|
|
|
|
for (let i = 0; i < 4; i++) {
|
|
|
|
|
await robot.keyTap('down');
|
|
|
|
|
}
|
|
|
|
|
await robot.keyTap('enter');
|
|
|
|
|
});
|
2018-08-13 15:54:55 +07:00
|
|
|
}
|
2018-08-07 19:49:42 +07:00
|
|
|
|
|
|
|
|
async menuSearch(element, namevalue) {
|
2018-08-13 15:54:55 +07:00
|
|
|
if (element.name == namevalue) {
|
2018-08-07 19:49:42 +07:00
|
|
|
return await element;
|
|
|
|
|
}
|
|
|
|
|
else if (element.items !== undefined) {
|
2018-08-13 15:54:55 +07:00
|
|
|
let result;
|
2018-08-07 19:49:42 +07:00
|
|
|
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 actionForMenus(arrMenu) {
|
|
|
|
|
await this.app.browserWindow.getBounds().then(async (bounds) => {
|
|
|
|
|
await robot.setMouseDelay(100);
|
|
|
|
|
let x = bounds.x + 95;
|
|
|
|
|
let y = bounds.y + 35;
|
|
|
|
|
await robot.moveMouseSmooth(x, y);
|
|
|
|
|
await robot.moveMouse(x, y);
|
|
|
|
|
await robot.mouseClick();
|
|
|
|
|
await this.webAction.openApplicationMenuByClick();
|
|
|
|
|
await robot.setKeyboardDelay(200);
|
|
|
|
|
await robot.keyTap('enter');
|
|
|
|
|
for (var i = 0; i < arrMenu.length; i++) {
|
|
|
|
|
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 verifyMinimizeWindows() {
|
|
|
|
|
await this.app.browserWindow.isMinimized().then(async function (minimized) {
|
|
|
|
|
await expect(minimized).toBeTruthy();
|
|
|
|
|
}).catch((err) => {
|
2018-08-13 15:54:55 +07:00
|
|
|
console.log("error:" + err.name);
|
2018-08-07 19:49:42 +07:00
|
|
|
});;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 pressCtrlW() {
|
|
|
|
|
await robot.keyToggle('w', 'down', ['control']);
|
|
|
|
|
await robot.keyToggle('w', 'up', ['control']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async pressCtrlM() {
|
|
|
|
|
await robot.keyToggle('m', 'down', ['control']);
|
|
|
|
|
await robot.keyToggle('m', 'up', ['control']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async pressCtrlR() {
|
|
|
|
|
await robot.keyToggle('r', 'down', ['control']);
|
|
|
|
|
await robot.keyToggle('r', 'up', ['control']);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-13 15:54:55 +07:00
|
|
|
async focusWindow() {
|
2018-08-07 19:49:42 +07:00
|
|
|
this.app.browserWindow.focus();
|
|
|
|
|
this.app.browserWindow.setAlwaysOnTop(true);
|
2018-08-13 15:54:55 +07:00
|
|
|
}
|
2018-08-07 19:49:42 +07:00
|
|
|
|
|
|
|
|
async openMenu(arrMenu) {
|
2018-08-13 15:54:55 +07:00
|
|
|
let arrStep = [];
|
2018-08-07 19:49:42 +07:00
|
|
|
for (var i = 0; i < arrMenu.length; i++) {
|
|
|
|
|
var item = await this.menuSearch(constants.MENU.root, arrMenu[i]);
|
2018-08-13 15:54:55 +07:00
|
|
|
await arrStep.push(item);
|
|
|
|
|
}
|
2018-08-07 19:49:42 +07:00
|
|
|
await this.actionForMenus(arrStep);
|
|
|
|
|
return arrStep;
|
2018-08-13 15:54:55 +07:00
|
|
|
}
|
2018-08-07 19:49:42 +07:00
|
|
|
|
2018-08-13 15:54:55 +07:00
|
|
|
async reload() {
|
2018-08-07 19:49:42 +07:00
|
|
|
await this.app.browserWindow.getBounds().then(async (bounds) => {
|
|
|
|
|
await robot.setMouseDelay(100);
|
|
|
|
|
let x = bounds.x + 95;
|
|
|
|
|
let y = bounds.y + 200;
|
|
|
|
|
await robot.moveMouseSmooth(x, y);
|
|
|
|
|
await robot.moveMouse(x, y);
|
|
|
|
|
await robot.mouseClick('right');
|
|
|
|
|
await robot.setKeyboardDelay(2000);
|
2018-08-13 15:54:55 +07:00
|
|
|
await robot.keyTap('right');
|
|
|
|
|
await robot.keyTap('down');
|
|
|
|
|
await robot.keyTap('enter');
|
|
|
|
|
}).catch((err1) => {
|
|
|
|
|
console.log("Message:" + err1);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async clickNotification() {
|
|
|
|
|
let screen = await this.app.electron.screen.getAllDisplays();
|
|
|
|
|
await this.app.browserWindow.getBounds().then(async (bounds) => {
|
2018-08-08 14:30:44 +07:00
|
|
|
await robot.setMouseDelay(50);
|
2018-08-13 15:54:55 +07:00
|
|
|
let x = screen[0].bounds.width - 50;
|
2018-08-07 19:49:42 +07:00
|
|
|
let y = screen[0].bounds.height - 100;
|
|
|
|
|
await robot.moveMouseSmooth(x, y);
|
2018-08-13 15:54:55 +07:00
|
|
|
await robot.moveMouse(x, y);
|
|
|
|
|
await robot.mouseClick();
|
|
|
|
|
});
|
2018-08-07 19:49:42 +07:00
|
|
|
}
|
|
|
|
|
|
2018-08-13 15:54:55 +07:00
|
|
|
async mouseMoveNotification() {
|
|
|
|
|
let screen = await this.app.electron.screen.getAllDisplays();
|
|
|
|
|
await this.app.browserWindow.getBounds().then(async (bounds) => {
|
2018-08-08 14:30:44 +07:00
|
|
|
await robot.setMouseDelay(50);
|
2018-08-13 15:54:55 +07:00
|
|
|
let x = screen[0].bounds.width - 50;
|
2018-08-07 19:49:42 +07:00
|
|
|
let y = screen[0].bounds.height - 100;
|
|
|
|
|
await robot.moveMouseSmooth(x, y);
|
2018-08-13 15:54:55 +07:00
|
|
|
await robot.moveMouse(x, y);
|
|
|
|
|
});
|
2018-08-07 19:49:42 +07:00
|
|
|
}
|
|
|
|
|
|
2018-08-13 15:54:55 +07:00
|
|
|
async mouseMoveCenter() {
|
|
|
|
|
let screen = await this.app.electron.screen.getAllDisplays();
|
|
|
|
|
await this.app.browserWindow.getBounds().then(async (bounds) => {
|
2018-08-08 14:30:44 +07:00
|
|
|
await robot.setMouseDelay(50);
|
2018-08-13 15:54:55 +07:00
|
|
|
let x = screen[0].bounds.width - 500;
|
|
|
|
|
let y = screen[0].bounds.height - 100;
|
|
|
|
|
await robot.moveMouseSmooth(x, y);
|
|
|
|
|
await robot.moveMouse(x, y);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async veriryPersistToastNotification(message) {
|
|
|
|
|
let i = 0;
|
|
|
|
|
while (i < 6) {
|
|
|
|
|
await Utils.sleep(1);
|
2018-08-07 19:49:42 +07:00
|
|
|
await i++;
|
|
|
|
|
}
|
2018-08-08 14:30:44 +07:00
|
|
|
await this.webAction.verifyToastNotificationShow(message);
|
2018-08-13 15:54:55 +07:00
|
|
|
await this.clickNotification();
|
2018-08-07 19:49:42 +07:00
|
|
|
await this.mouseMoveCenter();
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-13 15:54:55 +07:00
|
|
|
async verifyNotPersistToastNotification(message) {
|
|
|
|
|
let i = 0;
|
|
|
|
|
let count = 0;
|
|
|
|
|
|
|
|
|
|
while (i < 11) {
|
|
|
|
|
await Utils.sleep(1);
|
2018-08-07 19:49:42 +07:00
|
|
|
await i++;
|
|
|
|
|
}
|
2018-08-08 14:30:44 +07:00
|
|
|
await this.webAction.verifyNoToastNotificationShow(message);
|
2018-08-07 19:49:42 +07:00
|
|
|
await this.mouseMoveCenter();
|
2018-08-13 15:54:55 +07:00
|
|
|
}
|
2018-08-07 19:49:42 +07:00
|
|
|
|
2018-08-13 15:54:55 +07:00
|
|
|
async verifyNotCloseToastWhenMouseOver(message) {
|
2018-08-08 14:30:44 +07:00
|
|
|
await this.mouseMoveNotification();
|
2018-08-13 15:54:55 +07:00
|
|
|
let i = 0;
|
|
|
|
|
while (i < 8) {
|
|
|
|
|
await Utils.sleep(1);
|
2018-08-08 14:30:44 +07:00
|
|
|
await i++;
|
2018-08-07 19:49:42 +07:00
|
|
|
}
|
2018-08-08 14:30:44 +07:00
|
|
|
await this.webAction.verifyToastNotificationShow(message);
|
|
|
|
|
await this.mouseMoveCenter();
|
2018-08-13 15:54:55 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getBadgeCount() {
|
|
|
|
|
let count = await this.app.electron.remote.app.getBadgeCount();
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async resetBadgeCount() {
|
|
|
|
|
await this.app.electron.remote.app.setBadgeCount(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getBadgeCount() {
|
|
|
|
|
let count = await this.app.electron.remote.app.getBadgeCount();
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async verifyCurrentBadgeCount(number) {
|
|
|
|
|
let expected = false;
|
|
|
|
|
let i = 0;
|
|
|
|
|
let count = await this.getBadgeCount();
|
|
|
|
|
while (i < 5) {
|
|
|
|
|
if (count == number) {
|
|
|
|
|
expected = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
await Utils.sleep(1);
|
|
|
|
|
count = await this.getBadgeCount();
|
|
|
|
|
await i++;
|
|
|
|
|
}
|
|
|
|
|
await expect(expected).toBeTruthy();
|
|
|
|
|
}
|
2018-08-08 14:30:44 +07:00
|
|
|
|
2018-08-01 00:04:45 +07:00
|
|
|
}
|
|
|
|
|
|
2018-08-13 15:54:55 +07:00
|
|
|
module.exports = WindowsActions;
|