我正在测试一个场景,其中有3个复选框,这些复选框是根据服务调用和http get的响应填充的。
我所拥有的是当我使用protractor conf.js
运行测试时,还没有填充来自http get响应的响应,所以当我尝试测试任何东西时,浏览器停止并且测试失败
是否有方法可以使量角器在运行测试之前等待这些下拉值被填充?
conf.js:
// An example configuration file.
exports.config = {
//directConnect: true,
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
// Framework to use. Jasmine 2 is recommended.
framework: 'jasmine2',
// Spec patterns are relative to the current working directly when
// protractor is called.
specs: ['e2e/*.js'],
baseUrl: 'http://localhost:4000/',
// Options to be passed to Jasmine.
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};
test file:
var select = element(by.model('make'));
console.log(select);
select.$('[value="acura"]').click();
这在click事件上失败,因为当这个测试运行时,select没有选项元素,因为select会从json http get响应中填充。
提前致谢!!
答案 0 :(得分:0)
您可以尝试使用以下方法;在致电点击之前。
browser.waitForAngular();
答案 1 :(得分:0)
使用browser.wait()
-
browser.wait(function(){
return elementPresent.isPresent();
}).then(function(){
element.click();
})
答案 2 :(得分:0)
使用量角器的内置wait()
方法,使用ExpectedConditions
期望下拉列表被填充。这是如何 -
var select = element(by.model('make'));
browser.wait(protractor.ExpectedConditions.presenceOf(select.$('[value="acura"]')), 10000)
.then(function(){
select.$('[value="acura"]').click();
});
希望它有所帮助。