mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
AVT-914 [Spectron][Windows] Add test "Keep size and position of the windows in previous session" (#430)
This commit is contained in:
parent
f0de24ccf6
commit
7791d5b39a
@ -215,7 +215,7 @@ function doCreateMainWindow(initialUrl, initialBounds, isCustomTitleBar) {
|
|||||||
mainWindow.webContents.send('window-leave-full-screen');
|
mainWindow.webContents.send('window-leave-full-screen');
|
||||||
});
|
});
|
||||||
|
|
||||||
if (initialBounds && !isNodeEnv) {
|
if (initialBounds) {
|
||||||
// maximizes the application if previously maximized
|
// maximizes the application if previously maximized
|
||||||
if (initialBounds.isMaximized) {
|
if (initialBounds.isMaximized) {
|
||||||
mainWindow.maximize();
|
mainWindow.maximize();
|
||||||
|
@ -123,8 +123,8 @@ describe('Tests for Full screen', () => {
|
|||||||
robot.setMouseDelay(100);
|
robot.setMouseDelay(100);
|
||||||
let x = bounds.x + 200;
|
let x = bounds.x + 200;
|
||||||
let y = bounds.y + 200;
|
let y = bounds.y + 200;
|
||||||
robot.moveMouseSmooth(x, y);
|
robot.moveMouse(x, y);
|
||||||
robot.mouseClick();
|
robot.mouseClick("left");
|
||||||
|
|
||||||
robot.keyTap('f11');
|
robot.keyTap('f11');
|
||||||
|
|
||||||
|
@ -1,44 +1,35 @@
|
|||||||
const Application = require('./spectronSetup');
|
const Application = require('./spectronSetup');
|
||||||
const robot = require('robotjs');
|
|
||||||
const {isMac} = require('../../js/utils/misc');
|
const {isMac} = require('../../js/utils/misc');
|
||||||
|
const WindowsActions = require('./spectronWindowsActions');
|
||||||
|
|
||||||
let app = new Application({});
|
let app = new Application({});
|
||||||
let defaultWidth;
|
let windowActions;
|
||||||
let defaultHeight;
|
|
||||||
|
|
||||||
!isMac ? describe('Tests for Resizing windows', () => {
|
!isMac ? describe('Tests for Resizing windows', () => {
|
||||||
|
|
||||||
let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
||||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut();
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut();
|
||||||
|
|
||||||
beforeAll((done) => {
|
beforeAll(async (done) => {
|
||||||
return app.startApplication().then((startedApp) => {
|
try {
|
||||||
app = startedApp;
|
app = await new Application({}).startApplication();
|
||||||
|
windowActions = await new WindowsActions(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((done) => {
|
afterAll(async (done) => {
|
||||||
|
try {
|
||||||
if (app && app.isRunning()) {
|
if (app && app.isRunning()) {
|
||||||
// resize to default size
|
|
||||||
app.browserWindow.getBounds().then((bounds) => {
|
|
||||||
let x = bounds.x - (defaultWidth - bounds.width);
|
|
||||||
let y = bounds.y - (defaultHeight - bounds.height);
|
|
||||||
robot.moveMouse(bounds.x, bounds.y);
|
|
||||||
robot.mouseToggle("down");
|
|
||||||
robot.dragMouse(x, y);
|
|
||||||
robot.mouseToggle("up");
|
|
||||||
})
|
|
||||||
//close app
|
|
||||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
||||||
app.stop().then(() => {
|
await app.stop();
|
||||||
done();
|
done();
|
||||||
}).catch((err) => {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
done.fail(new Error(`Failed at post-condition: ${err}`));
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,24 +37,13 @@ let defaultHeight;
|
|||||||
* TC-ID: 3028239
|
* TC-ID: 3028239
|
||||||
* Cover scenarios in AVT-768
|
* Cover scenarios in AVT-768
|
||||||
*/
|
*/
|
||||||
it('should be minimized up to 300px', (done) => {
|
it('Should be minimized up to 300px', async (done) => {
|
||||||
app.browserWindow.getBounds().then((bounds) => {
|
try {
|
||||||
defaultHeight = bounds.height;
|
await windowActions.resizeWindows(0, 0);
|
||||||
defaultWidth = bounds.width;
|
expect([ 300, 300 ]).toEqual(await windowActions.getCurrentSize());
|
||||||
let x = bounds.x + bounds.width;
|
|
||||||
let y = bounds.y + bounds.height;
|
|
||||||
robot.setMouseDelay(500);
|
|
||||||
robot.moveMouse(bounds.x, bounds.y);
|
|
||||||
robot.mouseToggle("down");
|
|
||||||
robot.dragMouse(x, y);
|
|
||||||
robot.mouseToggle("up");
|
|
||||||
return app.browserWindow.getBounds().then((bounds) => {
|
|
||||||
const data = {x: bounds.width, y: bounds.height};
|
|
||||||
expect(data).toEqual({x: 300, y: 300});
|
|
||||||
done();
|
done();
|
||||||
}).catch((err) => {
|
} catch (err) {
|
||||||
done.fail(new Error(`failed to minimize window to 300 px with error: ${err}`));
|
done.fail(new Error(`failed to minimize window to 300 px with error: ${err}`));
|
||||||
})
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}) : describe.skip();
|
}) : describe.skip();
|
74
tests/spectron/saveLayout.spectron.js
Normal file
74
tests/spectron/saveLayout.spectron.js
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
const Application = require('./spectronSetup');
|
||||||
|
const WindowsActions = require('./spectronWindowsActions');
|
||||||
|
const WebActions = require('./spectronWebActions');
|
||||||
|
const { isMac } = require('../../js/utils/misc');
|
||||||
|
|
||||||
|
let app;
|
||||||
|
let windowActions;
|
||||||
|
let webActions;
|
||||||
|
|
||||||
|
!isMac ? describe('Tests for saved layout', () => {
|
||||||
|
|
||||||
|
let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
||||||
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut();
|
||||||
|
|
||||||
|
beforeAll(async (done) => {
|
||||||
|
try {
|
||||||
|
app = await new Application({}).startApplication();
|
||||||
|
windowActions = await new WindowsActions(app);
|
||||||
|
done();
|
||||||
|
} catch(err) {
|
||||||
|
done.fail(new Error(`Unable to start application error: ${err}`));
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async (done) => {
|
||||||
|
try {
|
||||||
|
if (app && app.isRunning()) {
|
||||||
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
||||||
|
await app.stop();
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
done.fail(new Error(`Failed at post-condition: ${err}`));
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keep size and position of the windows in previous session
|
||||||
|
* TC-ID: 2915948
|
||||||
|
* Cover scenarios in AVT-914
|
||||||
|
*/
|
||||||
|
it('Keep size and position of the windows in previous session', async (done) => {
|
||||||
|
try {
|
||||||
|
var defaultPosition = await windowActions.getCurrentPosition();
|
||||||
|
var defaultSize = await windowActions.getCurrentSize();
|
||||||
|
|
||||||
|
// Size and position of previos session keep after resizing and dragging
|
||||||
|
await windowActions.setPosition(defaultPosition[0], 20);
|
||||||
|
await windowActions.setSize(defaultSize[0] - 100, defaultSize[0] - 100);
|
||||||
|
await windowActions.sleep(1000); // Sleep 1s after resizing
|
||||||
|
var previousPosition = await windowActions.getCurrentPosition();
|
||||||
|
var previousSize = await windowActions.getCurrentSize();
|
||||||
|
await app.stop();
|
||||||
|
app = await new Application({}).startApplication({defaultSize: false, defaultPosition: false});
|
||||||
|
windowActions = await new WindowsActions(app);
|
||||||
|
webActions = await new WebActions(app);
|
||||||
|
expect(previousPosition).toEqual(await windowActions.getCurrentPosition());
|
||||||
|
expect(previousSize).toEqual(await windowActions.getCurrentSize());
|
||||||
|
|
||||||
|
// Size and position of previous session keep after maximizing
|
||||||
|
await webActions.maximizeWindows();
|
||||||
|
await windowActions.sleep(1000); // Sleep 1s after resizing
|
||||||
|
previousSize = await windowActions.getCurrentSize();
|
||||||
|
await app.stop();
|
||||||
|
app = await new Application({}).startApplication({defaultSize: false, defaultPosition: false});
|
||||||
|
windowActions = await new WindowsActions(app);
|
||||||
|
webActions = await new WebActions(app);
|
||||||
|
expect(previousSize).toEqual(await windowActions.getCurrentSize());
|
||||||
|
done();
|
||||||
|
} catch(err) {
|
||||||
|
done.fail(new Error(`Fail to keep size and position of the windows in previous session with error: ${err}`));
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}) : describe.skip();
|
@ -7,4 +7,7 @@ module.exports = {
|
|||||||
|
|
||||||
SEARCH_LIBRARY_PATH_MAC: "node_modules/electron/dist/Electron.app/Contents/library",
|
SEARCH_LIBRARY_PATH_MAC: "node_modules/electron/dist/Electron.app/Contents/library",
|
||||||
SEARCH_LIBRARY_PATH_WIN: "node_modules/electron/dist/library",
|
SEARCH_LIBRARY_PATH_WIN: "node_modules/electron/dist/library",
|
||||||
|
|
||||||
|
TESTED_HOST: "https://cip4-qa.symphony.com/",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
8
tests/spectron/spectronInterfaces.js
Normal file
8
tests/spectron/spectronInterfaces.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
module.exports= {
|
||||||
|
|
||||||
|
// Title bar
|
||||||
|
TITLE_BAR: "#title-bar",
|
||||||
|
MAXIMIZE_BTN: "#title-bar-maximize-button",
|
||||||
|
|
||||||
|
SYM_LOGO: "#logo"
|
||||||
|
};
|
@ -4,6 +4,7 @@ const fs = require('fs');
|
|||||||
const { isMac, isWindowsOS } = require('../../js/utils/misc');
|
const { isMac, isWindowsOS } = require('../../js/utils/misc');
|
||||||
const ncp = require('ncp').ncp;
|
const ncp = require('ncp').ncp;
|
||||||
const constants = require('./spectronConstants.js');
|
const constants = require('./spectronConstants.js');
|
||||||
|
const ui = require('./spectronInterfaces.js');
|
||||||
|
|
||||||
class App {
|
class App {
|
||||||
|
|
||||||
@ -30,18 +31,34 @@ class App {
|
|||||||
this.app = new Application(this.options);
|
this.app = new Application(this.options);
|
||||||
}
|
}
|
||||||
|
|
||||||
startApplication(configurations) {
|
async startApplication(configurations) {
|
||||||
return this.app.start().then((app) => {
|
try {
|
||||||
if (configurations)
|
this.app = await this.app.start();
|
||||||
{
|
await this.app.client.waitForVisible(ui.SYM_LOGO, require('./spectronSetup').getTimeOut());
|
||||||
if (configurations.alwaysOnTop) {
|
await this.app.browserWindow.minimize();
|
||||||
app.browserWindow.setAlwaysOnTop(true);
|
await this.app.browserWindow.restore();
|
||||||
|
if (configurations) {
|
||||||
|
if ((typeof configurations.alwaysOnTop !== "undefined") && (configurations.alwaysOnTop === false)) {
|
||||||
|
await this.app.browserWindow.setAlwaysOnTop(false);
|
||||||
|
} else {
|
||||||
|
await this.app.browserWindow.setAlwaysOnTop(true);
|
||||||
|
}
|
||||||
|
if (configurations.testedHost) {
|
||||||
|
await this.app.client.waitUntilWindowLoaded().url(configurations.testedHost);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return app;
|
|
||||||
}).catch((err) => {
|
if ((typeof configurations === "undefined") || (typeof configurations.defaultSize === "undefined") || (configurations.defaultSize === true)) {
|
||||||
|
await this.app.browserWindow.setSize(900, 900);
|
||||||
|
}
|
||||||
|
if ((typeof configurations === "undefined") || (typeof configurations.defaultPosition === "undefined") || (configurations.defaultPosition === true)) {
|
||||||
|
await this.app.browserWindow.center();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.app;
|
||||||
|
} catch (err) {
|
||||||
throw new Error("Unable to start application " + err);
|
throw new Error("Unable to start application " + err);
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static getAppPath() {
|
static getAppPath() {
|
||||||
|
20
tests/spectron/spectronWebActions.js
Normal file
20
tests/spectron/spectronWebActions.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
async maximizeWindows() {
|
||||||
|
await this.clickMaximizeButton();
|
||||||
|
await this.app.browserWindow.isMaximized().then(function (maximized) {
|
||||||
|
expect(maximized).toBeTruthy();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = WebActions;
|
54
tests/spectron/spectronWindowsActions.js
Normal file
54
tests/spectron/spectronWindowsActions.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
const robot = require('robotjs');
|
||||||
|
|
||||||
|
class WindowsActions {
|
||||||
|
constructor(app) {
|
||||||
|
this.app = app;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
robot.moveMouse(bounds.x, bounds.y);
|
||||||
|
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");
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async sleep(ms){
|
||||||
|
return new Promise(resolve=>{
|
||||||
|
setTimeout(resolve,ms)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = WindowsActions;
|
@ -41,6 +41,16 @@ describe('Tests for Zoom in and Zoom out', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
afterAll((done) => {
|
afterAll((done) => {
|
||||||
|
// Get it back normal size
|
||||||
|
if (!isMac) {
|
||||||
|
for (let i = 0; i < 4; i++) {
|
||||||
|
robot.keyToggle('+', 'down', ['control', 'shift']);
|
||||||
|
}
|
||||||
|
robot.keyToggle('+', 'up');
|
||||||
|
robot.keyToggle('control', 'up');
|
||||||
|
robot.keyToggle('shift', 'up');
|
||||||
|
}
|
||||||
|
|
||||||
if (app && app.isRunning()) {
|
if (app && app.isRunning()) {
|
||||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
||||||
app.client.getWindowCount().then((count) => {
|
app.client.getWindowCount().then((count) => {
|
||||||
@ -124,7 +134,7 @@ describe('Tests for Zoom in and Zoom out', () => {
|
|||||||
robot.setMouseDelay(100);
|
robot.setMouseDelay(100);
|
||||||
let x = bounds.x + 200;
|
let x = bounds.x + 200;
|
||||||
let y = bounds.y + 200;
|
let y = bounds.y + 200;
|
||||||
robot.moveMouseSmooth(x, y);
|
robot.moveMouse(x, y);
|
||||||
robot.mouseClick();
|
robot.mouseClick();
|
||||||
|
|
||||||
robot.keyToggle('0', 'down', ['control']);
|
robot.keyToggle('0', 'down', ['control']);
|
||||||
@ -174,7 +184,7 @@ describe('Tests for Zoom in and Zoom out', () => {
|
|||||||
robot.setMouseDelay(100);
|
robot.setMouseDelay(100);
|
||||||
let x = bounds.x + 200;
|
let x = bounds.x + 200;
|
||||||
let y = bounds.y + 200;
|
let y = bounds.y + 200;
|
||||||
robot.moveMouseSmooth(x, y);
|
robot.moveMouse(x, y);
|
||||||
robot.mouseClick();
|
robot.mouseClick();
|
||||||
|
|
||||||
robot.keyToggle('0', 'down', ['control']);
|
robot.keyToggle('0', 'down', ['control']);
|
||||||
|
Loading…
Reference in New Issue
Block a user