Blog
February 28, 2022
Automating tests enables achieving speed and efficiency throughout the development process. With automated Selenium regression testing, teams can find bugs and issues in their web tests on time and with minimal tester overhead.
In this blog post, we will focus on running automated Selenium regression tests and explain how to run code-based and scriptless regression tests.
Back to topWhat Is Selenium Regression Testing?
Selenium regression testing utilizes the Selenium platform to check the behavior of an application after updates have been made or a bug has been fixed to assess whether the new functionality is working and ensure user experience is not impacted.
Why Selenium for Regression Testing
Selenium is an open-source set of tools for automated web testing. Today, it is the leading tool for web testing on both desktop and mobile devices. By running test Selenium scripts against web browsers like Chrome, Firefox, and Safari, testers can ensure their web app doesn’t break.
Selenium can be used for a wide variety of tests, like UI testing, sanity testing, and regression testing. Running Selenium for regression testing helps developers find defects in their web apps before they impact customers. Strategically, such tests help developers modify code and introduce new features.
Automating Selenium regression testing lets testers focus on fixing issues or on more complicated types of tests. In addition, automation ensures tests are run methodically and efficiently and are not subject to human error.
Related Reading: Automated Regression Testing: A Comprehensive Guide >>
Back to topHow to Start Regression Testing With Selenium
To maximize the impact of your Selenium regression testing (as well as software regression testing with other frameworks), we recommend the following best practices:
1. Clarify Requirements
Focus on the product and clarify what’s important for you, the product team, your customers, and other stakeholders.
Ask yourself:
- Should I test only one application or more?
- When am I going to run the regression tests - at the end of each sprint or only after major changes?
- How is a major change defined?
- When do I need to reach full regression coverage?
2. Review Potential Use Cases
Use cases will help you understand exactly what you are facing. Start with a logical description of the tests you would like to cover. Don’t forget difficult scenarios so you can be fully prepared.
3. Create a Baseline
A proper baseline we can build on top of will enable us to understand where we are and how we’re progressing to where we need to be.
4. Choose Your Tech Stack
Choosing your tech stack includes the scripting language, the testing platform, and the scaling tools. Take into consideration the expected results, inbound and outbound data, and what needs to be covered.
Besides the usual tapping and scrolling you also need to prepare the following for mobile web testing:
- Fingerprint / Face ID.
- Simulation of network conditions (loss of connectivity, bad network coverage).
- Simulation of location.
- Image injection, such as barcodes or QR code scanning.
- Audio injection.
- SIM cards.
- Latest device OS availability since day 1 release.
- Full control of system settings (i.e. Offline mode, Low battery mode).
5. Organize Processes
The creation of processes is where we can start talking about automation and scaling with CI/CD tools. Expanding too quickly might lead to wasting valuable resources.
6. Create Tests
Achieve a critical mass of tests and add them to the automation pattern. All these tests need to be compliant with the general course of action and they should be atomic. This means they should be able to run autonomously without dependencies on other tests.
Now you’re ready to run the tests. Let’s see how, with Perfecto.
Back to topHow to Run Selenium Regression Tests With Perfecto
There are three ways to perform Selenium regression testing with Perfecto: code-based, low-code with our open-source Quantum framework, and scriptless. Let’s look at each one.
Option 1: Coded Selenium Regression Testing
For our code-based option, we will create a Java-based Selenium regression test, with TestNG and Maven. Please note this is an example project and there are many ways to create coded tests.
In your project, you will see three different device options: Android, iOS, and desktop.
You will notice that the code is identical. WithSelenium and Perfecto, you can reuse the same code for different device types. This makes them a fast and easy solution for responsive website testing.
Here is part of the code snippet for this first type of scenario:
reportiumClient.testStart("Perfecto desktop web test", new TestContext("tag2", "tag3")); //Starts the reportium test
reportiumClient.stepStart("browser navigate to perfecto"); //Starts a reportium step
driver.get("https://www.perfecto.io");
reportiumClient.stepEnd();
reportiumClient.stepStart("Verify title");
String aTitle = driver.getTitle();
PerfectoLabUtils.assertTitle(aTitle, reportiumClient); //compare the actual title with the expected title
reportiumClient.stepEnd();
Now, I will create a few scenarios that cover some of my own use cases. To keep the tests atomic, I will keep the navigation to the site for each step.
Test steps:
- Navigate to Perfecto.io
- Click on the first tab (PLATFORM)
- Select the first menu item (Testing Cloud)
- Make sure all submenu items are there (Mobile, Web, Scriptless, Platform Overview)
To create more tests, repeat these steps, but click on the second and third menu items when you reach step 3.
For help with the locators for the mobile test, you can use Perfecto's Object Spy to select the element you need after opening a device in your cloud and navigating to the desired page.
Below you will see a snippet of the code for the testing cloud use case for mobile devices:
reportiumClient.stepStart("Verify Testing Cloud Submenu Items");
driver.findElementByXPath("//*[@id=\"mm-toggle\"]").click();
driver.findElementByXPath("//*[text()=\"Platform\"]").click();
driver.findElementByXPath("//*[text()=\"Testing Cloud\"]").click();
driver.findElementByXPath("//*[text()=\"Mobile\"]");
driver.findElementByXPath("//*[text()=\"Web\"]");
driver.findElementByXPath("//*[@id=\"platform-col-2\"]//*[text()=\"Scriptless\"]");
driver.findElementByXPath("//*[@id=\"platform-col-2\"]//*[text()=\"Platform Overview\"]");
reportiumClient.stepEnd();
For the desktop web test you can use DevTools:
Below is a snippet of the code for the testing cloud use case for web browsers. As you can see, test creation is easy and fun to play with. This makes testing user-friendly and easier to run:
reportiumClient.stepStart("Verify Testing Cloud Submenu Items");
driver.manage().window().maximize();
driver.findElementByXPath("//*[@id=\"block-mainnavigationmegamenu\"]/ul/li[1]/span").click();
driver.findElementByXPath("//*[@id=\"platform-col-1\"]/nav/ul/li[1]/span").click();
driver.findElementByXPath("//*[@id=\"platform-col-2\"]/nav[1]/ul/li[1]/a");
driver.findElementByXPath("//*[@id=\"platform-col-2\"]/nav[1]/ul/li[2]/a");
driver.findElementByXPath("//*[@id=\"platform-col-2\"]/nav[1]/ul/li[3]/a");
driver.findElementByXPath("//*[@id=\"platform-col-2\"]/nav[1]/ul/li[4]/a");
reportiumClient.stepEnd();
You can also organize the tests with the help of TestNG by navigating to the following XML: “PerfectoJavaSample/testng_perfecto_selenium.xml.”
This video shows how to run coded Selenium regression tests with Perfecto in more detail:
You can see how easy and straightforward it is to simply build up the whole test by going through the logical steps you have in your mind. Quantum also provides a large number of pre-written steps for testers.
If you want to add your own steps you can easily do that as well.
Option 3: Scriptless Selenium Regression Testing
Perfecto Scriptless is a solution that will help anyone who is not comfortable with writing and then supporting code, but still wants to test web app features. Test setup is easy and can be done by a few mouse clicks. All tests are based on Selenium code, but are created in a non-programatic way in Perfecto Scriptless. To start with Perfecto Scriptless for Web, navigate to your Perfecto Cloud and click "Build Web Test."
After the test is executed, you can check Perfecto's reporting and monitor your test results.
Back to topBottom Line
Selenium regression testing is both simple and scalable with Perfecto, and accessible to everyone on your testing team.
Try out Perfecto’s regression testing capabilities with a free trial, or watch a demo of our regression testing (and other testing) capabilities.