Hello everybody,

We started writing about Selenium 4 since last week. Today, I am going to write about one of the most anticipated features of Selenium4. Now Selenium has native support for Chrome DevTools. You can trigger DevTools command during your test.

Other articles about new Selenium 4 features can be found:

Let’s start with DevTools.

What’s Chrome Dev Tools?

Chrome DevTools is a set of web developer tools built directly into the Google Chrome browser. DevTools can help you edit pages on-the-fly and diagnose problems quickly, which ultimately helps you build better websites, faster.

Emulate Network Type

You can emulate different network types by using the below snippet. All you need to do is to change the download/upload throughput and ConnectionType. You can also disconnect your Chrome browser’s connection and run your test by setting the first parameter to true in emulateNetworkConditions method. You can change the values and see how load time changes.

 

Override UserAgent

The User-Agent request header contains a characteristic string that allows the network protocol peers to identify the application type, operating system, software vendor or software version of the requesting software user agent.

Let’s modify our UserAgent and check if it worked or not. chromeDevToolssend method take Network object as a parameter. That object has a method called setUserAgentOverride which takes a string argument. This argument is going to be your new UserAgent string.

What does it change? For that test, there is no significant importance. It did not changed anything on the web app.

Sometimes, we want to test mobile web apps and that’s where UserAgent comes into play. We can change our browser to a mobile browser by providing a mobile user agent.

Now the web site open in the mobile web view.

 

Load Insecure Web Site

Sometimes, web sites have SSL issues. You need to approve that you want to continue navigating the web site. However, ChromeDevTools allows you to accept that warning easily.

Now you’ll be able to navigate the page without having any warning page.

Those were some samples that we were able to discover at first glance. We’ll provide more example in near future.

Check out the sample code in that link

Happy testing