Showing posts with label Selenium 4. Show all posts
Showing posts with label Selenium 4. Show all posts

Wednesday, December 1, 2021

Selenium 3 vs Selenium 4

 


Selenium has four components as below:

 

 



Earlier Selenium interacted with browsers. The request and response of communication are through JSON Wire protocol. The JSON Wire protocol encodes and decodes all the communications between Selenium and the Browsers.

 



 


 


Selenium 4.0
- initially announced in 2018. we had got alpha and beta versions.
- officially released the first stable version of Selenium 4 On October 13, 2021, and brought lots of upgrades with this release

 

What’s New in Selenium 4

-          Selenium is now W3C compliant

-          Relative locators: Elements can be located based on the location of the neighbouring elements.

-          Better Window/Tab management

-          Improved Selenium Grid

-          Upgraded Selenium IDE

-          New APIs for CDP (Chrome DevTools Protocol)

-          Deprecation of Desired Capabilities. New Options class introduced.

-          Modifications in the Actions class

Selenium is now W3C compliant

W3C: The World Wide Web Consortium

-          JSON wire protocol was used to communicate between the Selenium WebDriver APIs and the browser native APIs.

-          With W3C compliance, communication happens directly without required encoding and decoding.

-          Any software following W3C standard protocol can be integrated with Selenium with no compatibility issues.

Relative locators:

-          Functions to locate nearby elements in specific directions.

-          Existing locator strategy

o   id

o   name

o   linkText

o   partialLinkText

o   className

o   tagName

o   XPath

o   cssSelector

-          New relative locators

o   above

o   below

o   toLeftOf

o   toRightOf

o   near

Better Window/Tab management:

-          work with multiple windows or tabs in the same session.

-          Can now open multiple windows/tabs without creating a new driver object.

o   Open a new window and switch to the window

§  Driver.switchTo().newWindow(WindowType.WINDOW);

o   Open a new tab and switch to the tab

§  Driver.switchTo().newWindow(WindowType.TAB);

Improved Selenium Grid:

-          Selenium Grid helps in Distributed Test Execution.

-          Enables test execution on different combinations of browsers, OS, and machines

-          Enables parallel execution.

Selenium Grid is now redesigned

-          Docker support

-          Enables to spin up the containers. (No need to set up VMs)

-          Enables to deploy the grid on Kubernetes for better scaling

-          Easier management – No need to set up and start hubs and nodes separately.

3 ways to run Selenium Grid

Standalone mode

The new Selenium Server Jar contains all the functionalities needed to run a grid

 java -jar selenium-server-4.0.0.jar standalone

 The Grid automatically identifies that the WebDrivers for Chrome and Firefox are present on the system.

Hub and Node

The classical way of using the Grid for Selenium test automation consists of two major components – Hub and Nodes.

 Start hub java -jar selenium-server-4.0.0.jar hub

Register node java -jar selenium-server-4.0.0.jar node –detect-drivers

Distributed

Grid 4 can be started in a fully distributed manner, with each piece running in its process.

 Selenium Grid 4 consists of FOUR processes:

Router

Distributor

Session

Node

 

 

 Upgraded Selenium IDE:

-          Record and Playback tool

-          Available as an add-on – Firefox, Chrome, MS Edge

o   Improved GUI

o   SIDE runner – Selenium IDE runner for CMD execution, grid and node projects

o   Better element locator strategy

o   More stable and reliable

New APIs for CDP (Chrome DevTools Protocol):

Chrome DevTools – set of tools built directly into Chromium-based browsers like Chrome, Opera and Microsoft Edge to help developers debug and investigate websites

-          Inspect elements in the DOM

-          Edit elements and CSS on the fly

-          Check and monitor the site’s performance

-          Mock faster/slower networks speeds

-          Mock geolocations of the user

-          Execute and debug JavaScript

-          View console logs

Selenium 4 comes with native support for Chrome DevTools APIs

-          Capture and monitor network traffic

-          Simulate poor network conditions

-          Perform geolocation testing

-          Change device mode to do responsive design testing

-          new ChromiumDriver class, which includes two methods to access Chrome DevTools:

o   getDevTools()

o   executeCdpCommand()


Deprecation of Desired Capabilities:

Desired Capabilities were primarily used in the test scripts to define the test environment (browser name, version, operating system) for execution on the Selenium Grid.

 Capabilities objects are replaced with the Options class.

Firefox – FirefoxOptions

Chrome – ChromeOptions

Internet Explorer – InternetExplorerOptions

Microsoft Edge – EdgeOptions

Safari – SafariOptions

 

For example:

 ChromeOptions options = new ChromeOptions();

options.setAcceptInSecureCerts(true);

options.setCapability(“build”, “Testing Chrome Options Selenium 4”);

options.setCapability(“name”, “Testing Chrome Options Selenium 4”);

options.setCapability(“platformName”, “Windows 10”);

options.setCapability(“browserName”, “chrome”);

options.setCapability(“browserVersion”, “latest”);

 

Modifications in the Actions class:

Actions class is used to simulate input actions from mouse and keyboard on specific web elements (e.g., Left click, Right-click, Double click, etc.)

 

Old

New

Click on a web element

moveToElement(element).click()

click(element)

Click on element without releasing the click

moveToElement(element).clickAndHold()

clickAndHold(element)

Right click

moveToElement(element).contextClick()

contextClick(element)

 release() initially a part of org.openqa.selenium.interactions.ButtonReleaseAction class. Is now part of Actions class.

 

 

Thursday, January 25, 2018

Difference between get() vs navigate() in Selenium

Selenium offers two distinct functions, get() and Maps(), for loading web pages. While both serve the fundamental purpose of directing the browser to a URL, they possess unique advantages and disadvantages that make them suitable for different scenarios. This article will delve into a detailed comparison of these two functions.

What is the get() function in Selenium?

The get() function in Selenium WebDriver is used to open a specified URL in the browser. Its primary purpose is to initiate a new browser session and navigate directly to the given web address. This method is straightforward and efficient for simply loading a web page from a URL.

What is the Maps() function in Selenium?

In Selenium WebDriver, the Maps() method is part of the WebDriver.Navigation interface. It offers more advanced capabilities for managing browser history and navigation compared to the get() method. The Maps() method allows users to move forward and backward through the browser's history, refresh the current page, and also navigate to a specific URL. Its purpose is to provide more granular control over browser navigation, extending beyond just loading a URL.

Difference Between get() and Maps() in Selenium

The following table highlights the key differences between the get() and Maps() functions in Selenium:

Factorsget()Maps()
Interface PartPart of the WebDriver interface.Part of the Navigation interface.
Wait for Webpage LoadWaits until the webpage is fully loaded and available before returning control.Does not inherently wait for the webpage to be fully loaded.
History TrackingDoes not have a history tracking feature, thus preventing users from going back to previous pages via the browser's history.Has a history tracking feature, allowing users to go back to previous web pages.
Refresh FeatureDoes not support the refresh feature.Supports the refresh feature, allowing the current page to be reloaded.
Forward FeatureDoes not support the forward function to move to the next page in browser history once the user has moved back.Supports the forward function, allowing the user to move to the next page in browser history after navigating back.


Selenium 3 vs Selenium 4