0

I am learning protractor but I am facing a problem with a "Promise" error. I read Mocha testing with promises: Error: Timeout of 2000ms exceeded and https://github.com/angular/protractor/blob/master/docs/control-flow.md#disabling-the-control-flow but I am still stuck in this simple code.

Basically if I add the line element(by.css(gotograb_css)).click();

There will be an error Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

Do I add a .then () after this ? I tried it and the error is still there even with done() at the end of the script.

My test framework in config.js for protractor is mochai

Background 1.The element css is correct as I can run it in Selenium / Java.

  1. I try this
it("testing site", (done)=> {

 .......
   done();
})

It does not work out too. Same error

var title_css = "h1[ng-bind='::$ctrl.primaryText']";
var gotograb_css = "a[ng-bind='::$ctrl.linkoutText']";

  it("testing site", ()=> {

    browser.get('https://www.eat24.com/');

    let EC = protractor.ExpectedConditions; // 
    let title_element = element(by.css(title_css)); 
    let condition = EC.presenceOf(title_element);
    browser.wait(condition, 30000)
    element(by.css(gotograb_css)).click(); //ERROR 

  })
john
  • 413
  • 7
  • 16

3 Answers3

0

I think the problem is that the browser.wait function is not getting resolved.
Try this:

    let condition = EC.presenceOf(title_element);
    return browser.wait(condition, 30000)
        .then(function () {
            return element(by.css(gotograb_css)).click();
        });        
Joaquin Casco
  • 704
  • 5
  • 14
0

Looks like you have global timeout set to 2000 ms in your config.

And what happens is you try to wait up to 30 sec, which obviously more than your global timeout.

So just open the config and see if this is the case

Sergey Pleshakov
  • 7,964
  • 2
  • 17
  • 40
0

If you are working with mocha probably you will need disable timeout adding to config file something like this:

  mochaOpts: {
    enableTimeouts: false
  },
Rubén Pozo
  • 1,035
  • 1
  • 12
  • 23