摩卡硒测试简单的例子不起作用

时间:2014-10-04 16:36:12

标签: selenium mocha

我试图了解如何一起使用摩卡和硒。我找到了一个简单的教程但是一旦启动我就会收到以下错误

Google Search
    1) should work

0 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)

这是我的代码

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

test.describe('Google Search', function() {
    test.it('should work', function() {
       var driver = new webdriver.Builder().
           withCapabilities(webdriver.Capabilities.firefox()).
           build();
       driver.get('http://www.google.com');
       var searchBox = driver.findElement(webdriver.By.name('q'));
       searchBox.sendKeys('simple programmer');
       searchBox.getAttribute('value').then(function(value) {
            assert.equal(value, 'simple programmer');
       });
       driver.quit();
     });
});

所以我运行以下命令来测试selenium-webdriver,它只对mocha

失败
npm test selenium-webdriver

我得错误

1) Mocha Integration it properly allows timeouts and cancels control flow :
 Error: timeout of 1000ms exceeded
  at Test.done (/usr/local/lib/node_modules/mocha/lib/runnable.js:204:67)
  at Test.runnable.callback.mochaCallback (/Users/jcostanzo/Work/Development/automation/phantomjs/node_modules/selenium-webdriver/test/testing/index_test.js:61:30)
  at Test.cleanupBeforeCallback [as callback] (/Users/jcostanzo/Work/Development/automation/phantomjs/node_modules/selenium-webdriver/testing/index.js:123:52)
  at null.<anonymous> (/usr/local/lib/node_modules/mocha/lib/runnable.js:157:10)
  at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)

1 个答案:

答案 0 :(得分:1)

您可以通过this.timeout(5000)功能或describe功能调用it来延长超时时间。

在此处查找所有详细信息和示例:http://visionmedia.github.io/mocha/#suite-specific-timeouts