使用 browser.wait() 重复同步地重试相同的 actions/jobs

Using browser.wait() to do retry same actions/jobs repeatedly and synchronously

我在同步做事或在量角器中一次又一次地重试相同的动作时遇到了很多困难。我有一种方法似乎不是最好的方法,但仍然有效。 诀窍是利用 browser.wait()

我已经针对其中一种情况实施了上面的操作,其中计数器在执行特定操作后没有立即更新,并且想比较 action.To 之前和之后的计数器值,以获得需要刷新的正确更新值在 UI.

中更新计数器之前多次浏览器

以下函数重试 5 次以检查计数器是否在退出之前更新。

//  icount : initial counter value(already fetched)
//  fcount : final counter value
//  foo : function used to fetch counter value
//  val : Maximum # of retries

 this.retryVerification = function(icount,foo,val){
            var retry = 0;
            browser.wait(function(){
                browser.refresh();
                browser.sleep(1000);
                var fcount = foo();
                return fcount.then(function(fcount){
                    fcount = parseInt(fcount);
                    retry = retry + 1;
                    return (fcount == (icount+1) || retry == val);
                });
            });
        };

你试过waitForAngular这样吗:

browser.waitForAngular();

你可以参考这个API: Protractor API for waitForAngular