简体   繁体   English

如何在量角器中使用 browser.wait 命令?

[英]How to use browser.wait command in Protractor?

I have my test-data(element finder and element ids) in json file and parsing in my test scripts to perform the test.我在 json 文件中有我的测试数据(元素查找器和元素 ID),并在我的测试脚本中解析以执行测试。 The issue I have here is , I put browser.sleep after each element for the respective element to occur on the DOM.我在这里遇到的问题是,我将 browser.sleep 放在每个元素之后,以便在 DOM 上出现相应的元素。 but I want to replace that browser.sleep with browser.wait since browser.sleep is not the best practice.但我想用 browser.wait 替换那个 browser.sleep,因为 browser.sleep 不是最佳实践。 below is my code.下面是我的代码。 please give your suggestions how to replace browser.sleep with wait command.请就如何用 wait 命令替换 browser.sleep 给出您的建议。

var controlData = require("../../TestData/EmailForm/e2e_Test.json");
        var controlKeys;
        var respose;
        var testData;

        function(callback){
            controlKeys=["BtnEmailChkBox","BtnUpdate","TrueEmailGetAttribute"];
            async.eachSeries(controlKeys,function(key,next){
                commands.execute(testConfig,controlData[key],function(err,res){
                    respose = res[0].data;
                    testData = controlData[key].actions[0].data;
                    expect(respose).toEqual(testData);
                    browser.sleep(5000);
                    next();
                });
            },function(err){
                callback();
            })
        },

You could write custom wait function as utils for you test or you could write it directly.您可以编写自定义等待函数作为测试用的工具,也可以直接编写。 For this purpose Protractor provide browser.wait() function.为此, Protractor提供browser.wait()函数。

First argument is a function predicate, you could take a look at predefined functions in ExpectedConditions namespace.第一个参数是函数谓词,您可以查看ExpectedConditions命名空间中的预定义函数。

Second one is optional and define how long to wait for the condition to be true.第二个是可选的,定义等待条件为真的时间。

Third one is also optional and define the message to use if the wait times out.第三个也是可选的,它定义等待超时时要使用的消息。

browser.wait(
  ExpectedConditions.presenceOf(your_element),
  how_long_you_want_to_wait_in_ms
  optional_third_parameter_could_be_error_message
)

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

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