1
votes

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

1
can you provide what is this.spinner? - nilesh
Also when you say it fails, what does that mean? Do you get any error? - nilesh
this.spinner is xpath of the spinner, "element(by.xpath('//div[contains(@class="spinner")]'))" and the problem is here if the the spinner is not displayed before time passes out then we get error message message saying the no element found. - Suhail Ahmed

1 Answers

1
votes

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