question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Help with WDIO Testrunner and Spectron

See original GitHub issue

I 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');
    });
  });
});

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:open
  • Created 7 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

5reactions
anth0dcommented, May 9, 2017

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.

0reactions
rafalradomskicommented, Oct 10, 2017

Can we use browser WDIO in spectron?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration File - WebdriverIO
The configuration file contains all necessary information to run your test suite. It's a NodeJS module that exports a JSON.
Read more >
webdriverio/webdriverio - Gitter
I'm able to attach debugger with wdio and VS code but the debugger doesn't pause at breakpoints.
Read more >
Chapter 13. Testing applications with Spectron - Electron in ...
Using Spectron to test Electron applications; Understanding the relationship among Spectron, WebdriverIO, and Selenium WebDriver; Controlling Electron APIs ...
Read more >
@goosewobbler/spectron - npm
Easily test your Electron apps using ChromeDriver and WebdriverIO.. Latest version: 17.0.0-beta2, last published: 9 months ago.
Read more >
End-to-end testing with GitLab CI/CD and WebdriverIO
We'll get to running the above test in CI/CD in a moment. When writing tests, however, it helps if you don't have to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found