Harisha K P
Harisha K P

Reputation: 357

Protractor: How to resolve promise and stop skipping of scenarios if one scenario fails

I have a Protarctor-CucumberJS framework and a suite of test scenarios. When I execute the entire suite, one script fails at an expect (ChaiJS) statement.

Scenario 1  : Passed
Scenario 2  : Passed
Scenario 3  : Failed (Unresolved Promise)
Scenario 4  : Skipped
Scenario 5  : Skipped
Scenario 6  : Skipped
Scenario 7  : Skipped
Scenario 8  : Skipped
Scenario 9  : Skipped
Scenario 10 : Skipped

The step definition of that particular step looks like this:

Then('I verify if valid success message received as {string}', function (successMessage) {
    expect($(.abc).getText()).to.eventually.equal(successMessage);
});

Due to a defect, app is not showing an error, the element: $(".abc") is not displayed on screen and this scenario fails after 30 seconds of function time-out. Complete error is pasted below. But the problem is all other scenarios after this are skipped with the same error message.

Error: function timed out, ensure the promise resolves within 30000 milliseconds at Timeout._time.default.setTimeout [as _onTimeout] (C:\bla\bla\node_modules\cucumber\lib\user_code_runner.js:81:20) at ontimeout (timers.js:436:11) at tryOnTimeout (timers.js:300:5) at listOnTimeout (timers.js:263:5) at Timer.processTimers (timers.js:223:10)

Questions:

  1. How can I avoid skipping of preceding scenarios if one scenario fails?
  2. How to resolve the promise in situations like above.

Upvotes: 5

Views: 296

Answers (1)

Joaquin Casco
Joaquin Casco

Reputation: 734

Are you able to use async functions? If so you could try with a conditional for if the element is present or not, something like this:

    Then('I verify if valid success message received as {string}', async function (successMessage, done) {
        const abcElement = await $(.abc).isPresent();
        if (abcElement) {
            expect(await $(.abc).getText()).to.eventually.equal(successMessage);
            done();
        } else {
            done();
        }
    });

Upvotes: 2

Related Questions