Coming from Mobilewright
The Mobilewright engine runs on mobilecli, the same tool as Mobilewright. Every WebdriverIO command makes the same mobilecli calls as its Mobilewright counterpart and waits by the same rules, see Waiting and timeouts. If you know Mobilewright, this page shows where each part of its API is in WebdriverIO.
test/specs/login.e2e.ts
import { browser, expect, $ } from '@wdio/globals'
describe('Login', () => {
it('logs in with valid credentials', async () => {
await $('~input-email').setValue('test@webdriver.io') // locator.fill()
await $('~input-password').setValue('Test1234!') // locator.fill()
await browser.hideKeyboard() // screen.keyboard.hide()
await $('~button-LOGIN').click() // locator.tap()
await expect($('~You are logged in!')).toBeDisplayed()
})
})
Commands​
| Mobilewright | WebdriverIO | mobilecli |
|---|---|---|
| a locator | $(selector), $$(selector) | device.dump.ui, the engine matches the selector in the UI tree |
locator.tap() | $(selector).click(), $(selector).tap() | device.io.tap |
locator.fill(text) | $(selector).setValue(text) | device.io.tap, device.io.fill |
locator.clear() | $(selector).clearValue() | device.io.tap, device.io.fill with no text |
$(selector).addValue(text) | device.io.tap, device.io.text | |
locator.getText(), getValue() | $(selector).getText(), getValue() | device.dump.ui |
locator.isVisible(), isEnabled() | $(selector).isDisplayed(), isEnabled() | device.dump.ui |
screen.keyboard.hide(), isVisible() | browser.hideKeyboard(), isKeyboardShown() | device.io.keyboard.hide, device.io.keyboard.status |
screen.viewTree() | browser.getPageSource() | device.dump.ui |
Both return the same as in Mobilewright: getText() returns the text, else the label, else the value. getValue() returns only the value, or an empty string if the element has none.
Waits​
| Mobilewright | WebdriverIO |
|---|---|
locator.waitFor({ state: 'visible', timeout: 10000 }) | await $('~message').waitForDisplayed({ timeout: 10000 }) |
locator.waitFor({ state: 'hidden' }) | await $('~spinner').waitForDisplayed({ reverse: true }) |
locator.waitFor({ state: 'enabled' }) | await $('~submit').waitForEnabled() |
locator.waitFor({ state: 'disabled' }) | await $('~submit').waitForEnabled({ reverse: true }) |
Timeouts​
| Mobilewright | WebdriverIO |
|---|---|
Action timeout (use.actionTimeout) | actionTimeout in mobilecli:options, else waitforTimeout |
Test timeout (timeout) | The timeout of the framework, for example mochaOpts.timeout |
Expect timeout (expect.timeout) | waitforTimeout, or the wait option of a matcher |
Install timeout (use.installTimeout) | installTimeout in mobilecli:options |
App launch timeout (use.appLaunchTimeout) | appLaunchTimeout in mobilecli:options |
Action timeout per action (locator.tap({ timeout })) | Not supported. Wait first with waitForEnabled({ timeout }), see Give one command more time |
| Global and allocation timeout | No counterpart |
See Settings for every setting of mobilecli:options.
What else changes​
- Configuration. The device, the app and the timeouts go in
wdio.conf.ts, see Configuration. The app ofmobilecli:appis installed and started when the session starts. - Selectors. Use
~for an accessibility id,id=for an id, or a class name, see Selectors. - Devices. Only local devices are supported. Support for device clouds is in progress.
- The rest of WebdriverIO. The testrunner, page objects and retries work as with any other protocol.