The browser object is the session instance you use to control the browser or mobile device with. If you use the WDIO test runner, you can access the WebDriver instance through the global
The session is initialized by the test runner. The same goes for ending the session. This is also done by the test runner process.
Besides all commands from the API, the
browser object provides some more information you might be interested in during your test run:
If using the WDIO testrunner you can always define custom configurations within your WDIO config:
And access it in your tests:
Custom configurations should not be confused with Options, which are accessed separately.
When using the WDIO testrunner, if any configuration and option keys conflict in name (e.g.
baseUrl in the following code snippets) the option value will take precedence and overwrite the config value.
If you need to modify your test based on whether or not your session runs on a mobile device, you can access the mobile flags to check.
For example, given this config:
You can access these flags in your test like so:
This can be useful if, for example, you want to define selectors in your page objects based on the device type, like this:
You can also use these flags to run only certain tests for certain device types: