Improve this doc

The Browser Object

If you use the wdio test runner you can access the webdriver instance through the global browser object. The session is initialized by the test runner so you don’t need to call init command. 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:

Get desired capabilities

1
2
3
4
5
6
7
8
9
10
11
12
console.log(browser.desiredCapabilities);
/**
* outputs:
* {
javascriptEnabled: true,
locationContextEnabled: true,
handlesAlerts: true,
rotatable: true,
browserName: 'chrome',
loggingPrefs: { browser: 'ALL', driver: 'ALL' }
}
*/

Get wdio config options

1
2
3
4
5
6
// wdio.conf.js
exports.config = {
// ...
foobar: true,
// ...
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
console.log(browser.options);
/**
* outputs:
* {
port: 4444,
protocol: 'http',
waitforTimeout: 10000,
waitforInterval: 250,
coloredLogs: true,
deprecationWarnings: true,
logLevel: 'verbose',
baseUrl: 'http://localhost',
connectionRetryTimeout: 90000,
connectionRetryCount: 3,
sync: true,
specs: [ 'err.js' ],
foobar: true, // <-- custom option
// ...
*/

Check if capability is a mobile device

1
2
3
4
5
6
7
8
9
10
11
12
var client = require('webdriverio').remote({
desiredCapabilities: {
platformName: 'iOS',
app: 'net.company.SafariLauncher',
udid: '123123123123abc',
deviceName: 'iPhone',
}
});

console.log(client.isMobile); // outputs: true
console.log(client.isIOS); // outputs: true
console.log(client.isAndroid); // outputs: false

Log results

1
browser.logger.info('some random logging');

For more information about the logger class check out Logger.js on GitHub.