[英]Wait until condition is met Selenium-Webdriver
I am trying to create additional conditions on top of the selenium-webdriver conditions. 我正在尝试在selenium-webdriver条件之上创建其他条件。 I am still trying to grasp the complete concept of promises and callbacks.
我仍在尝试理解promise和回调的完整概念。 I have drastically improved thanks to the help of stack overflow.
由于堆栈溢出的帮助,我得到了极大的改进。 I am unsure of how to repeat a condition every so many seconds in javascript.
我不确定如何在JavaScript中每隔这么多秒重复一次条件。 My inheritance may be wrong as well.
我的继承权也可能是错误的。
var WebElementCondition = require('./selenium-webdriver/lib/until');
var ExpectedConditions = function()
{
this.waitForWindowWithTitle = function (title)
{
return driver.getAllWindowHandles().then(function (title, handles) {
console.log(handles.length + ' .then function');
for (var window in handles) {
if (window.title === title)
{
return true;
}
else
{
return false;
}
}
});
}
}
module.exports = ExpectedConditions;
require('util').inherits(module.exports, WebElementCondition);
In waitForWindowWithTitle function would I do something like 在waitForWindowWithTitle函数中,我会做些什么
return driver.wait(10000).then(function() {
driver.getAllWindowHandles().then(function (title, handles) {
console.log(handles.length + ' .then function');
for (var window in handles) {
if (window.title === title)
{
return true;
}
else
{
return false;
}
}
});
});
You can use wait
which accepts any JS function to create custom conditions. 您可以使用
wait
来接受任何JS函数来创建自定义条件。 Here is an example that checks when angular is ready. 这是检查角度准备就绪的示例。
// Wait for Angular to Finish
function angularReady(): any {
return $browser.executeScript("return (window.angular !== undefined) && (angular.element(document).injector() !== undefined) && (angular.element(document).injector().get('$http').pendingRequests.length === 0)")
.then(function(angularIsReady) {
return angularIsReady === true;
});
}
$browser.wait(angularReady, 5000).then(...);
wait<T>(condition: promise.Promise<T> | until.Condition<T> | ((driver: WebDriver) => T) | Function, timeout?: number, opt_message?: string): promise.Promise<T>;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.