I am new on webdriverIO, I am trying to implement the Page Model Object in a hybrid app, when do loginPage.login(user, pass) is calling and I'm trying to setValue I am getting errors, the value could not set, looks like is out of context or is not recognize the element, but if for example doing the same code but changing the loginPage.login by the same elements directly or in the same level than script the values are set, any idea about this, the language is TypeScript
Script:
describe('My Login application', () => {
it('should login with valid credentials', async () => {
await wait(5000)
initializePage.start()
console.log("-------------------------Contexts: " + await driver.getContexts())
await browser.pause(2000)
console.log("-------------------------Contexts 2: " + await driver.getContexts())
await driver.switchContext('WEBVIEW_chrome')
loginPage.login(driver, '3617976', 'Password')
browser.pause(2000)
})
})
Login Page
import { $, driver, browser } from '@wdio/globals'
import Page from './base.page';
class LoginPage extends Page {
constructor(){
super()
}
private get inputUsername () {
return $('.//input[@name="username"]')
}
private get inputPassword () {
return $('//input[@name="password"]');
}
private get btnLogin () {
return $('//button[@name="action"]');
}
public async login (WebdriverIO.Browser , username: string, password: string) {
try{
await (await this.inputUsername).setValue(username)
await (await this.inputPassword).setValue(password)
await (await this.btnLogin).click()
}catch(ex){
console.log(ex.message)
}
}
}
export default new LoginPage();
This is the log of execution
mobile-test % npm run android Debugger attached.
> android
> wdio run ./wdio.conf.ts
Debugger attached.
Execution of 1 workers started at 2025-03-19T06:41:17.280Z
2025-03-19T06:41:17.292Z INFO @wdio/cli:launcher: Run onPrepare hook
2025-03-19T06:41:17.294Z INFO @wdio/cli:launcher: Run onWorkerStart hook
2025-03-19T06:41:17.294Z INFO @wdio/local-runner: Start worker 0-0 with arg: run ./wdio.conf.ts [0-0]
2025-03-19T06:41:18.194Z INFO @wdio/local-runner: Run worker command: run [0-0] RUNNING in Android - file:///tests/specs/android.spec.ts [0-0]
2025-03-19T06:41:18.379Z INFO webdriver: Initiate new session using the WebDriver protocol [0-0]
2025-03-19T06:41:18.379Z INFO @wdio/utils: Connecting to existing driver at http://localhost:4723/wd/hub/ [0-0]
2025-03-19T06:41:18.394Z INFO webdriver: [POST] http://localhost:4723/wd/hub/session [0-0]
2025-03-19T06:41:18.394Z INFO webdriver: DATA { [0-0] capabilities: { [0-0] alwaysMatch: { [0-0] platformName: 'Android', [0-0] 'appium:deviceName': 'Medium Phone API 35', [0-0] 'appium:automationName': 'UiAutomator2', [0-0] 'appium:uuid': 'emulator-5554', [0-0] 'appium:maxInstances': '1', [0-0] 'appium:fullContextList': true, [0-0] 'appium:app': 'build.apk' [0-0] }, [0-0] firstMatch: [ {} ] [0-0] } [0-0] } [0-0] before Script [0-0] -------------------------Start script [0-0]
2025-03-19T06:41:38.425Z INFO webdriver: The standard Appium `contexts` method is used. If you want to get more detailed data, you can set `returnDetailedContexts` to `true`. [0-0]
2025-03-19T06:41:38.429Z INFO webdriver: COMMAND getAppiumContexts() [0-0]
2025-03-19T06:41:38.432Z INFO webdriver: The standard Appium `contexts` method is used. If you want to get more detailed data, you can set `returnDetailedContexts` to `true`. [0-0]
2025-03-19T06:41:38.432Z INFO webdriver: [GET] http://localhost:4723/wd/hub/session/fc178ebb-34f1-4a16-8e52-9d1adefc02de/contexts [0-0]
2025-03-19T06:41:38.440Z INFO webdriver: COMMAND getAppiumContexts() [0-0]
2025-03-19T06:41:38.441Z INFO webdriver: [GET] http://localhost:4723/wd/hub/session/fc178ebb-34f1-4a16-8e52-9d1adefc02de/contexts [0-0]
2025-03-19T06:41:38.688Z INFO webdriver: RESULT [ 'NATIVE_APP', 'WEBVIEW_chrome' ] [0-0] -------------------------Contexts: NATIVE_APP,WEBVIEW_chrome [0-0]
2025-03-19T06:41:41.476Z INFO webdriver: The standard Appium `contexts` method is used. If you want to get more detailed data, you can set `returnDetailedContexts` to `true`. [0-0]
2025-03-19T06:41:41.476Z INFO webdriver: COMMAND getAppiumContexts() [0-0]
2025-03-19T06:41:41.927Z INFO webdriver: The standard Appium `contexts` method is used. If you want to get more detailed data, you can set `returnDetailedContexts` to `true`. [0-0]
2025-03-19T06:41:41.928Z INFO webdriver: [GET] http://localhost:4723/wd/hub/session/fc178ebb-34f1-4a16-8e52-9d1adefc02de/contexts [0-0]
2025-03-19T06:41:41.929Z INFO webdriver: COMMAND getAppiumContexts() [0-0]
2025-03-19T06:41:41.930Z INFO webdriver: [GET] http://localhost:4723/wd/hub/session/fc178ebb-34f1-4a16-8e52-9d1adefc02de/contexts [0-0]
2025-03-19T06:41:41.934Z INFO webdriver: RESULT [ 'NATIVE_APP', 'WEBVIEW_chrome' ] [0-0]
2025-03-19T06:41:42.155Z INFO webdriver: RESULT [ 'NATIVE_APP', 'WEBVIEW_chrome' ] [0-0]
2025-03-19T06:41:42.353Z INFO webdriver: RESULT [ 'NATIVE_APP', 'WEBVIEW_chrome' ] [0-0]
2025-03-19T06:41:45.573Z INFO webdriver: The standard Appium `contexts` method is used. If you want to get more detailed data, you can set `returnDetailedContexts` to `true`. [0-0]
2025-03-19T06:41:45.577Z INFO webdriver: COMMAND getAppiumContexts() [0-0]
2025-03-19T06:41:45.578Z INFO webdriver: The standard Appium `contexts` method is used. If you want to get more detailed data, you can set `returnDetailedContexts` to `true`. [0-0]
2025-03-19T06:41:45.578Z INFO webdriver: [GET] http://localhost:4723/wd/hub/session/fc178ebb-34f1-4a16-8e52-9d1adefc02de/contexts [0-0]
2025-03-19T06:41:45.580Z INFO webdriver: COMMAND getAppiumContexts() [0-0]
2025-03-19T06:41:45.580Z INFO webdriver: [GET] http://localhost:4723/wd/hub/session/fc178ebb-34f1-4a16-8e52-9d1adefc02de/contexts [0-0]
2025-03-19T06:41:45.817Z INFO webdriver: RESULT [ 'NATIVE_APP', 'WEBVIEW_chrome' ] [0-0] -------------------------Contexts 2: NATIVE_APP,WEBVIEW_chrome [0-0]
2025-03-19T06:41:46.715Z INFO webdriver: The standard Appium `contexts` method is used. If you want to get more detailed data, you can set `returnDetailedContexts` to `true`. [0-0]
2025-03-19T06:41:46.715Z INFO webdriver: COMMAND getAppiumContexts() [0-0]
2025-03-19T06:41:49.547Z INFO webdriver: The standard Appium `context`-method is used. If you want to switch to a webview with a specific title or url, please provide an object with the `title` or `url` property. See for more information. [0-0]
2025-03-19T06:41:49.548Z INFO webdriver: COMMAND switchAppiumContext("WEBVIEW_chrome") [0-0]
2025-03-19T06:41:49.548Z INFO webdriver: The standard Appium `contexts` method is used. If you want to get more detailed data, you can set `returnDetailedContexts` to `true`. [0-0]
2025-03-19T06:41:49.548Z INFO webdriver: [GET] http://localhost:4723/wd/hub/session/fc178ebb-34f1-4a16-8e52-9d1adefc02de/contexts [0-0]
2025-03-19T06:41:49.549Z INFO webdriver: [POST] http://localhost:4723/wd/hub/session/fc178ebb-34f1-4a16-8e52-9d1adefc02de/context [0-0]
2025-03-19T06:41:49.549Z INFO webdriver: DATA { name: 'WEBVIEW_chrome' } [0-0]
2025-03-19T06:41:49.551Z INFO webdriver: COMMAND getAppiumContexts() [0-0]
2025-03-19T06:41:49.552Z INFO webdriver: [GET] http://localhost:4723/wd/hub/session/fc178ebb-34f1-4a16-8e52-9d1adefc02de/contexts [0-0]
2025-03-19T06:41:49.554Z INFO webdriver: RESULT [ 'NATIVE_APP', 'WEBVIEW_chrome' ] [0-0]
2025-03-19T06:41:49.781Z INFO webdriver: RESULT [ 'NATIVE_APP', 'WEBVIEW_chrome' ] [0-0]
2025-03-19T06:41:50.395Z INFO webdriver: RESULT null [0-0]
2025-03-19T06:41:52.365Z INFO webdriver: The standard Appium `contexts` method is used. If you want to get more detailed data, you can set `returnDetailedContexts` to `true`. [0-0]
2025-03-19T06:41:52.367Z INFO webdriver: COMMAND getAppiumContexts() [0-0]
2025-03-19T06:41:54.087Z INFO webdriver: COMMAND findElement("xpath", ".//input[@name="username"]") [0-0]
2025-03-19T06:41:54.088Z INFO webdriver: The standard Appium `contexts` method is used. If you want to get more detailed data, you can set `returnDetailedContexts` to `true`. [0-0]
2025-03-19T06:41:54.088Z INFO webdriver: [GET] http://localhost:4723/wd/hub/session/fc178ebb-34f1-4a16-8e52-9d1adefc02de/contexts [0-0]
2025-03-19T06:41:54.089Z INFO webdriver: [POST] http://localhost:4723/wd/hub/session/fc178ebb-34f1-4a16-8e52-9d1adefc02de/element [0-0]
2025-03-19T06:41:54.089Z INFO webdriver: DATA { using: 'xpath', value: './/input[@name="username"]' } [0-0]
2025-03-19T06:41:54.093Z INFO webdriver: COMMAND getAppiumContexts() [0-0]
2025-03-19T06:41:54.094Z INFO webdriver: [GET] http://localhost:4723/wd/hub/session/fc178ebb-34f1-4a16-8e52-9d1adefc02de/contexts [0-0]
2025-03-19T06:41:54.099Z INFO webdriver: RESULT [ 'NATIVE_APP', 'WEBVIEW_chrome' ] [0-0]
2025-03-19T06:41:54.102Z INFO webdriver: COMMAND deleteSession() [0-0]
2025-03-19T06:41:54.102Z INFO webdriver: [DELETE] http://localhost:4723/wd/hub/session/fc178ebb-34f1-4a16-8e52-9d1adefc02de [0-0]
2025-03-19T06:41:54.320Z WARN webdriver: WebDriverError: 'POST /wd/hub/session/fc178ebb-34f1-4a16-8e52-9d1adefc02de/element' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed). Check the server log and/or the logcat output for more details when running "element" with method "POST" and args "{"using":"xpath","value":".//input[@name=\"username\"]"}" [0-0]
2025-03-19T06:41:54.320Z INFO webdriver: Retrying 1/3 [0-0]
2025-03-19T06:41:54.321Z INFO webdriver: [POST] http://localhost:4723/wd/hub/session/fc178ebb-34f1-4a16-8e52-9d1adefc02de/element [0-0]
2025-03-19T06:41:54.321Z INFO webdriver: DATA { using: 'xpath', value: './/input[@name="username"]' } [0-0]
2025-03-19T06:41:54.323Z INFO webdriver: RESULT [ 'NATIVE_APP', 'WEBVIEW_chrome' ] [0-0]
2025-03-19T06:41:54.352Z INFO webdriver: RESULT null [0-0] PASSED in Android - file:///tests/specs/android.spec.ts
2025-03-19T06:41:54.482Z INFO @wdio/cli:launcher: Run onWorkerEnd hook
"DotReporter" Reporter: .
Spec Files: 1 passed, 1 total (100% completed) in 00:00:37
2025-03-19T06:41:54.486Z INFO @wdio/local-runner: Shutting down spawned worker
2025-03-19T06:41:54.739Z INFO @wdio/local-runner: Waiting for 0 to shut down gracefully
2025-03-19T06:41:54.739Z INFO @wdio/local-runner: shutting down
2025-03-19T06:41:54.739Z INFO @wdio/cli:launcher: Run onComplete hook Waiting for the debugger to disconnect... Waiting for the debugger to disconnect... mobile-test %