<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rishabh Madhesiya on Medium]]></title>
        <description><![CDATA[Stories by Rishabh Madhesiya on Medium]]></description>
        <link>https://medium.com/@rishabh.madhesiya?source=rss-53510e1f038f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*mgo5Qv1WpMlF7Pfp</url>
            <title>Stories by Rishabh Madhesiya on Medium</title>
            <link>https://medium.com/@rishabh.madhesiya?source=rss-53510e1f038f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 14:59:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rishabh.madhesiya/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Selenium 4 : What’s new]]></title>
            <link>https://medium.com/@rishabh.madhesiya/selenium-4-whats-new-b3c9baf6e359?source=rss-53510e1f038f------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3c9baf6e359</guid>
            <category><![CDATA[chrome-devtools]]></category>
            <category><![CDATA[selenium]]></category>
            <category><![CDATA[automation-testing]]></category>
            <category><![CDATA[selenium-4]]></category>
            <dc:creator><![CDATA[Rishabh Madhesiya]]></dc:creator>
            <pubDate>Thu, 27 Apr 2023 15:47:27 GMT</pubDate>
            <atom:updated>2023-04-27T15:47:27.847Z</atom:updated>
            <content:encoded><![CDATA[<h3>Selenium 4 : What’s new</h3><p>Selenium is a popular open-source test automation tool widely used for web application testing. It allows you to automate your application across browsers. The latest release of Selenium, Selenium 4, comes with lot of new features and improvements that makes it even more powerful and easy to use. In this blog, we will discuss some of the key changes and features of Selenium 4.</p><p>Selenium 4 has come with a major change which has made webdriver APIs completely compliant with W3C standards. This means that encoding and decoding of API requests through JSON wire protocol which was needed in the earlier versions of selenium will no longer be needed and our webdriver will now directly interact with the test browser.</p><p><strong>No need to manage chromedriver jar with v4.6.0!</strong></p><p>Earlier to start chromedriver you had to download chromedriver jar and set its path in your code</p><pre>public static void main(String[] args) {<br>   System.setProperty(&quot;webdriver.chrome.driver&quot;, &quot;//path to your chromedriver jar&quot;);<br>   WebDriver driver = new ChromeDriver();<br>}</pre><p>With selenium releases starting from v4.6.0, selenium manager has started taking care of the driver management. Now you no longer have to specify chromedriver path while initializing your driver.</p><pre>&lt;dependency&gt;<br>    &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;<br>    &lt;artifactId&gt;selenium-java&lt;/artifactId&gt;<br>    &lt;version&gt;4.6.0&lt;/version&gt;<br>&lt;/dependency&gt;</pre><pre>public static void main(String[] args) {<br>   WebDriver driver = new ChromeDriver();<br>}</pre><p><strong>Support for Chrome DevTools Protocol</strong><br>One of the most exciting features of Selenium 4 is the integration of the Chrome DevTools Protocol. This integration allows Selenium to control Chrome browser instances using the DevTools protocol. This enables users to perform many actions that were previously not possible with Selenium. For example, you can now capture network logs, control the browser’s cache, and intercept requests and responses.</p><p><strong>Recording Network Calls</strong></p><pre>WebDriver driver = new ChromeDriver();<br>DevTools tools;<br>tools = ((HasDevTools) driver).getDevTools();<br>tools.createSession();<br>tools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));<br>AtomicInteger count = new AtomicInteger();<br>LinkedHashMap&lt;String,Optional&lt;String&gt;&gt; dataMap = new LinkedHashMap&lt;&gt;();<br><br>//The following listener is triggered whenever a new request has been initiated<br>tools.addListener(Network.requestWillBeSent(), req -&gt; {<br>    String requestId = req.getRequestId().toString();<br>    RequestWillBeSent request = req;<br>    ResponseReceived res = null;<br>    Optional&lt;String&gt; payload = req.getRequest().getPostData();<br>     try {<br>         //we are adding the requests initiated to a list so that we can access the request along with their response as soon as we get response for these calls<br>        dataMap.put(requestId,payload);<br>     }<br>    catch (NullPointerException e)<br>    {<br>    }<br><br>});<br><br>//The following listener is triggered whenever response has been received for a particular api<br>tools.addListener(Network.responseReceived(), response -&gt; {<br>    ResponseReceived res = response;<br>    String reqid = response.getRequestId().toString();<br>    try {<br>        if(dataMap.get(reqid).isPresent()) {<br>            System.out.println(&quot;Request Sent:&quot; + dataMap.get(reqid).get());<br>            System.out.println(&quot;Response Status Code:&quot; + res.getResponse().getStatus());<br>            System.out.println(&quot;Response Message:&quot; + res.getResponse().getStatusText());<br>        }<br>    }<br>    catch(NullPointerException e)<br>    {}<br>});<br><br>driver.get(&quot;https://www.naukri.com&quot;);</pre><p><strong>Intercepting network calls and setting your own response</strong></p><pre>NetworkInterceptor interceptor = new NetworkInterceptor(<br>        driver,<br>        Route.matching(req -&gt; true)<br>                .to(() -&gt; req -&gt; new HttpResponse()<br>                        .setStatus(200)<br>                        .addHeader(&quot;Content-Type&quot;, MediaType.HTML_UTF_8.toString())<br>                        .setContent(() -&gt; new ByteArrayInputStream(&quot;This is the mocked response for our page&quot;.getBytes(StandardCharsets.UTF_8)))));<br><br>driver.get(&quot;https://www.google.com&quot;);<br>String source = driver.getPageSource();<br>System.out.println(source);</pre><p><strong>Mocking Location Coordinates</strong></p><pre>//The 3 parameters passed here are latitude, longitude and accuracy<br>tools.send(Emulation.setGeolocationOverride(Optional.of(52.5043),<br>        Optional.of(13.4501),<br>        Optional.of(1)));<br>driver.get(&quot;https://my-location.org/&quot;);</pre><p><strong>Disable webp images on your site</strong></p><pre>LinkedList&lt;DisabledImageType&gt; data = new LinkedList&lt;&gt;();<br>data.add(DisabledImageType.WEBP);<br>tools.send(Emulation.setDisabledImageTypes(data));<br>driver.get(&quot;https://developers.google.com/speed/webp/gallery1&quot;);</pre><p><strong>Relative Locators</strong></p><p>Selenium 4 has added a new feature that allows users to find out elements relative to other elements using natural language like syntax.</p><p>For example for the login page below which has 2 input fields and a button we can fill in and submit the form with the following code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*HND3ae1YSjAHxQWGeBjnzQ.png" /></figure><pre>WebElement username = driver.findElement(By.id(&quot;username&quot;));<br>username.sendKeys(&quot;username&quot;);<br>driver.findElement(with(By.tagName(&quot;input&quot;)).below(username)).sendKeys(&quot;password&quot;);<br>driver.findElement(with(By.tagName(&quot;button&quot;)).below(username)).click();</pre><p><strong>Manipulating Network Conditions</strong></p><p>Adding Latency to your driver:</p><pre>ChromiumNetworkConditions networkConditions = new ChromiumNetworkConditions();<br>networkConditions.setLatency(Duration.ofMillis(2000));<br>WebDriver augmentedDriver = new Augmenter().augment(driver);<br>((HasNetworkConditions) augmentedDriver).setNetworkConditions(networkConditions);<br>augmentedDriver.get(&quot;https://www.google.com&quot;);</pre><p>Disabling internet to check application behaviour when user goes offline:</p><pre>ChromiumNetworkConditions networkConditions = new ChromiumNetworkConditions();<br>networkConditions.setOffline(true);<br>    ((HasNetworkConditions) augmentedDriver).setNetworkConditions(networkConditions);<br>    augmentedDriver.get(&quot;https://www.naukri.com&quot;);</pre><p><strong>Improved Selenium Docker Grid Console</strong></p><p>All active sessions can be viewed under the sessions tab in your grid console, you can see running test cases by clicking on the session links. In previous versions, users had to login to these sessions using VNC viewer to see active sessions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WdmxTK6Ou8QAs1yOUvTADA.jpeg" /></figure><p>Selenium 4 is a significant improvement over previous versions of Selenium. Its new features and improvements make it easier to use, more powerful, and more reliable. We will be covering implementation of selenium dockerized grid with selenium 4 in our next blog. Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3c9baf6e359" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>