I am struggling with browser.addCommand(), I use WebDriverIO Version 6 + typescript, and when I try to add a command to wdio.conf.js and run the test it fails with error "Unable to compile TypeScript:"
my ts.confg:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": [
"./*"
],
"src/*": [
"./src/*"
],
"test/*": [
"./test/*"
]
},
"sourceMap": false,
"target": "es6",
"module": "commonjs",
"typeRoots": ["./types"],
"types": [
"node",
"@wdio/sync",
"@wdio/jasmine-framework"
],
"include": ["./test/**/*.ts","./types/wdio.d.ts"],
"exclude": [
"./node_modules"
],
}
wdio.d.ts file:
declare module WebdriverIO {
interface Element {
waitAndClick: () => void;
}
}
wdio.conf.js file:
before: function (capabilities, specs) {
browser.addCommand("waitAndClick", function () {
this.waitForDisplayed({timeout: 5000})
this.click()
}, true)
}
in Page Object:
$('.classname').waitAndClick();
I am able to see the method in page object as in the example above. When I trying to run it fails with error "Unable to compile TypeScript: error TS2339: Property 'waitAndClick' does not exist on type 'Element'."
I finally have a solution, you need to add wdio.d.ts to types property in tsconfig.json.
- "types": ["node", "@wdio/sync", "@wdio/jasmine-framework"]
+ "types": ["node", "@wdio/sync", "@wdio/jasmine-framework", "./wdio"]