Unable to declare and use user-defined/custom properties in wdio 8 project #11723
Closed
parida1611
started this conversation in
Technical Discussion
Replies: 1 comment
-
With removing the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So below is my setup configuration:
node: v18.17.1
npm: 9.6.7
wdio : 8
My package.json file:
{
"name": "wdio8",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"wdio": "wdio run ./wdio.conf.ts",
"PROD-chrome-sanity": "set ENV=PROD && npx wdio run wdio.conf.ts --spec test/specs/lpl/sanity.ts"
},
"author": "",
"license": "ISC",
"dependencies": {
"-": "^0.0.1",
"@wdio/cli": "^8.23.4",
"save-dev": "^0.0.1-security"
},
"devDependencies": {
"@wdio/local-runner": "^8.23.4",
"@wdio/mocha-framework": "^8.23.1",
"@wdio/spec-reporter": "^8.23.1",
"ts-node": "^10.9.1",
"typescript": "^5.3.2",
"wdio-intercept-service": "^4.4.0"
}
}
my wdio.conf.ts file: where "users" is a user defined property here.
const users = import (
./configs/users/usersConfigPROD.json
);import type { Options } from '@wdio/types'
export const config: Options.Testrunner = {
}
I am trying to fetch the "users" property in my page object file as below:
//page.pageobject.ts
import { browser } from '@wdio/globals'
const usersList = browser.options.users; // getting an error "Property 'users' does not exist on type 'Testrunner | WebdriverIO'"
/**
/
export default class Page {
/*
* Opens a sub page of the page
* @param path path of the sub page (e.g. /path/to/page.html)
*/
public open (path: string) {
console.log(usersList);
console.log(browser.options.baseUrl);
return browser.url(
https://the-internet.herokuapp.com/${path}
)}
}
while trying to use property "users" getting an error "Property 'users' does not exist on type 'Testrunner | WebdriverIO'". If I still run the code, the value of "usersList" comes to be undefined. To solve this, I also created a custom type definition file
//custom.d.ts file
declare global {
export interface custom extends WebdriverIO {
users : any;
}
}
and added path in tsconfig.json file's "include" property as below:
//tsconfig.json
{
"compilerOptions": {
"moduleResolution": "node",
"module": "commonjs",
"target": "es2022",
"lib": [
"es2022",
"dom"
],
"types": [
"node",
"@wdio/globals/types",
"expect-webdriverio",
"@wdio/mocha-framework"
],
"skipLibCheck": true,
"noEmit": true,
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": [
"test",
"wdio.conf.ts",
"custom.d.ts"
]
}
but nothing seems to work.
At the end my goal is to declare and initialize the new property "users" in wdio.conf.ts file and to be able to use it at different location as browser.options property.
Earlier in wdio v7, I was able to do so via browser.config.users, but now after upgrade to wdio 8 this doesn't seems to work with browser.options.users. Please let me know what I should be doing here to achieve the goal or solve this issue. Also let me know If I have missed any required information here.
I am struggling with this since a week now. Any help is appreciated here.
Beta Was this translation helpful? Give feedback.
All reactions