Help with WDIO Testrunner and Spectron
See original GitHub issueI am adapting an existing test suite (using mocha and chai/chai as promised) using WDIO Testrunner to use an electron version of the app the tests were originally written for. The example in the documentation of a test with chai as promised does not use a test runner file, just a standalone test, nor can I find an example of WDIO Testrunner being used elsewhere in the documentation. Is it possible to use WDIO Testrunner in conjunction with Spectron? When I try to configure the testrunner file to use the electron app instead of chrome (via chromeOptions: {binary: ‘path’}), the app launches, but all tests timeout and fail.
The documentation indicates that Spectron exposes the client property of an Application instance. The current set of tests I have use the browser global object. How are these two objects related, and is there some straight-forward way of converting these objects? There also does not seem to be a clear cut way of exposing the client property from the test runner file itself, is this correct?
From a maintainability perspective, it would be really beneficial if I could simply write a different Testrunner file specific to the electron app that utilises the same underlying test files as the web app. Is this possible?
Here’s my Testrunner file and an example of the tests I am trying to run:
wdio.conf.js
exports.config = {
host: 'localhost',
port: '4444',
path: '/wd/hub',
specs: [
'./ui/*.js'
],
maxInstances: 1,
capabilities: [{
browserName: 'chrome',
chromeOptions: {
// binary: 'path/to/electron/app'
}
}],
logLevel: 'silent',
sync: false,
coloredLogs: true,
screenshotPath: './errorShots/',
baseUrl: 'http://localhost:3000',
waitforTimeout: 19500,
framework: 'mocha',
mochaOpts: {
timeout: 20000
},
reporters: ['dot'],
reporterOptions: {
outputDir: './logs/'
},
before: function() {
var chai = require('../service/node_modules/chai/chai');
var chaiAsPromised = require('../service/node_modules/chai-as-promised');
expect = chai.expect;
chai.Should();
chai.use(chaiAsPromised);
chaiAsPromised.transferPromiseness = browser.transferPromiseness;
//File specifying ui actions -- defines custom commands
require('./framework/app_extensions.js');
}
};
Example test
describe("Menu tests", function() {
console.log('\nMenu Tests:')
// check Menu visibility
describe("Menu visibility", function() {
it("should be visible", function() {
return browser
.openApp() // contained in app_extensions.js
.isVisible('.menu').should.eventually.be.true
.isVisible('#dropdownModelsMenu').should.eventually.be.true;
});
});
// check Model submenu
describe("Models Menu", function(){
var modelsMenuId = "#dropdownModelsMenu";
var modelsSubMenu = ["#open-model", "#import-model", "#save-project", "#export-model", "#delete-project"];
it("should open the submenu", function() {
return browser
.openApp()
.waitForEnabled(modelsMenuId)
.click(modelsMenuId)
.waitForVisible(modelsSubMenu[0])
.isVisible(modelsSubMenu[0]).should.eventually.be.true
.isVisible(modelsSubMenu[1]).should.eventually.be.true
.isVisible(modelsSubMenu[2]).should.eventually.be.true
.isVisible(modelsSubMenu[3]).should.eventually.be.true
.isVisible(modelsSubMenu[4]).should.eventually.be.true;
});
it("should disable submenu options when model not loaded", function() {
return browser
.openApp()
.waitForEnabled(modelsMenuId)
.click(modelsMenuId)
.getAttribute(modelsSubMenu[2], 'class').should.eventually.contain('disabled')
.getAttribute(modelsSubMenu[3], 'class').should.eventually.contain('disabled')
.getAttribute(modelsSubMenu[4], 'class').should.eventually.contain('disabled');
});
});
});
describe("Menu tests", function() {
console.log('\nMenu Tests:')
// check Menu visibility
describe("Menu visibility", function() {
it("should be visible", function() {
return browser
.openApp() // contained in app_extensions.js
.isVisible('.menu').should.eventually.be.true
.isVisible('#dropdownModelsMenu').should.eventually.be.true;
});
});
// check Model submenu
describe("Models Menu", function(){
var modelsMenuId = "#dropdownModelsMenu";
var modelsSubMenu = ["#open-model", "#import-model", "#save-project", "#export-model", "#delete-project"];
it("should open the submenu", function() {
return browser
.openApp()
.waitForEnabled(modelsMenuId)
.click(modelsMenuId)
.waitForVisible(modelsSubMenu[0])
.isVisible(modelsSubMenu[0]).should.eventually.be.true
.isVisible(modelsSubMenu[1]).should.eventually.be.true
.isVisible(modelsSubMenu[2]).should.eventually.be.true
.isVisible(modelsSubMenu[3]).should.eventually.be.true
.isVisible(modelsSubMenu[4]).should.eventually.be.true;
});
it("should disable submenu options when model not loaded", function() {
return browser
.openApp()
.waitForEnabled(modelsMenuId)
.click(modelsMenuId)
.getAttribute(modelsSubMenu[2], 'class').should.eventually.contain('disabled')
.getAttribute(modelsSubMenu[3], 'class').should.eventually.contain('disabled')
.getAttribute(modelsSubMenu[4], 'class').should.eventually.contain('disabled');
});
});
});
I have been looking into this over the past few days haven’t met much with success. Any help would be greatly appreciated. Thanks.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:6
Top GitHub Comments
Can we get a response on this issue @kevinsawicki ? It seems like Spectron was not designed for use with WDIO testrunner. I have had no success trying to use my existing WebdriverIO test framework with Spectron.
Can we use browser WDIO in spectron?