简体   繁体   English

在JavaScript量角器中使用browser.wait()

[英]Use of browser.wait() in javascript-protractor

Is it a good approach to use browser.wait() for each and every element in javascript-protractor? 为javascript-protractor中的每个元素使用browser.wait()是一个好方法吗? Is their any other better approach? 他们还有其他更好的方法吗?

browser.wait() You provide an Expected Condition function for Protractor/WebDriverJS to execute and wait for the result of the function to evaluate to true. browser.wait()您为Protractor/WebDriverJS提供了一个Expected Condition函数,以便执行并等待该函数的结果评估为true。 Protractor would continuously execute the function and stop once the result of the function evaluates to true or a configurable timeout has been reached. 量角器将连续执行该函数,并在函数结果评估为true或达到可配置的超时后停止。

browser.wait(EC.textToBePresentInElement(element(by.binding('myvar')), "expected"), 5000, "Text is not something I've expected");

var EC = protractor.ExpectedConditions;

var anyTextToBePresentInElement = function(elementFinder) {
  var hasText = function() {
    return elementFinder.getText().then(function(actualText) {
      return actualText;
    });
  };
  return EC.and(EC.presenceOf(elementFinder), hasText);
};

If you want to have some wait before finding each element then you should go with implicit wait.. 如果要在查找每个元素之前先等待一下,则应该使用隐式等待。

description for implicit wait 隐式等待的描述

If not on each find element then if you are using wait with some condition like wait for element/ element to be clickable ( Expected conditions) or like page to contain something[smart wait] then its good l, Else its not good idea to implement hardocded wait[ browser.sleep()]. 如果不在每个find元素上,则如果您使用带有某种条件的等待,例如,等待元素/元素可单击(预期条件)或喜欢页面包含某些内容[智能等待],则其效果很好,否则实现它不是一个好主意hardocded wait [browser.sleep()]。

Refer below link:- 参考以下链接:

Smart/Explicit waits 智能/显式等待

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM