Electron-84: integrated RobotJS into the test

This commit is contained in:
Vikas Shashidhar 2017-07-07 18:38:12 +05:30 committed by Vishwas Shashidhar
parent a3598f9731
commit 37e9a08900

View File

@ -1,30 +1,45 @@
describe('Tests for Full Screen', () => { const path = require('path');
const fs = require('fs');
const childProcess = require('child_process');
const Application = require('./spectron/spectronSetup');
let robot;
let configPath;
let app = new Application({});
describe('Tests for Full screen', () => {
let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000; jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;
let app;
beforeAll((done) => { beforeAll((done) => {
const Application = require('./spectron/spectronSetup'); childProcess.exec(`npm rebuild robotjs --target=${process.version} --build-from-source`, function () {
app = new Application({}); robot = require('robotjs');
return app.startApplication().then((startedApp) => { return app.startApplication().then((startedApp) => {
app = startedApp; app = startedApp;
done(); app.browserWindow.setFullScreen(false);
}).catch((err) => { done();
expect(err).toBeNull(); }).catch((err) => {
expect(err).toBeNull();
});
}); });
}); });
afterAll((done) => { afterAll((done) => {
if (app && app.isRunning()) { if (app && app.isRunning()) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
app.stop().then(() => { app.client.getWindowCount().then((count) => {
done(); if (count > 0) {
}).catch((err) => { app.stop().then(() => {
console.log(err); done();
done(); }).catch((err) => {
}); console.log(err);
done();
});
} else {
done();
}
})
} else { } else {
done(); done();
} }
@ -32,7 +47,6 @@ describe('Tests for Full Screen', () => {
it('should launch the app', (done) => { it('should launch the app', (done) => {
return app.client.waitUntilWindowLoaded().then(() => { return app.client.waitUntilWindowLoaded().then(() => {
app.browserWindow.setFullScreen(false);
return app.client.getWindowCount().then((count) => { return app.client.getWindowCount().then((count) => {
expect(count === 1).toBeTruthy(); expect(count === 1).toBeTruthy();
done(); done();
@ -60,16 +74,23 @@ describe('Tests for Full Screen', () => {
}); });
}); });
it('should set the app full screen', () => { it('should set the app full screen and check whether it is in full screen', () => {
return app.browserWindow.setFullScreen(true); robot.setMouseDelay(200);
}); robot.moveMouseSmooth(205, 10);
robot.mouseClick();
robot.setKeyboardDelay(200);
robot.keyTap('down');
robot.keyTap('down');
robot.keyTap('down');
robot.keyTap('down');
robot.keyTap('down');
robot.keyTap('down');
robot.keyTap('enter');
it('should check whether the app is in full screen', () => { return app.browserWindow.isFullScreen().then((fullscreen) => {
return app.browserWindow.isFullScreen().then((isFullScreen) => { expect(fullscreen).toBeTruthy();
expect(isFullScreen).toBeTruthy();
}).catch((err) => { }).catch((err) => {
expect(err).toBeNull(); expect(err).toBeNull();
}); })
}); });
}); });