- Cucumber Test Scenario
@login
Scenario: Test signin link
Given the user goes to "example.com"
When the user clicks on login button
Then the current page is the login page
Hi, Whenever chai/'Chai as promise' assertion fails my test execution stops abruptly, instead of making the corresponding cucumber step fail. If a scenario has 5 cucumber DSL step and if assertion fails in 2nd step test execution I expect test result should be
- 1 scenario (1 failed)
- 5 steps (1 failed, 3 skipped, 1 passed)
But I get test result like below with error code 199
- Step Definition
this.When(/^the user clicks on login button$/, function() { browser.ignoreSynchronization = false; return browser.wait(wagHomePage.elements.signIn.isDisplayed().then(function(visible) { if (visible) { wagHomePage.elements.signIn.click().then(function() { expect(visible).to.be.true; }); } else { chai.assert.isTrue(false); } })); }); this.Then(/^the current page is the login page$/, function() { expect(wagLoginPage.elements.pageIdentifier.isDisplayed()).to.eventually.be.true; });
@login
Scenario: Test signin link
√ Given the user goes to "example.com"
[19:58:02] E/launcher - expected false to be true
[19:58:02] E/launcher - AssertionError: expected false to be true
at doAsserterAsyncAndAddThen (C:\JS_UIAutomation\node
_modules\chai-as-promised\lib\chai-as-promised.js:293:29)
at .<anonymous> (C:\JS_UIAutomation\node_modules\chai
-as-promised\lib\chai-as-promised.js:283:21)
at get (C:\JS_UIAutomation\node_modules\chai\lib\chai
\utils\overwriteProperty.js:50:37)
at Function.assert.isTrue (C:\JS_UIAutomation\node_mo
dules\chai\lib\chai\interface\assert.js:332:31)
at C:\JS_UIAutomation\example_site_tests\step_defin
itions\wagLogin_definition.js:23:29
at elementArrayFinder_.then (C:\Users\username\AppData\Roaming\npm\node_modules\protractor\lib\element.ts:840:
22)
at ManagedPromise.invokeCallback_ (C:\Users\username\AppData\Roaming\npm\node_modules\protractor\node_modules\
selenium-webdriver\lib\promise.js:1366:14)
at TaskQueue.execute_ (C:\Users\username\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-web
driver\lib\promise.js:2970:14)
at TaskQueue.executeNext_ (C:\Users\username\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium
-webdriver\lib\promise.js:2953:27)
at asyncRun (C:\Users\username\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib
\promise.js:2813:27)
[19:58:02] E/launcher - Process exited with error code 199
Please help me to get proper test result like
- 1 scenario (1 failed)
- 5 steps (1 failed, 3 skipped, 1 passed)
return browser.wait(wagHomePage.elements.signIn.isDisplayed().then(function(visible) { if (visible) { wagHomePage.elements.signIn.click().then(function() { expect(visible).to.be.true; }); } else { chai.assert.isTrue(false); } }));You are first waiting for the element to be displayed, if it is visible, you are clicking on something (that resolves in a promise) and then use the previous result in an expect. Can you explain this? - wswebcreationC:\JS_UIAutomation\example_site_tests\step_definitions\wagLogin_definition.js:23:29. Can you add a string to your expect like thisexpect(visible).to.equal(true, 'Descriptive message: ');- wswebcreation