我将使用Mocha,Chai和selenium webdriver编写一个简单的测试。但它扔我:
错误:超出25000ms超时。确保done()回调是 在这次考试中被召唤。
以下是我使用的代码:
'use strict';
var webdriver = require ('selenium-webdriver'),
chai = require ('chai'),
until = webdriver.until,
By = webdriver.By,
wait = webdriver.wait,
chaiAsPromised = require("chai-as-promised"),
assert = chai.assert,
mocha = require('mocha'),
expect = chai.expect;
chai.config.includeStack = true;
var driver;
describe('Login', function(){
before(function(done){
driver = new webdriver
.Builder()
.withCapabilities(webdriver.Capabilities.chrome())
.build();
driver.get('http://someurl');
driver.findElement(By.id('username')).sendKeys('username');
driver.findElement(By.id('password')).sendKeys('password');
driver.findElement(By.id('Login')).click();
this.timeout(25000);
setTimeout(done, 25000);
});
after(function(done){
driver.quit();
this.timeout(5000);
done();
});
it('verify the waiting for task Button', function(){
driver.wait(until.elementLocated(By.css('.StartButton__btn')))
.then(function(){
driver.findElement(By.css('.StartButton__btn')).click();
});
var waitScreenTest =
driver.findElement(By.css('.WaitingScreen__text')).getText();
assert(waitScreenTest, 'Waiting for Tasks');
});
});
我该如何解决这个问题?
答案 0 :(得分:0)
您问题的标准答案是"返回您的承诺,以便Mocha可以等待他们"。
但是,selenium-webdriver
为Mocha的股票函数提供了包装器。这些函数挂钩到Selenium的承诺机制,并且不需要返回promises或使用done
回调来等待Selenium的驱动程序完成。您只需导入selenium-webdriver/testing
,然后使用该模块提供的describe
,it
,before
,after
,...函数。
var test = require('selenium-webdriver/testing');
test.describe("top level", function () {
test.before(...);
test.it("some test", function () {
});
});