Suhail Ahmed
Suhail Ahmed

Reputation: 554

wait for http request to complete in protractor

I am trying to wait for spinner to disappear and then for my steps to execute but nothing is working for me.

browser.wait(function () {

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

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

and i even tried with

browser.wait(function () {

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

even with below method

browser.sleep(1000);

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

if (result === true) {

var EC = protractor.ExpectedConditions;

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

then only thing that works is

browse.sleep(10000);

i don't want to use sleep in my code. can anyone help me with how to wait for complete http request to complete and then process with testing

Upvotes: 1

Views: 3416

Answers (1)

LostJon
LostJon

Reputation: 2387

you should consider using Expected Conditions since they return true/false based on current conditions

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

so your test case would become:

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

UPDATE

in order to use done, you would generally pass this cb into your it() function. This means your test could look like

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();
    })
  })
});

Since your entire code isn't posted up here, you should have something similar to:

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

Upvotes: 2

Related Questions