Always getting "Error: Exceeding 2000ms" with Selenium

Good morning,

I am currently studying how to manipulate selenium with javascript (using mocha). I have created a really basic test that gives me a lot of runtime problems. Whenever I run the test, a new instance of chrome is created and the browser is displayed. When the browser first appears, it puts "data:" in the URL field, then goes to Then I get the following error:

$ mocha test

      ✓ should return -1 when the value is not present! 

  Google Search
    1) should work

  1 passing (2s)
  1 failing

  1) Google Search should work:
     Error: timeout of 2000ms exceeded
      at null.<anonymous> (/usr/local/lib/node_modules/mocha/lib/runnable.js:157:19)
      at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)


Here's the test itself:

var assert = require('assert'),
    test = require('selenium-webdriver/testing'),
    webdriver = require('selenium-webdriver'),
    chrome = require('selenium-webdriver/chrome');

test.describe('Google Search', function() {'should work', function() {
    var chromeOptions = new chrome.Options();

    var driver = new webdriver.Builder().withCapabilities(chromeOptions.toCapabilities()).build();

    driver.wait(function() {
     return driver.getTitle().then(function(title) {  
       return title === 'webdriver - Google Search';
    }, 1000);



source to share

2 answers

The error message you are getting is similar to Mocha timeout. The usual way to set a timeout in Mocha is:

it("foo", function () {


where value

is whatever value you want (in ms). A value of 0 disables Mocha timeouts. The default is 2000ms.



IF it crashes somewhere particularly consistently, you might want to consider calling driver.Manage().Timeouts()



doesn't really wait as it does Thread.sleep()

, it just sets the maximum driver timeout for implicit waits. It's enough to just call it once at the beginning of your code (with a 20 second parameter). Read up on ImplicitlyWait and the WebDriverWait class.

As far as I can remember (when I should have used) this is because you did not receive a response at the expected / default time.



All Articles