For some time now all browser vendors work on a new version of WebDriver called WebDriver Bidi which enables new automation capabilities for all browser. In this chapter we want to get familiar with the new protocol and use some of its capabilities.
One of the new features of the WebDriver Bidi protocol is its ability to capture console.log
and error entries from the application you are browsing. This is made possible through the bi-directional communication between the browser driver and your automation library. In WebdriverIO you can get access these console.log
events by registering event listener to the browser.
The objective of this chapter are the following:
- Create a new test for testing out Bidi commands
- Opt-in to the new protocol capabilities by adding
webSocketUrl: true
to your capabilities - Write a test that verifies whether there are any JavaScript errors after navigating to the page
- Call the
sessionSubscribe
command and let the driver know that you are interested inlog.entryAdded
events - Register a command handler via
browser.on('log.entryAdded', (entryAdded) => ...)
and log error entries - Make the test navigate to
https://the-internet.herokuapp.com/javascript_error
- Let the test fail if you discover an error being thrown during page load
Note
JavaScript errors are often raised after the page load, when the application starts to render. Therefor you probably won't have any log entries right after you call the url
command. For simplicity let's use await browser.pause(1000)
to delay the test execution and make sure that our events come through.
Next to console events you can also listen to network activities now. The WebDriver Bidi protocol offers several events you can listen to that contain information on requests made by the browser.
The objective of this chapter are the following:
- Add a new test where we want to verify that all page requests where successful
- Use the
sessionSubscribe
command again, to enable events fornetwork.responseCompleted
- Register a command handler via
browser.on('network.responseCompleted', (responses) => ...)
and log failing network requests - Make the test navigate to
https://the-internet.herokuapp.com/broken_images
- Let the test fail if the request contained any failing requests
Note
Requests to application assets are often made after the page load, when the application starts to render. Therefor you probably won't have any request entries logged right after you call the url
command. For simplicity let's use await browser.pause(1000)
to delay the test execution and make sure that our requests come through.