Refactored spectron tests

This commit is contained in:
Kiran Niranjan 2017-07-06 15:09:50 +05:30 committed by Kiran Niranjan
parent c4fb2ff12d
commit d220b6ada6
6 changed files with 236 additions and 112 deletions

View File

@ -15,8 +15,9 @@
"prebuild": "npm run rebuild && npm run browserify-preload", "prebuild": "npm run rebuild && npm run browserify-preload",
"browserify-preload": "browserify -o js/preload/_preloadMain.js -x electron --insert-global-vars=__filename,__dirname js/preload/preloadMain.js", "browserify-preload": "browserify -o js/preload/_preloadMain.js -x electron --insert-global-vars=__filename,__dirname js/preload/preloadMain.js",
"rebuild": "electron-rebuild -f", "rebuild": "electron-rebuild -f",
"test": "npm run lint && jest --verbose --testPathPattern test", "test": "npm run lint && npm run copy-config && jest --verbose --testPathPattern test --runInBand",
"lint": "eslint --ext .js js/", "lint": "eslint --ext .js js/",
"copy-config": "ncp 'config' 'node_modules/electron/dist/Electron.app/Contents/config'",
"rename-exe": "cd dist/win-unpacked && ren Symphony.exe Symphony-Electron.exe" "rename-exe": "cd dist/win-unpacked && ren Symphony.exe Symphony-Electron.exe"
}, },
"jest": { "jest": {
@ -79,6 +80,7 @@
"eslint-plugin-jsx-a11y": "^4.0.0", "eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.10.0", "eslint-plugin-react": "^6.10.0",
"jest": "^19.0.2", "jest": "^19.0.2",
"ncp": "^2.0.0",
"spectron": "^3.7.2" "spectron": "^3.7.2"
}, },
"dependencies": { "dependencies": {

View File

@ -1,56 +1,80 @@
const Application = require('./spectronSetup');
const path = require('path');
describe('Tests for Always on top', () => { describe('Tests for Always on top', () => {
let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000; jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;
let app; let app;
beforeAll(() => { beforeAll((done) => {
const Application = require('./utils/spectronSetup');
app = new Application({}); app = new Application({});
return app.startApplication().then((startedApp) => {
app = startedApp;
done();
}).catch((err) => {
expect(err).toBeNull();
});
}); });
afterAll(() => { afterAll((done) => {
if (app && app.isRunning()) { if (app && app.isRunning()) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
return app.stop(); app.stop().then(() => {
done();
}).catch((err) => {
console.log(err);
done();
});
} }
}); });
it('should launch the app', () => { it('should launch the app', (done) => {
return app.startApplication().then((startedApp) => { return app.client.waitUntilWindowLoaded().then(() => {
app = startedApp; return app.client.getWindowCount().then((count) => {
return app.client.waitUntilWindowLoaded().then(async () => {
const count = await app.client.getWindowCount();
expect(count === 1).toBeTruthy(); expect(count === 1).toBeTruthy();
}) done();
}).catch((err) => {
expect(err).toBeNull();
});
}).catch((err) => {
expect(err).toBeNull();
}); });
}); });
it('should check window count', async () => { it('should check window count', () => {
const count = await app.client.getWindowCount(); return app.client.getWindowCount().then((count) => {
expect(count === 1).toBeTruthy(); expect(count === 1).toBeTruthy();
}).catch((err) => {
expect(err).toBeNull();
});
}); });
it('should check browser window visibility', async () => { it('should check browser window visibility', () => {
const isVisible = await app.browserWindow.isVisible(); return app.browserWindow.isVisible().then((isVisible) => {
expect(isVisible).toBeTruthy(); expect(isVisible).toBeTruthy();
}).catch((err) => {
expect(err).toBeNull();
});
}); });
it('should check is always on top', async () => { it('should check is always on top', async () => {
const isAlwaysOnTop = await app.browserWindow.isAlwaysOnTop(); return app.browserWindow.isAlwaysOnTop().then((isAlwaysOnTop) => {
expect(isAlwaysOnTop).toBeFalsy(); expect(isAlwaysOnTop).toBeFalsy();
}).catch((err) => {
expect(err).toBeNull();
});
}); });
it('should change the always on top property', () => { it('should change the always on top property', () => {
return app.browserWindow.setAlwaysOnTop(true); return app.browserWindow.setAlwaysOnTop(true);
}); });
it('should check is always on top to be true', async () => { it('should check is always on top to be true', () => {
const isAlwaysOnTop = await app.browserWindow.isAlwaysOnTop(); return app.browserWindow.isAlwaysOnTop().then((isAlwaysOnTop) => {
expect(isAlwaysOnTop).toBeTruthy(); expect(isAlwaysOnTop).toBeTruthy();
}).catch((err) => {
expect(err).toBeNull();
});
}); });
}); });

View File

@ -1,56 +1,83 @@
const Application = require('./spectronSetup');
describe('Tests for Bring to front', () => { describe('Tests for Bring to front', () => {
let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000; jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;
let app; let app;
beforeAll(() => { beforeAll((done) => {
const Application = require('./utils/spectronSetup');
app = new Application({}); app = new Application({});
return app.startApplication().then((startedApp) => {
app = startedApp;
done();
}).catch(() => {
expect(true).toBe(false);
});
}); });
afterAll(() => { afterAll((done) => {
if (app && app.isRunning()) { if (app && app.isRunning()) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
return app.stop(); app.stop().then(() => {
done();
}).catch((err) => {
console.log(err);
done();
});
} }
}); });
it('should launch the app', () => { it('should launch the app', (done) => {
return app.startApplication().then((startedApp) => { return app.client.waitUntilWindowLoaded().then(() => {
app = startedApp; return app.client.getWindowCount().then((count) => {
return app.client.waitUntilWindowLoaded().then(async () => {
const count = await app.client.getWindowCount();
expect(count === 1).toBeTruthy(); expect(count === 1).toBeTruthy();
}) done();
}).catch(() => {
expect(true).toBe(false);
});
}).catch(() => {
expect(true).toBe(false);
}); });
}); });
it('should minimize the app', () => { it('should minimize the app', () => {
return app.browserWindow.minimize().then(async () => { return app.browserWindow.minimize().then(() => {
const isMinimized = await app.browserWindow.isMinimized(); return app.browserWindow.isMinimized().then((isMinimized) => {
expect(isMinimized).toBeTruthy(); expect(isMinimized).toBeTruthy();
}) }).catch(() => {
expect(true).toBe(false);
});
}).catch(() => {
expect(true).toBe(false);
});
}); });
it('should not be focused', () => { it('should not be focused', () => {
return app.browserWindow.isFocused().then((isFocused) => { return app.browserWindow.isFocused().then((isFocused) => {
expect(isFocused).toBeFalsy(); expect(isFocused).toBeFalsy();
}).catch(() => {
expect(true).toBe(false);
}); });
}); });
it('should maximize browser window', () => { it('should maximize browser window', () => {
return app.browserWindow.restore().then(async () => { return app.browserWindow.restore().then(async () => {
const isMinimized = await app.browserWindow.isMinimized(); return app.browserWindow.isMinimized().then((isMinimized) => {
expect(isMinimized).toBeFalsy(); expect(isMinimized).toBeFalsy();
}).catch(() => {
expect(true).toBe(false);
});
}).catch(() => {
expect(true).toBe(false);
}); });
}); });
it('should be focused', () => { it('should be focused', () => {
return app.browserWindow.isFocused().then((isFocused) => { return app.browserWindow.isFocused().then((isFocused) => {
expect(isFocused).toBeTruthy(); expect(isFocused).toBeTruthy();
}).catch(() => {
expect(true).toBe(false);
}); });
}); });

View File

@ -1,36 +1,48 @@
const Application = require('./spectronSetup');
const path = require('path'); const path = require('path');
describe('Tests for clipboard', () => { describe('Tests for clipboard', () => {
let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000; jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;
let app; let app;
beforeAll(() => { beforeAll((done) => {
const Application = require('./utils/spectronSetup');
app = new Application({}); app = new Application({});
return app.startApplication().then((startedApp) => {
app = startedApp;
done();
});
}); });
afterAll(() => { afterAll((done) => {
if (app && app.isRunning()) { if (app && app.isRunning()) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
return app.stop(); app.stop().then(() => {
done();
}).catch((err) => {
console.log(err);
done();
});
} }
}); });
it('should launch the app', () => { it('should launch the app', (done) => {
return app.startApplication().then((startedApp) => { return app.client.waitUntilWindowLoaded().then(() => {
app = startedApp; return app.client.getWindowCount().then((count) => {
return app.client.waitUntilWindowLoaded().then(async () => {
const count = await app.client.getWindowCount();
expect(count === 1).toBeTruthy(); expect(count === 1).toBeTruthy();
}) done();
}).catch((err) => {
expect(err).toBeFalsy();
});
}).catch((err) => {
expect(err).toBeFalsy();
}); });
}); });
it('should check window count', () => { it('should check window count', () => {
return app.client.url('file:///' + path.join(__dirname, '..', 'demo/index.html')) return app.client.url('file:///' + path.join(__dirname, '..', 'demo/index.html'));
}); });
it('should set the username field', () => { it('should set the username field', () => {
@ -45,8 +57,8 @@ describe('Tests for clipboard', () => {
it('should verify electron clipboard', () => { it('should verify electron clipboard', () => {
return app.client return app.client
.getValue('#tag').then((value) => { .getValue('#tag').then((value) => {
app.electron.clipboard.writeText(value) return app.electron.clipboard.writeText(value)
.electron.clipboard.readText().then(function (clipboardText) { .electron.clipboard.readText().then((clipboardText) => {
expect(clipboardText === 'Test').toBeTruthy(); expect(clipboardText === 'Test').toBeTruthy();
}); });
}); });
@ -54,7 +66,7 @@ describe('Tests for clipboard', () => {
it('should verify electron clipboard copy', () => { it('should verify electron clipboard copy', () => {
return app.electron.clipboard.writeText('Testing copy') return app.electron.clipboard.writeText('Testing copy')
.electron.clipboard.readText().then(function (clipboardText) { .electron.clipboard.readText().then((clipboardText) => {
return app.client.setValue('#tag', clipboardText).getValue('#tag').then((value) => { return app.client.setValue('#tag', clipboardText).getValue('#tag').then((value) => {
expect(value === 'Testing copy').toBeTruthy(); expect(value === 'Testing copy').toBeTruthy();
}); });

View File

@ -1,31 +1,45 @@
const Application = require('./spectronSetup'); const Application = require('./utils/spectronSetup');
const path = require('path'); const path = require('path');
describe('Tests for Notification position', () => { describe('Tests for Notification position', () => {
let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000; jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;
let app; let app;
beforeAll(() => { beforeAll((done) => {
app = new Application({}); app = new Application({});
return app.startApplication().then((startedApp) => {
app = startedApp;
done();
}).catch((err) => {
expect(err).toBeNull();
});
}); });
afterAll(() => { afterAll((done) => {
if (app && app.isRunning()) { if (app && app.isRunning()) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
return app.stop(); app.stop().then(() => {
done();
}).catch((err) => {
console.log(err);
done();
});
} }
}); });
it('should launch the app', () => { it('should launch the app', (done) => {
return app.startApplication().then((startedApp) => { return app.client.waitUntilWindowLoaded().then(() => {
app = startedApp; return app.client.getWindowCount().then((count) => {
return app.client.waitUntilWindowLoaded().then(async () => {
const count = await app.client.getWindowCount();
expect(count === 1).toBeTruthy(); expect(count === 1).toBeTruthy();
}) done();
}).catch((err) => {
expect(err).toBeNull();
});
}).catch((err) => {
expect(err).toBeNull();
}); });
}); });
@ -39,10 +53,15 @@ describe('Tests for Notification position', () => {
return app.client.url(filePath); return app.client.url(filePath);
}); });
it('should load demo html', async () => { it('should load demo html', () => {
return app.client.waitUntilWindowLoaded().then(async () => { return app.client.waitUntilWindowLoaded().then(() => {
const title = await app.client.getTitle(); return app.client.getTitle().then((title) => {
expect(title === '').toBeTruthy(); expect(title === '').toBeTruthy();
}).catch((err) => {
expect(err).toBeNull();
});
}).catch((err) => {
expect(err).toBeNull();
}); });
}); });
@ -57,16 +76,24 @@ describe('Tests for Notification position', () => {
.windowByIndex(1) .windowByIndex(1)
}); });
it('should check notification position', async () => { it('should check notification position', () => {
const bounds = await app.browserWindow.getBounds(); return app.browserWindow.getBounds().then((bounds) => {
expect(bounds.x === 0).toBeTruthy(); expect(bounds.x === 0).toBeTruthy();
expect(bounds.y > 0).toBeTruthy(); expect(bounds.y > 0).toBeTruthy();
}).catch((err) => {
expect(err).toBeNull();
});
}); });
it('should change the window', () => { it('should change the window', () => {
return app.client.windowByIndex(0).then(async () => { return app.client.windowByIndex(0).then(() => {
const title = await app.browserWindow.getTitle(); return app.browserWindow.getTitle().then((title) => {
expect(title === 'Symphony | Secure Seamless Communication').toBeTruthy(); expect(title === 'Symphony | Secure Seamless Communication').toBeTruthy();
}).catch((err) => {
expect(err).toBeNull();
});
}).catch((err) => {
expect(err).toBeNull();
}); });
}); });
@ -78,23 +105,35 @@ describe('Tests for Notification position', () => {
.click('#ok-button') .click('#ok-button')
.windowByIndex(0) .windowByIndex(0)
.click('#notf') .click('#notf')
.windowByIndex(1).then(async () => { .windowByIndex(1).then(() => {
const title = await app.browserWindow.getTitle(); return app.browserWindow.getTitle().then((title) => {
expect(title === 'Electron').toBeTruthy(); expect(title === 'Electron').toBeTruthy();
}).catch((err) => {
expect(err).toBeNull();
});
}).catch((err) => {
expect(err).toBeNull();
}); });
}); });
it('should check notification position and equal to lower-right', async () => { it('should check notification position and equal to lower-right', () => {
const bounds = await app.browserWindow.getBounds(); return app.browserWindow.getBounds().then((bounds) => {
expect(bounds.x > 0).toBeTruthy(); expect(bounds.x > 0).toBeTruthy();
expect(bounds.y > 0).toBeTruthy(); expect(bounds.y > 0).toBeTruthy();
}).catch((err) => {
expect(err).toBeNull();
});
}); });
it('should change the window', () => { it('should change the window', () => {
return app.client return app.client.windowByIndex(0).then(() => {
.windowByIndex(0).then(async () => { return app.browserWindow.getTitle().then((title) => {
const title = await app.browserWindow.getTitle();
expect(title === 'Symphony | Secure Seamless Communication').toBeTruthy(); expect(title === 'Symphony | Secure Seamless Communication').toBeTruthy();
}).catch((err) => {
expect(err).toBeNull();
});
}).catch((err) => {
expect(err).toBeNull();
}); });
}); });
@ -106,23 +145,35 @@ describe('Tests for Notification position', () => {
.click('#ok-button') .click('#ok-button')
.windowByIndex(0) .windowByIndex(0)
.click('#notf') .click('#notf')
.windowByIndex(1).then(async () => { .windowByIndex(1).then(() => {
const title = await app.browserWindow.getTitle(); return app.browserWindow.getTitle().then((title) => {
expect(title === 'Electron').toBeTruthy(); expect(title === 'Electron').toBeTruthy();
}).catch((err) => {
expect(err).toBeNull();
});
}).catch((err) => {
expect(err).toBeNull();
}); });
}); });
it('should check notification position and equal to upper-right', async () => { it('should check notification position and equal to upper-right', () => {
const bounds = await app.browserWindow.getBounds(); return app.browserWindow.getBounds().then((bounds) => {
expect(bounds.x > 0).toBeTruthy(); expect(bounds.x > 0).toBeTruthy();
expect(bounds.y > 0).toBeTruthy(); expect(bounds.y > 0).toBeTruthy();
}).catch((err) => {
expect(err).toBeNull();
});
}); });
it('should change the window to main', () => { it('should change the window to main', () => {
return app.client return app.client.windowByIndex(0).then(() => {
.windowByIndex(0).then(async () => { return app.browserWindow.getTitle().then((title) => {
const title = await app.browserWindow.getTitle();
expect(title === 'Symphony | Secure Seamless Communication').toBeTruthy(); expect(title === 'Symphony | Secure Seamless Communication').toBeTruthy();
}).catch((err) => {
expect(err).toBeNull();
});
}).catch((err) => {
expect(err).toBeNull();
}); });
}); });
@ -132,11 +183,17 @@ describe('Tests for Notification position', () => {
.click('#notf') .click('#notf')
.getWindowCount().then((count) => { .getWindowCount().then((count) => {
expect(count === 3).toBeTruthy(); expect(count === 3).toBeTruthy();
}).catch((err) => {
expect(err).toBeNull();
}) })
.windowByIndex(1).then(() => { .windowByIndex(1).then(() => {
return app.browserWindow.getTitle().then((title) => { return app.browserWindow.getTitle().then((title) => {
expect(title === 'Electron').toBeTruthy(); expect(title === 'Electron').toBeTruthy();
}).catch((err) => {
expect(err).toBeNull();
}); });
}).catch((err) => {
expect(err).toBeNull();
}); });
}); });

View File

@ -9,20 +9,22 @@ class App {
if (!this.options.path){ if (!this.options.path){
this.options.path = App.getAppPath(); this.options.path = App.getAppPath();
this.options.args = [path.join(__dirname, '..', 'js/main.js')]; this.options.args = [path.join(__dirname, '..', '..', 'js/main.js')];
} }
this.app = new Application(this.options); this.app = new Application(this.options);
} }
startApplication() { startApplication() {
return this.app.start().then(() => { return this.app.start().then((app) =>{
return this.app return app;
}).catch((err) => {
console.log(err);
}); });
} }
static getAppPath() { static getAppPath() {
let electronPath = path.join(__dirname, '..', 'node_modules', '.bin', 'electron'); let electronPath = path.join(__dirname, '..', '..', 'node_modules', '.bin', 'electron');
if (process.platform === 'win32') { if (process.platform === 'win32') {
electronPath += '.cmd'; electronPath += '.cmd';
} }