How To Perform Selenium 4 Automation Testing [with examples]

14 min read
16 February 2023

The importance of automation testing has been realised by nearly every business today. Numerous tools and frameworks are available in the market to meet this growing demand. But despite all the available automation testing frameworks and tools, Selenium is one of the most commonly used tools by testers worldwide to automate testing processes.

Even recently a new update of Selenium was released that gained a lot of popularity from the audience. Basically, with Selenium 4.0, there are several additional benefits, such as seamless integration, parallel testing, cross-browser testing, better documentation, etc., making Selenium testing much easier and more accessible for developers.

However before investing in automation testing frameworks and tools, businesses should read all the features and phases of Selenium 4.0's test execution. So, without further ado, let's begin.

What is Selenium 4?

A Selenium framework is a free tool that is used to automate the testing of web applications across different platforms and browsers. It is possible to create Selenium Test Scripts in various programming languages, such as Java, C#, Python, etc. When testing is performed using the Selenium testing tool, it is commonly referred to as Selenium testing.

There is no doubt that Selenium 4 is the most recent version of the Selenium tool available in the market today. As a major upgrade to Selenium 3, Selenium 4 comes with some new functionality and features. And the LambdaTest Selenium Automation Grid provides security, robustness, and scalability when it comes to automating testing across the entire software lifecycle. With this significant tool, you can write automated tests for web application projects.

The first step in this whole process is to install Selenium on your computer. Additionally, you'll have to write the code that will allow you to manipulate your browser by using one or more Selenium libraries.

Features of Selenium 4

Selenium 4 has made a great impact in the market with some really great features and functionalities. Here are a few of them.

1. Enhanced Selenium Grid

In previous versions of Selenium Grid, setting it up was complex and scaling was rigid. But with the newer version Docker support has been added to Selenium Grid. Instead of setting up heavy virtual machines, developers and testers can spin up containers. Additionally, the grid has been redesigned in such a way that it will be possible to deploy it on Kubernetes to enable better scalability for QAs.

With Selenium Grid, no hubs and nodes need to be set up and started separately, which makes management much easier. The grid can now be deployed in three different ways by teams or individual testers:

  • Standalone mode

  • Hub and Node

  • Fully distributed

2. Upgraded Selenium IDE

A popular recording and playback tool used by most Selenium engineers is Selenium IDE. The Selenium IDE was originally available only as an add-on for Firefox. It was later deprecated when the latest Firefox version was released. The reason for this is that the latest Firefox (ver. 55) uses Web Extensions to manage add-ons. Having been revived with Selenium 4, you can now use the IDE with Firefox and Chrome through its add-on. MS Store also has made the Selenium IDE add-on available on its webpage.

The new Selenium 4 IDE provides some notable features:

  • A more intuitive GUI for a better user experience.

  • SIDE tool and Selenium IDE runner are included with the new IDE. In other words, it allows QA to run .side projects on a node.js platform. SIDE runners also enable individuals to run cross-browser tests on a locally installed Selenium Grid or a cloud-based Selenium Grid.

  • Due to an improved control flow mechanism, testers can write better "if" and "while" conditions.

  • It includes a backup element locator strategy that assists in finding elements if the web element cannot be found. A stable set of test cases will be created as a result.

  • Selenium IDE allows exporting test cases in the desired language binding such as Java, C#, Python, .NET, and JavaScript.

3. Relative Locators in Selenium 4

By including relative locators, Selenium 4 makes it easy to locate elements. By using intuitive terms that users often use, testers can now identify certain web elements, such as:

  • To left of

  • To right of

  • Above

  • Below

As part of Selenium 4, this new method is being introduced so that web elements can be positioned based on their visual location relative to other DOM elements.

4. Improved Documentation

With a neat UI for navigating to the desired area or page, the documentation section has been revamped significantly. The information will prove helpful to testers and developers who need to find specific information about a tool, language binding, or similar item.

In addition to tools and APIs that fall under the Selenium umbrella, the documentation is exhaustive. The goal is to familiarize individual testers (particularly beginners) with all the features and requirements of automation testing.

5. Support for Chrome Debugging Protocol

