Majesty
Majesty

Reputation: 1909

AngularJS Protractor: randomly fail in headless mode (Firefox)

Here is my conf file.

exports.config = {
  rootElement: '[ng-app="myapp"]',
  framework: 'jasmine',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['./web/assets/e2e/**/*protractor.js'],
  SELENIUM_PROMISE_MANAGER: false,
  baseUrl: 'https://localhost',
  capabilities: {
    browserName: 'firefox',
    marionette: true,
    acceptInsecureCerts: true,
    'moz:firefoxOptions': {
      args: ['--headless'],
    },
  }
}

So with this config my tests fails randomly with the following error

Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.

But! When I comment out following lines

    'moz:firefoxOptions': {
      args: ['--headless'],
    },

which stands for headless mode and watch how firefox run my tests - tests never fail and take 3 time less time.

Below is an example of test that failed a couple of times with the error I mentioned above.

  it('- should test add button open a form', async () => {
    await ClientListPageDriver.openAddClientForm();

    await FormDriver.toBeShown('Add New Client');

    await FormDriver.pressClose();
  });

And here are methods from drivers I referencing

  this.openAddClientForm = async () => {
    const button = await $('button[ng-click="$ctrl.addClient()"]');
    await button.click();
  };

  this.toBeShown = async (title) => {
    const modalElement = await $('#form').element(by.cssContainingText('.form-header h2', title))

    const awaitSeconds = 6;
    return await browser.wait(
      protractor.ExpectedConditions.presenceOf(modalElement),
      awaitSeconds * 1000,
      `Form should be shown within ${awaitSeconds} sec`,
    );
  };

  this.pressClose = async () => {
    const button = await $('button[ng-click="$ctrl.closeForm()"]');
    await button.click();
  };

My question is - what I'm doing wrong, what I'm probably missing and how can I fix it? Thanks!

Upvotes: 1

Views: 175

Answers (1)

Madhan Raj
Madhan Raj

Reputation: 1442

Add the below code to your config

allScriptsTimeout: 20000,
    jasmineNodeOpts: {
    defaultTimeoutInterval: 100000
     }

Adjust the timeout interval as per your test execution time. Refer https://www.theoldschoolhouse.com/reviews_client/node_modules/protractor/docs/timeouts.md for more info

Hope it help you

Upvotes: 2

Related Questions