Regression Testing Example with Selenium

|
| By Webner

Regression Testing Example With Selenium

Regression testing is a process to verify that code changes in the product do not impact the existing functionality of the product. In simple words, regression testing is performed to re-execute test cases in order to check whether the previous functionality of the application is working fine and the new changes have not introduced any new bugs.

Some examples of Regression Testing:

1. When new functionality is added to the application.
2. When there is a change in requirements.
3. When some issues are fixed.

Regression Testing Example with selenium:

We are taking an example of the exam list page in study-section (https://www.studysection.com) website, where on the exam list page we get the free exams after clicking on the free exam checkbox. This is working fine. But a new feature is added on the page for the “list view” of the exams on the page from the default grid view. To verify the new feature does not affect the existing functionality of the page we have to perform regression testing.

Selenium code to test the functionality of the Free exam check box on the Exam list page:

Code:

package Testing;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Loginpage 
{
WebDriver driver;

	public void login() throws InterruptedException{
	   
	//Open the Chrome Browser
	System.setProperty("webdriver.chrome.driver","C:/chromedriver.exe");
	driver = new ChromeDriver();
	driver.manage().window().maximize();
	driver.manage().deleteAllCookies();
		
             //GOTO the URL
	driver.get("https://www.studysection.com/Categories/basic-computer-skills");
		
	//Get the size of the exams on the page before clicking on the Free exam checkbox button
	List <WebElement> nofpaidexams = driver.findElements(By.xpath("//span[@class='ajax-certificate-name data_for_search cursor_pointer']"));
	System.out.println("Total Number of Exams before Click on the Free Exam checkbox "+nofpaidexams.size());
		
	//Get the name of the exams on the page
	for(int i = 0;i<nofpaidexams.size();i++)
	{
	String name = nofpaidexams.get(i).getText();
	System.out.println(name);	
	}
	
           //Click on the Free exam checkbox
	driver.findElement(By.xpath("//input[@id='btnFreeExams']")).click();
	System.out.println("n");
			
           //Get the size of the exams on the page after clicking on the Free exam checkbox button
	List<WebElement> nofreexams = driver.findElements(By.xpath("//span[@class='ajax-certificate-name data_for_search cursor_pointer']"));
	System.out.println("Total Number of Exams after Click on the Free Exam checkbox "+nofreexams.size());
		
	//Get the name of the exams on the page 
	for(int i = 0;i<nofreexams.size();i++)
	{
             String name1 = nofreexams.get(i).getText();
	System.out.println(name1);
              }
}
	public static void main(String[] args) throws InterruptedException {
	Loginpage call = new Loginpage();
	call.login();
	}
}

Output:

Total number of Exam on the exam list page before click on the Free exam checkbox:
Regression Testing  Selenium

Total number of Exam on the exam list page after click on the Free exam checkbox:
Regression Testing  Selenium

Testing of the List view feature on the same page:

After testing the Free exam checkbox button functionality new feature is added on the same page that is used for the List view of the exams on the page. To test that we are writing the code to click on the list button on the page. After verifying it is working fine. We are integrating the code with the existing code to ensure that this functionality is not affecting the previous functionality of the page.

Code:

  //Test the new added feature(List view)
driver.findElement(By.xpath("//button[@class='btn active cursor_pointer show_list_view_of_certificates']/i")).click();

Output:
Regression Testing  Selenium

Leave a Reply

Your email address will not be published. Required fields are marked *