The application cache, Fetch, Network, Profiler, Performance, and other Chrome development properties are now available to QAs. In addition to performing geolocation testing and simulating poor network conditions, QAs can also leverage Chrome DevTools APIs. Chrome DevTools Protocol is natively supported by Selenium 4. Furthermore, this API can be used by developers and quality assurance testers to test and resolve critical bugs for specific web pages more quickly and easily.

6. Deprecation of Desired Capabilities

Several Desired Capabilities were used primarily to define the test environment for the Selenium Grid, namely the browser name, version, and operating system used for the test execution. An option in Selenium 4 replaces a capability object. To do this, testers must create an Options object, set test requirements, and pass it to the Driver constructor. The following options objects will be used for defining browser-specific capabilities going forward:

  • Firefox – FirefoxOptions

  • Chrome – ChromeOptions

  • Internet Explorer (IE) – InternetExplorerOptions

  • Microsoft Edge – EdgeOptions

  • Safari – SafariOptions

7. Modifications in the Actions Class

The Actions class in Selenium is primarily used to simulate mouse and keyboard inputs on specific web elements (e.g., Left, Right, Double, etc.) so that they can only be executed under automation and without human intervention. Several new methods have been added to the Actions class in Selenium 4, including the following:

  • click(WebElement)

MoveToElement(onElement).click() is replaced with this method in the Actions class. Using it, you can click on a particular web element.

  • clickAndHold(WebElement)

The moveToElement(onElement).clickAndHold() method will be replaced with this method. In this case, the element is selected without releasing the click.

  • contextClick(WebElement)

This method replaces moveToElement(onElement).contextClick(). This will be accomplished by right-clicking option.

  • doubleClick(WebElement)

The moveToElement(element).doubleClick() method has been replaced with this method. When a component is double-clicked, it will be activated.

  • release()

There was a method (user for releasing the pressed mouse button) in the org.openqa.selenium.interactions.ButtonReleaseAction class that was used for this purpose initially. Some changes have been made to the Selenium version, which has been placed in the Actions class.

8. Browser Window and Tab Control

With Selenium 4, you can control browser windows using new functionalities. For instance, the newWindow() method can open a new browser tab or window. To decide between a window or tab, you can specify the new window type as WindowType.Window or WindowType.Tab.

Phases of Selenium4 Test Process Execution

During automation testing with Selenium 4, an application goes through several phases. The aim of this section is to give you a deeper understanding of those phases that lead to successful testing.

1) Test Planning

The focus of this phase is to understand what to automate, organise resources, prepare the team for task distribution, set up budgets, and so on. After the plan has been prepared, it is important to have the team review it. So start by:

  • Get details about the environment (UI Design and Database) from the development team.

  • Assess the AUT (Application Under Test) in terms of object identification and element identification.

Selenium IDE: Record the navigations and playback them for analysis (Record + Playback)

Selenium WebDriver: Analyse the AUT with Element Inspectors,

  • Mozilla Firefox – Built-in feature “Page inspector.”

  • Google Chrome – Built-in Developer tools (F12)

  • MS Edge – Built-in Developer tools (F12)

Select Test Cases for Automation

a. Each build should have a set of test cases that can be executed at the beginning and during modifications (Smoke, Sanity)

b. Each modified build can be tested for regression and retraction with a set of test cases.

c. Multiple sets of test data can be used to execute a test case (Data Driven Tests)

Specifications for selecting Test Cases:

  • Configure Selenium Tools and Others for Automated Testing

(Selenium WebDriver, TestNG, Eclipse IDE, Java, Maven, Jenkins, etc.)

  • Using Eclipse's IDE, you can edit files, use syntax highlighting and context help, and compile code automatically.

  • Java (JDK) Software must be downloaded and installed on your computer.

  • In the OS environment, set the Java Environment Variable path.

  • From www.selniumhq.org, download the Java language binding for Selenium WebDriver and add it to the Java Project in Eclipse.

  • TestNG Testing framework can be downloaded and installed from the Eclipse IDE.

  • In Selenium Test Cases, download and instantiate browser drivers (Firefox, Chrome, MS Edge).

2) Generate Basic Tests/Test Cases

As part of this phase, test cases are generated that need to be focused and worked on so that the application is as efficient as possible before being presented to an audience.

In UFT:

1) Object Repository based Test Design (Recording, Keyword Driven Methodology)

Or

2) Descriptive Programming (Static Programming and Dynamic Programming)

In Selenium:

