Updated AVT-1146

This commit is contained in:
Truong.Pham 2018-09-07 15:11:20 +07:00
parent 0331596438
commit 9c7c73b616
3 changed files with 45 additions and 134 deletions

View File

@ -1,140 +1,45 @@
const Application = require('./spectronSetup'); const Application = require('./spectronSetup');
const { isMac } = require('../../js/utils/misc'); const WindowsActions = require('./spectronWindowsActions');
const robot = require('robotjs'); const constants = require('./spectronConstants.js');
const {isMac} = require('../../js/utils/misc');
let app, windowsActions;
let configPath; describe('Tests for fullscreen', () => {
let app = new Application({}); jasmine.DEFAULT_TIMEOUT_INTERVAL = constants.TIMEOUT_TEST_SUITE;
describe('Tests for Full screen', () => { beforeAll(async (done) => {
try {
let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; app = await new Application({}).startApplication({ testedHost: constants.TESTED_HOST, alwaysOnTop: true });
jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut(); windowsActions = await new WindowsActions(app);
done();
beforeAll((done) => { } catch (err) {
return app.startApplication().then((startedApp) => { await windowsActions.stopApp();
app = startedApp;
getConfigPath().then((config) => {
configPath = config;
done();
}).catch((err) => {
done.fail(new Error(`full-screen failed in getConfigPath with error: ${err}`));
});
}).catch((err) => {
done.fail(new Error(`Unable to start application error: ${err}`)); done.fail(new Error(`Unable to start application error: ${err}`));
}); };
}); });
function getConfigPath() { afterAll(async (done) => {
return new Promise(function (resolve, reject) { try {
app.client.addCommand('getUserDataPath', function () { await windowsActions.stopApp();
return this.execute(function () { done();
return require('electron').remote.app.getPath('userData'); } catch (err) {
}) done.fail(new Error(`Failed at post-condition: ${err}`));
}); };
app.client.getUserDataPath().then((userConfigPath) => { });
resolve(userConfigPath.value)
}).catch((err) => {
reject(err);
});
});
}
afterAll((done) => { it('Should set the app full screen and check whether it is in full screen', async (done) => {
if (app && app.isRunning()) { try {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; if (await windowsActions.isAppRunning()) {
app.client.getWindowCount().then((count) => { if (isMac) {
if (count > 0) { await windowsActions.fullScreenOnMac();
app.stop().then(() => {
done();
}).catch((err) => {
done();
});
} else { } else {
done(); await windowsActions.openMenu(["View", "Toggle Full Screen"]);
} }
}) await windowsActions.verifyAppFullScreen();
} else {
done();
}
});
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(`full-screen failed in getWindowCount with error: ${err}`));
});
}).catch((err) => {
done.fail(new Error(`full-screen 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(`full-screen 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(`full-screen failed in getWindowCount with error: ${err}`));
});
});
it('should bring the app to top', () => {
app.browserWindow.focus();
return app.browserWindow.setAlwaysOnTop(true).then(() => {
return app.browserWindow.isAlwaysOnTop().then((isOnTop) => {
expect(isOnTop).toBeTruthy();
});
});
});
it('should set the app full screen and check whether it is in full screen', (done) => {
if (isMac) {
robot.setMouseDelay(100);
robot.moveMouseSmooth(205, 10);
robot.mouseClick();
robot.setKeyboardDelay(100);
// Key tap 5 times as "Enter Full Screen" is in the
// 5th position under view menu item
for (let i = 0; i < 5; i++) {
robot.keyTap('down');
} }
robot.keyTap('enter'); done();
} catch (err) {
return app.browserWindow.isFullScreen().then((fullscreen) => { done.fail(new Error(`Fail to verify app full screen: ${err}`));
expect(fullscreen).toBeTruthy(); };
done();
}).catch((err) => {
done.fail(new Error(`full-screen failed in isFullScreen with error: ${err}`));
})
} else {
return app.browserWindow.getBounds().then((bounds) => {
robot.setMouseDelay(100);
let x = bounds.x + 200;
let y = bounds.y + 200;
robot.moveMouse(x, y);
robot.mouseClick("left");
robot.keyTap('f11');
return app.browserWindow.isFullScreen().then((fullscreen) => {
expect(fullscreen).toBeTruthy();
done();
}).catch((err) => {
done.fail(new Error(`full-screen failed in isFullScreen with error: ${err}`));
})
});
}
}); });
}); });

View File

@ -39,15 +39,20 @@ class App {
} }
if ((typeof configurations === "undefined") || (typeof configurations.defaultSize === "undefined") || (configurations.defaultSize === true)) { if ((typeof configurations === "undefined") || (typeof configurations.defaultSize === "undefined") || (configurations.defaultSize === true)) {
await this.app.browserWindow.setFullScreen(false);
await this.app.browserWindow.setSize(900, 900); await this.app.browserWindow.setSize(900, 900);
} }
if ((typeof configurations === "undefined") || (typeof configurations.defaultPosition === "undefined") || (configurations.defaultPosition === true)) { if ((typeof configurations === "undefined") || (typeof configurations.defaultPosition === "undefined") || (configurations.defaultPosition === true)) {
await this.app.browserWindow.center(); await this.app.browserWindow.center();
} }
await this.app.browserWindow.minimize();
await this.app.browserWindow.restore(); if (isWindowsOS) {
await this.app.browserWindow.minimize();
await this.app.browserWindow.restore();
}
return this.app; return this.app;
} catch (err) { } catch (err) {
throw new Error("Unable to start application " + err); throw new Error("Unable to start application " + err);
}; };
} }
@ -124,7 +129,7 @@ class App {
}); });
}); });
} }
} }
module.exports = App; module.exports = App;

View File

@ -93,7 +93,7 @@ class WindowsActions {
await expect(isAlwaysOnTop).toBeTruthy(); await expect(isAlwaysOnTop).toBeTruthy();
} else { } else {
await expect(isAlwaysOnTop).toBeFalsy(); await expect(isAlwaysOnTop).toBeFalsy();
} }
} }
async menuSearch(element, namevalue) { async menuSearch(element, namevalue) {
@ -527,6 +527,7 @@ class WindowsActions {
await this.app.stop(); await this.app.stop();
} }
} }
async isAppRunning() { async isAppRunning() {
return this.app.isRunning(); return this.app.isRunning();
} }