I tried implementing custom commands in TypeScript based on the WebdriverIO documentation, but unfortunately, I wasn't able to get it working.
my ts.confg
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": [
"./*"
],
"src/*": [
"./src/*"
],
"test/*": [
"./test/*"
]
},
/* Basic Options */
// "incremental": true,
"sourceMap": true,
"outDir": "out", /* Enable incremental compilation */
"target": "es6",
"module": "commonjs",
"typeRoots": ["./types"], /* List of folders to include type definitions from. */
"types": [
"node",
"@wdio/sync",
"@wdio/jasmine-framework"
],
"esModuleInterop": true,
"include": ["./test/**/*.ts","./types/wdio.d.ts","./types/command.ts"],
"exclude": [
"./node_modules"
],
}
The types file contains wdio.d.ts declarations.
declare module WebdriverIO {
interface Element {
waitAndClick: () => void;
}
interface Browser {
// waitAndClick: (el:WebdriverIO.Element) => void;
// you can add commands here too
// waitAndClick: () => void;
}
}
In my wdio.conf.js file:
before: function (capabilities, specs) {
browser.addCommand('waitAndClick', ()=> {
var el = $();
el.waitForDisplayed({timeout: 5000});
el.click();
}, true);
}
And in my spec file:
$('mat.classname').waitAndClick();
However, I'm still getting an error that says "Error: selector needs to be typeof string
or function
".