Glad you enjoyed the content. We have created multiple courses that takes our students from ground level. If you want to become a full stack Automation engineer, Please check out the academy at: sdetunicorns.com/courses/
Hi, I made this changes in my wdio.conf.js so that chai assertion can be assessed from anywhere without importing it. May be it can help others. ----------- beforeTest: function () { const chai = require("chai"); const chaiWebdriver = require("chai-webdriverio").default; chai.use(chaiWebdriver(browser)); global.chaiAssert = chai.assert; global.chaiShould = chai.should; global.chaiExpect = chai.expect; }, ------------------------
Hi Dilpreet, I am still facing an issue with script run. I have setup the configuration and chai assertation and babel. I have also added require: ['@babel/register'] in config file but I am getting below error. Could you please suggest the possible root cause of this? import { expect as chaiExpect } from 'chai'; [0-0] ^^^^^^ [0-0] [0-0] SyntaxError: Cannot use import statement outside a module
Most of the default assertions with WebdriverIO has options to add your own error message. You can take a look at an example here - webdriver.io/docs/api/expect-webdriverio#tohaveelementclass
Thank you sir, you explained it so well....
Glad you enjoyed the content. We have created multiple courses that takes our students from ground level. If you want to become a full stack Automation engineer, Please check out the academy at: sdetunicorns.com/courses/
Hi,
I made this changes in my wdio.conf.js so that chai assertion can be assessed from anywhere without importing it. May be it can help others.
-----------
beforeTest: function () {
const chai = require("chai");
const chaiWebdriver = require("chai-webdriverio").default;
chai.use(chaiWebdriver(browser));
global.chaiAssert = chai.assert;
global.chaiShould = chai.should;
global.chaiExpect = chai.expect;
},
------------------------
Yes, this takes away the pain of importing it everywhere. Thanks for commenting!
Hi Dilpreet, I am still facing an issue with script run. I have setup the configuration and chai assertation and babel. I have also added require: ['@babel/register'] in config file but I am getting below error. Could you please suggest the possible root cause of this?
import { expect as chaiExpect } from 'chai';
[0-0] ^^^^^^
[0-0]
[0-0] SyntaxError: Cannot use import statement outside a module
You will need to install all the babel packages as well. Take a look at this - webdriver.io/docs/babel/
If I want to print my own error message if assertion fails.. then is there any way.. something like assert(expected, actual, error message) ?
Most of the default assertions with WebdriverIO has options to add your own error message. You can take a look at an example here - webdriver.io/docs/api/expect-webdriverio#tohaveelementclass
Hi , How do I continue tests execution after assertion fails. Do we have something like soft assertion ( Selenium webdriver) in webdriverio?
No, WebdriverIO does not support soft assertions and is also not recommended. If you still need it, you can wrap the code around try/catch.