Javascript “内部超时”;“在每个之前”;不受考试的尊重
我知道为了测试API端点,应该模拟xhtml请求,但现在我想用真正的API来测试它 我想做什么: 打开一个页面,单击“连接”按钮,然后等待最长10秒钟,以使某个元素的Javascript “内部超时”;“在每个之前”;不受考试的尊重,javascript,selenium,selenium-webdriver,automated-tests,mocha.js,Javascript,Selenium,Selenium Webdriver,Automated Tests,Mocha.js,我知道为了测试API端点,应该模拟xhtml请求,但现在我想用真正的API来测试它 我想做什么: 打开一个页面,单击“连接”按钮,然后等待最长10秒钟,以使某个元素的内部文本更改为“已连接” 下面是我的简单测试代码: const assert = require('assert'); const webdriver = require('selenium-webdriver'); const By = webdriver.By; const until = web
内部文本更改为“已连接”
下面是我的简单测试代码:
const assert = require('assert');
const webdriver = require('selenium-webdriver');
const By = webdriver.By;
const until = webdriver.until;
const chrome = require('selenium-webdriver/chrome');
const test = require('selenium-webdriver/testing');
const mochaTimeOut = 25000;
test.beforeEach(function() {
this.timeout(mochaTimeOut);
driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();
driver.get('http://127.0.0.1/dist/popup.html');
});
test.afterEach(function() {
driver.quit();
});
test.describe('Connect functionality', function() {
test.it('Try to connect', function(done) {
// this.timeout(22222); // only works if I uncomment this line
driver.findElement(By.id('connect')).click().then(function (el) {
driver.findElement(By.id('state')).then(function (stateEl) {
driver.wait(until.elementTextContains(stateEl, 'Connected'), 10000);
})
}).then(done);
});
});
如果按原样运行此测试,则会出现以下错误:
错误:超过2000毫秒的超时时间。对于异步测试和挂钩,确保调用“done()”;如果返回承诺,请确保它已解决
但如果我取消注释这一行,它会起作用:
// this.timeout(22222);
我真的不喜欢使用超时,但我看不到其他解决方法。对timeout
的调用是分层的。问题是您的之前每个都没有子项。您需要全局设置超时,或者可以在测试中复制超时。请描述调用:
test.describe('Connect functionality', function() {
this.timeout(mochaTimeout);
这样,它将应用于测试中的所有测试。描述块