globalworming
globalworming

Reputation: 767

Protractor test does not finish, seems to loop until the jasmine timeout error hits

I feel pretty dumb to not be able to get the most basic protractor test to work. Given protractor 5.4.1 i have a spec.js

describe('my example tests', () => {
  const EC = protractor.ExpectedConditions;
    it('tests google', async () => {
      await browser.waitForAngularEnabled(false);
      await browser.get("https://google.com");
      await browser.wait(EC.visibilityOf($('input')));
      await element(by.css("input")).click();});});

and a conf of

exports.config = {

  directConnect: true,
  specs: ['tests/**/*.js'],
  capabilities: {
    browserName: 'chrome',
  },

  SELENIUM_PROMISE_MANAGER: false,

  jasmineNodeOpts: {
    defaultTimeoutInterval: 40000
  }
};

when running protractor conf.js the browser opens, goes to the page and then nothing happens until the 40s jasmine timeout hits. What I get are ~25 warnings per second
W/element - more than one element found for locator By(css selector, input) - the first result will be used
as if some command is running in an endless loop until I get an error Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. which does not tell me much and is hard to google.

Has anyone experienced this issue?

Upvotes: 0

Views: 109

Answers (1)

Jeremy Kahan
Jeremy Kahan

Reputation: 3826

On the Google page, the locator $('input') matches many elements, which is why you got the warning. The first one was used, but unfortunately, the first one was hidden. so await browser.wait(EC.visibilityOf($('input'))); failed, which gave the timeout error. Using a locator that locates a unique and not hidden input element on the page, like element(by.name('q')) ought to work better.

I like the Hetzner cloud protractor test helper which provides wrappers like waitToBeDisplayed whose error reporting is less generic, if I recall correctly (it has been a while since I used it).

Upvotes: 2

Related Questions