AVT-937,AVT-938,AVT-939 : [Spectron][Windows] Close window when 'Minimize on Close' is ON (#437)

This commit is contained in:
tranducanh
2018-08-01 16:13:57 +07:00
committed by Vishwas Shashidhar
parent 7791d5b39a
commit f893b5658c
6 changed files with 318 additions and 14 deletions

View File

@@ -0,0 +1,154 @@
const Application = require('./spectronSetup');
const { isMac } = require('../../js/utils/misc');
const WindowsAction = require('./spectronWindowsActions');
const WebAction = require('./spectronWebActions');
var app = new Application({
startTimeout: Application.getTimeOut(),
waitTimeout: Application.getTimeOut()
});
let wActions;
let webActions;
!isMac ?describe('Add Test To Verify Minimize on Close', () => {
let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut();
beforeAll(async (done) => {
await app.startApplication().then(async(startedApp) => {
app.app = await startedApp;
wActions = await new WindowsAction(app.app);
webActions = await new WebAction(app.app);
}).then((async() =>{
await getConfigPath(app.app).then((config) => {
app.pathApp = config;
}).catch((err) => {
done.fail(new Error(`Unable to start application error: ${err}`));
});
done();
}));
});
function getConfigPath(app) {
return new Promise(function (resolve, reject) {
app.client.addCommand('getUserDataPath', function () {
return app.client.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.client.getWindowCount().then((count) => {
if (count > 0) {
app.stop().then(() => {
done();
}).catch((err) => {
done();
});
} else {
done();
}
})
} else {
done();
}
});
/**
* Verify Minimize on Close option once the application is installed
* TC-ID: 3084609
* Cover scenarios in AVT-939
*/
it('Verify Minimize on Close option once the application is installed', async(done) => {
await Application.readConfig(app.pathApp).then(async (userConfig) => {
//When app un-ticked on Minimize On Close Menu Item
//Select 1 times to perform for ticking Menu
await wActions.openMenu(["Window","Minimize on Close"]);
if (userConfig.minimizeOnClose != false) {
//When app ticked on Minimize On Close Menu Item
//Select 2 times to perform for ticking Menu
await wActions.openMenu(["Window","Minimize on Close"]);
}
await wActions.openMenu(["Window","Close"]);
await wActions.verifyMinimizeWindows();
done();
}).catch((err) => {
done.fail(new Error(`minimize-on-close failed in readConfig with error: ${err}`));
})
});
/**
* Close window when 'Minimize on Close' is ON
* TC-ID: 2911252
* Cover scenarios in AVT-937
*/
it('Close window when "Minimize on Close" is ON', async (done) => {
Application.readConfig(app.pathApp).then(async (userConfig) => {
//When app un-ticked on Minimize On Close Menu Item
//Select 1 times to perform for ticking Menu
await wActions.focusWindow();
await wActions.openMenu(["Window","Minimize on Close"]);
if (userConfig.minimizeOnClose != false) {
await wActions.openMenu(["Window","Minimize on Close"]);
}
//When app ticked on Minimize On Close Menu Item
//Select 2 times to perform for ticking Menu
await wActions.openMenu(["Window","Close"])
await wActions.verifyMinimizeWindows();
await wActions.focusWindow();
await wActions.pressCtrlW();
await wActions.verifyMinimizeWindows();
await wActions.focusWindow();
await wActions.openMenu(["Window","Close"])
await wActions.verifyMinimizeWindows();
done();
}).catch((err) => {
done.fail(new Error(`minimize-on-close failed in readConfig with error: ${err}`));
})
});
/**
* Verify by deselecting Minimize on Close option once the application is launched
* TC-ID: 3084612
* Cover scenarios in AVT-938
*/
it('Verify by deselecting Minimize on Close option once the application is launched', async (done) => {
await Application.readConfig(app.pathApp).then(async (userConfig) => {
await wActions.focusWindow();
await wActions.openMenu(["Window","Minimize on Close"]).then(async ()=>
{
if (userConfig.minimizeOnClose == false) {
//When app does not tick on Minimize On Close Menu Item
//Select 2 times to perform for un-ticking Menu
await wActions.openMenu(["Window","Minimize on Close"]);
}
await wActions.openMenu(["Window","Close"])
await wActions.verifyMinimizeWindows();
done();
});
}).catch((err) => {
done.fail(new Error(`minimize-on-close failed in readConfig with error: ${err}`));
})
});
}) : describe.skip();

View File

@@ -7,7 +7,16 @@ module.exports = {
SEARCH_LIBRARY_PATH_MAC: "node_modules/electron/dist/Electron.app/Contents/library",
SEARCH_LIBRARY_PATH_WIN: "node_modules/electron/dist/library",
TESTED_HOST: "https://cip4-qa.symphony.com/",
};
MENU: {
"root": {
name: "menu", step: 0, items: [
{ name: "Edit", step: 0, items: [{ name: "Undo", step: 0 }, { name: "Redo", step: 1 }, { name: "Cut", step: 2 }, { name: "Copy", step: 3 }, { name: "Paste", step: 4 }, { name: "Paste and Match Style", step: 5 }, { name: "Delete", step: 6 }, { name: "Select All", step: 7 }] },
{ name: "View", step: 1, items: [{ name: "Reload", step: 0 }, { name: "Actual Size", step: 1 }, { name: "Zoom In", step: 2 }, { name: "Zoom Out", step: 3 }, { name: "Toogle Full Screen", step: 4 }] },
{ name: "Window", step: 2, items: [{ name: "Minimize", step: 0 }, { name: "Close", step: 1 }, { name: "Auto Launch On Startup", step: 2 }, { name: "Always on Top", step: 3 }, { name: "Minimize on Close", step: 4 }] },
{ name: "Help", step: 3, items: [{ name: "Symphony Help", step: 0 }, { name: "Learn More", step: 1 }, { name: "Troubleshooting", step: 2 }, { name: "About Symphony", step: 3 }] }
]
}
}
};

View File

@@ -1,8 +1,9 @@
module.exports= {
module.exports= {
// Title bar
TITLE_BAR: "#title-bar",
MAXIMIZE_BTN: "#title-bar-maximize-button",
SYM_LOGO: "#logo"
MAXIMIZE_BTN: "#title-bar-maximize-button",
SYM_LOGO: "#logo",
MINIMIZED_BUTTON: "button#title-bar-minimize-button",
CLOSE_BUTTON: "button#title-bar-close-button",
MAIN_MENU_ITEM: "#hamburger-menu-button"
};

View File

@@ -27,9 +27,9 @@ class App {
App.copyLibraries(constants.SEARCH_LIBRARY_PATH_WIN);
}
this.app = new Application(this.options);
}
this.pathApp = '';
}
async startApplication(configurations) {
try {
@@ -56,7 +56,7 @@ class App {
}
return this.app;
} catch (err) {
} catch (err) {
throw new Error("Unable to start application " + err);
};
}
@@ -70,7 +70,7 @@ class App {
}
static getTimeOut() {
return 90000
return 90000;
}
static readConfig(configPath) {
@@ -133,7 +133,7 @@ class App {
});
});
}
}
module.exports = App;