a) Selenium IDE: Using the Recording feature or typing test steps using Element Locators and Selenium commands to record selenium tests.

b) Selenium WebDriver: Using the Element Locators and the WebDriver API Commands.

3) Enhance Test Cases

A good application can be made better by improving upon the test cases that were written in the previous phase.

a) Inserting Verification points

In UFT:

Using Checkpoints (UFT Tool feature)

Using VBScript conditional statements

In Selenium IDE:

Using “verify” or “assert” commands

In Selenium WebDriver:

Using WebDriver Verification Commands (limited use)

Using Programming Control Flow Statements

Using TestNG Testing Framework “assert” methods

b) Parameterization

  • Replacing constant (fixed) values with parameters is called Parameterization.

  • Passing single value or multiple values.

  • Use the Parameterization feature for Data Driven Testing.

In UFT:

Using Data Table (UFT tool feature)

Using VBScript Automation Object Models (FileSystemObject, Excel Object.)

In Selenium IDE: No Support

In Selenium WebDriver: Using programming (Flat files/excel files).

c) Synchronization

In UFT: Using Synchronization Point, or wait for a command, or increasing Tool default time

In Selenium IDE: Using Synchronization Timeout feature ( Tool feature)

In Selenium WebDriver: Using programming wait feature or WebDriver command

d) Error Handling

Handling expected and unexpected Errors

In UFT: Using Recovery Scenarios (tool feature or VBScript features)

In Selenium WebDriver: Using programming features (Ex: exception handling in Java)

e) Adding Comments

To make the code readable and to disable the code from execution.

In UFT: Use VBScript Comment syntax.

In Selenium IDE: Use Selenium IDE comments syntax.

In Selenium WebDriver: Use Programming Syntax (for example if you use Java, then use Java Comment syntax)

4) Run & Debug Test Cases

After all aspects of the application have been examined, the next step is to run it and remove bugs with each run.

Run > Debug > Run… and so on.

A mandatory task in Testing is running Test Cases, whereas Debugging Test Cases is optional in Automated Testing.

Run Test Scripts / Test Cases

  • Run a Single Test case

  • Batch Testing

In UFT:

Use the “Test Batch Runner” tool, AOM Script, ALM/QC, etc.

In Selenium IDE: using the Test Suite feature

In Selenium WebDriver: Using Programming and using Testing Framework

Debug Test Cases

Note: Debugging feature is NA for Manual Testing, and It is only for Automated Testing

What is Debugging?

Implementing a step-by-step process to locate and isolate errors.

When debugging is required?

Scenario 1: Test Case doesn't show any errors and provides desired results - Not required.

Scenario 2: Errors in the test case - Optional.

Scenario 3: No errors are reported, and the test case does not provide the desired results - Required.

Debugging is needed whenever the Test case does not show any errors and does not provide the desired result.

5) Analyze Test Results and Report Defects

Creating a report of all the analyses made during the above-mentioned phases is much more important than you might think. The purpose of this step is to analyze your application's status and, more importantly, its defects. Upon which you will need to report further.

a) Analyze Test Result:

Test Results can be generated using Programming Control Flow statements or Testing Framework verification methods with Selenium WebDriver; it does not come with a built-in Result Report facility.

Status of Test Results in Software Testing

1) Pass (if expected == actual)

2) Fail (if expected != actual)

3) Warning (Whenever Test Case is not executing correctly)

4) Done (if there is no verification point in the Test case)

b) Reporting Defects:

After analyzing the test results, defects are reported if deviations from expected results are found.

Functional Test Automation and Defect Management

  • Selenium with Excel

  • Selenium with Bugzilla or Jira.

To Wrap Up

With Selenium 4, Selenium test automation has experienced a tremendous architectural shift, making it more stable and feature-rich than before. Selenium has become invincible due to compliance with the World Wide Web Consortium.

Automating Selenium tests using Selenium 4 makes it possible to automate browsers. Through the new features and improvements in Selenium 4, the tool has gained user trust and confidence to be used for Selenium Automation Testing projects without the fear of getting outdated. Hence, must use them for your automation testing tasks.

In case you have found a mistake in the text, please send a message to the author by selecting the mistake and pressing Ctrl-Enter.
Alex 9.8K
Joined: 4 years ago
Comments (0)

    No comments yet

You must be logged in to comment.

Sign In / Sign Up