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.

v4 wdio-mocha-framework behaves incorrectly when using ".only"

See original GitHub issue

Hey, I’m running into a few issues when using wdio cli to run Mocha tests:

  1. When .only is appended to a describe, Webdriver seems to ignore it and incorrectly continues to run all test suites in the spec file.
  2. When .only is appended to an it test case, it correctly becomes the only test case to run, but suffers from a different problem: it runs asynchronously instead of synchronously.

For example, the code below has two identical tests, but one is sync and the other is async. When the suite is run, Test 1 passes and Test 2 fails. When Test 1 is appended with .only, it fails. When Test 2 is appended with .only, it passes.

describe('sanity tests', function () {
    it('Test 1: sync google search', function (done) {
        browser.url('https://www.google.com');
        browser.setValue('input[type="text"]', 'test search string');
        browser.click('button[type="submit"]');
        browser.pause(1000);
        assert.equal(browser.getTitle(), 'test search string - Google Search', "Search title is incorrect");
    });

    it('Test 2: async google search', function (done) {
        browser.url('https://www.google.com')
            .setValue('input[type="text"]', 'test search string')
            .click('button[type="submit"]')
            .pause(1000)
            .getTitle(function(err, title) {
                assert.equal(browser.title, 'test search string - Google Search', "Search title is incorrect");
            })
            .call(done);
    });
});

Node modules being used:

    "mocha": "2.4.5",
    "selenium-standalone": "4.9.0",
    "wdio-mocha-framework": "0.2.11",
    "webdriverio": "4.0.3"

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
christian-bromanncommented, May 11, 2016

Just fyi: describe.only won’t work because each spec file runs in its own child process and doesn’t know about other files. We will introduce a global grep/fgrep option with #1247

3reactions
albertogasparincommented, Aug 17, 2016

FYI, I’ve implemented a “quick and dirty” solution to support it (I prefer a slower bootstrap than having my entire suite running because I forgot .only is not working as it should):

// wdio.conf.js
function getTestFiles(filesPattern) {
  let glob = require('glob');
  let fs = require('fs');
  let files = glob.sync(filesPattern, { cache: true });
  let singleSpec;
  files.some((f) => fs.readFileSync(f).indexOf('describe.only') >= 0 && (singleSpec = f));
  return singleSpec || filesPattern;
}

let config = {
  specs: [
    getTestFiles('./tests/**/*.spec.js'),
  ],
  //...
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

webdriverio/webdriverio - Gitter
Hello, I have a question…If an inputfield is not visible on the page, but it exists, can i use the command browser.setValue()? (wdio...
Read more >
Mocha documentation — DevDocs
WARNING: Exclusive tests are incompatible with parallel mode. The exclusivity feature allows you to run only the specified suite or test-case by appending...
Read more >
Organizing Test Suite - WebdriverIO
Once your tests have several spec files, you should start running your tests concurrently. To do so, adjust the maxInstances property in your...
Read more >
How to debug webdriverio in standalone mode?
client() , you you won't been to deal with it anymore. Just pick a framework to run your test-cases (Mocha, Cucumber, or Jasmine)...
Read more >
WebdriverIO Tutorial: Browser Commands for Selenium Testing
WebdriverIO is a very well known End to End JavaScript framework for automation ... How To Handle Browser Windows With WebdriverIO Commands?
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