Selenium始终出现“错误:超过2000ms超时" [英] Always getting 'Error: timeout of 2000ms exceeded' with Selenium
问题描述
早上好
我目前正在学习如何使用javascript(使用摩卡)来驱动Selenium.我创建了一个非常基本的测试,这给我在运行时带来了很多麻烦.每当我运行测试时,都会创建一个新的chrome实例,并显示浏览器.最初启动浏览器时,它将在URL框中放置"data:",然后转到google.com.然后,我得到以下错误:
I am currently learning how to drive Selenium with javascript (using mocha). I created a really basic test that is giving me a lot of trouble at runtime. Whenever I run the test a new instance of chrome is created and the browser displays. When the browser initially comes up it places "data:," in the URL box then proceeds to google.com. I then get the following error back:
$摩卡咖啡测试
Array
#indexOf()
✓ 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)
这是测试本身:
var assert = require('assert'),
test = require('selenium-webdriver/testing'),
webdriver = require('selenium-webdriver'),
chrome = require('selenium-webdriver/chrome');
test.describe('Google Search', function() {
test.it('should work', function() {
var chromeOptions = new chrome.Options();
chromeOptions.addArguments(['test-type']);
var driver = new webdriver.Builder().withCapabilities(chromeOptions.toCapabilities()).build();
driver.get('http://www.google.com');
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click();
driver.wait(function() {
return driver.getTitle().then(function(title) {
return title === 'webdriver - Google Search';
});
}, 1000);
driver.quit();
});
});
推荐答案
对我来说,您收到的错误消息看起来像是Mocha超时.在Mocha中设置超时的通常方法是:
The error message you get looks like a Mocha timeout to me. The normal way to set a timeout in Mocha is:
it("foo", function () {
this.timeout(value);
...
});
其中,value
是您想要的任何值(以毫秒为单位).值为0将关闭Mocha的超时.默认值为2000ms.
where value
is whatever value you want (in ms). A value of 0 turns off Mocha's timeouts. The default is 2000ms.
这篇关于Selenium始终出现“错误:超过2000ms超时"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!