Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138163

get a meaningful stack trace with mocha and selenium-webdriver js

$
0
0

When I can't find an element in a JavaScript selenium test, it doesn't give me an easy way to find out which line failed:

Here is an example:

// test.js

const webdriver = require('selenium-webdriver');
const Builder = webdriver.Builder;
const By = webdriver.By;

describe('web driver', function() {
  let driver;
  beforeEach(function() {
    return new Builder().forBrowser('chrome').build().then(function(_driver) {
      driver = _driver;
    });
  });

  it('should always be able to find the element', function() {
    return driver.findElement(By.name('test-element'));
  });

  afterEach(function() {
    return driver.quit();
  });
});

When run like this:

npm install selenium-webdriver@4.0.0-alpha.1
npm install mocha@6.0.2
nvm install 8.15.1
nvm use 8.15.1
node_modules/.bin/mocha test.js

I get the following error:

     NoSuchElementError: no such element: Unable to locate element: {"method":"css selector","selector":"*[name="test-element"]"}
  (Session info: chrome=72.0.3626.121)
  (Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 4.15.0-46-generic x86_64)
      at Object.checkLegacyResponse (node_modules/selenium-webdriver/lib/error.js:585:15)
      at parseHttpResponse (node_modules/selenium-webdriver/lib/http.js:533:13)
      at Executor.execute (node_modules/selenium-webdriver/lib/http.js:468:26)
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:189:7

which is easy to make sense of in this test, but it is really hard in longer tests as it does not give me a line of my test, and I am often searching for the same element more than once.

Is there a way to fix this?

(my actual tests are with async/await, but I did this example without and the problem is the same)


Viewing all articles
Browse latest Browse all 138163

Trending Articles