Capturing network logs is something that is key to complete automation.
Often testers are left with the black box of not knowing when a call is being made while going the automation route, with this tool WebdriverIO using the Chrome dev tools protocol via puppeteer it becomes easy for us to achieve that.
We can achieve automation of request analysis and also verify if the requests are made at the right place.
How to do it with WebdriverIO
Ensure you are running this with Chrome browser as this is not available for all the browsers
There are no additional changes required in your wdio.conf.js file
There are no additional libraries required as well
For you to capture a specific type of requests the control lies in browser.mock section
Example for when you want to capture all GET calls
var output = browser.mock('**',{method:'get'})
browser.url('https://reqres.in')
Example for when you want to capture all POST calls
var output = browser.mock('**',{method:'post'})
browser.url('https://reqres.in')
Example for when you want to capture any POST calls that end with login in the request URL
var output1 = browser.mock('**/login',{method:'post'})
browser.url('https://the-internet.herokuapp.com/login')
Example for when you want to capture any POST calls that end with authenticate in the request URL
var output2 = browser.mock('**/authenticate',{method:'post'})
browser.url('https://the-internet.herokuapp.com/login')
Example for when you want to capture any GET calls that end with api/users/2 in the request URL
var output3 = browser.mock('**/api/users/2',{method:'get'})
browser.url('https://reqres.in')
Note: Once you specify a URL to capture, it will capture all the calls that are made let's say if you made 5 calls all 5 will be captured as a separate object inside that variable in JSON format.
In this video below I have gone about explaining all of the above scenarios and how to automate them. Hope you'll like it
Br,
Ap.
Top comments (0)