View File

@@ -3,8 +3,8 @@ 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);
}
@@ -15,6 +15,19 @@ class WebActions {
expect(maximized).toBeTruthy();
})
}
async minimizeWindowByClick() {
await this.app.client.click(ui.MINIMIZED_BUTTON);
}
async closeWindowByClick() {
await this.app.client.click(ui.CLOSE_BUTTON);
}
async openApplicationMenuByClick() {
await this.app.client.click(ui.MAIN_MENU_ITEM);
}
}
module.exports = WebActions;

View File

@@ -1,8 +1,13 @@
const robot = require('robotjs');
const constants = require('./spectronConstants.js');
const WebActions = require ('./spectronWebActions.js');
class WindowsActions {
constructor(app) {
this.app = app;
}
async getCurrentSize() {
@@ -48,7 +53,129 @@ class WindowsActions {
return new Promise(resolve=>{
setTimeout(resolve,ms)
})
}
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;
}
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');
});
}
async quitApp() {
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 < 6; i++) {
await robot.keyTap('down');
}
await robot.keyTap('enter');
});
}
async pressCtrlW() {
await robot.keyToggle('w', 'down', ['control']);
await robot.keyToggle('w', 'up', ['control']);
}
async focusWindow() {
await this.app.browserWindow.show();
}
async menuSearch(element, namevalue) {
if (element.name == namevalue) {
return await element;
}
else if (element.items !== undefined) {
var result;
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 openMenu(arrMenu) {
var arrStep = [];
for (var i = 0; i < arrMenu.length; i++) {
var item = await this.menuSearch(constants.MENU.root, arrMenu[i]);
await arrStep.push(item);
}
await this.actionForMenus(arrStep);
return arrStep;
}
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(1000);
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');
});
}
}
module.exports = WindowsActions;