【问题标题】:wait for http request to complete in protractor在量角器中等待 http 请求完成
【发布时间】:2017-08-08 00:51:27
【问题描述】:

我正在尝试等待微调器消失,然后执行我的步骤,但对我没有任何效果。

browser.wait(function () {

return this.spinner.isDisplayed().then(function (result) {

return !result;});}, 20000);

我什至尝试过

browser.wait(function () {

return !browser.isElementPresent(this.spinner);}, 20000);

即使使用以下方法

browser.sleep(1000);

this.spinner.isPresent().then(function (result) {

如果(结果 === 真){

var EC = protractor.ExpectedConditions;

browser.wait(EC.invisibilityOf(this.spinner), 10000);}});

那么唯一有效的是

browse.sleep(10000);

我不想在我的代码中使用睡眠。任何人都可以帮助我如何等待完整的 http 请求完成然后处理测试

【问题讨论】:

  • 你能提供this.spinner是什么吗?
  • 另外,当你说它失败时,这是什么意思?你有什么错误吗?
  • this.spinner 是微调器的 xpath,"element(by.xpath('//div[contains(@class="spinner")]'))" 如果在时间过去之前,微调器不会显示,然后我们会收到错误消息,提示找不到元素。

标签: protractor jasmine2.0


【解决方案1】:

您应该考虑使用预期条件,因为它们根据当前条件返回真/假

http://www.protractortest.org/#/api?view=ProtractorExpectedConditions.prototype.invisibilityOf

所以你的测试用例会变成:

browser.wait(EC.invisibilityOf(this.spinner),20000).then(function(){
    ...continue test, spinner gone
});

更新

为了使用done,您通常会将此cb 传递给您的it() 函数。这意味着您的测试可能看起来像

describe("example describe",function(){
  it("should be an example only", function(done){
    request.get("www.google.com",function(res){
      //done with async request, now call done
      done();
    })
  })
});

由于您的整个代码没有在这里发布,您应该有类似的内容:

it("should wait for spinner to go bye-bye",function(done){
  browser.wait(EC.invisibilityOf(this.spinner),20000).then(function(){
    done()
  });
});

【讨论】:

  • 在您的回调中(即.then)您是否调用done() 来标记异步完成?
  • 没有。我不知道 done() 你能帮我试试吗。
  • 查看更新了解更多信息
猜你喜欢
  • 1970-01-01
  • 2018-07-19
  • 1970-01-01
  • 1970-01-01
  • 2017-07-04
  • 2019-05-19
  • 1970-01-01
  • 1970-01-01
  • 2016-04-01
相关资源
最近更新 更多