Parameterized Test Execution Order

Let’s see, How can you Paramertize Execution Order of tests in Selenium. In this tutorial, We will learn How can we decide the Execution Order at Compile time in Selenium.

In this tutorial we will see, If we have the requirement to run the Test Cases Related to one functionality only then How can we do that.

 

So we are going to learn what is the role of Utilities in Framework designing and how can we learn the Data from External Source in Selenium.

In this Tutorial, we will read the Data from External File (Excel file) and use this is our Framework.

 

Configure Apache POI in Project

We will read the Data from Excel File, For this, we need some third party APIs to communicate with the Excel file. We will use POI API to communicate with the Excel Files. Here we will see, How can we configure the POI in Our Project.

 

  • First, we need to Download the POI jar files. (Download form Here!)
  • From the above link, Download the .zip file present within the Binary Distribution section.
  • Unzip this .zip file.
  • Now Open the Eclipse and Right click the project name, navigate to Build Path and select ‘Configure Build Path‘.
  • Click on Add External JARS and navigate to the folder where you have kept the Apache POI jar files.
  • Select the Executable Jar files from all the folders including lib and bin.

You have successfully configured the POI in your project.

 

Parameterized Test Execution Order

Now we will start to design the Framework. In this framework, What we will do-

  • We will keep the Name of Excel Sheet on our Functionality Name or Test Class name. i.e we are testing the functionality of Login then We will keep the sheet name like LoginTest.

  • Now we will keep the Tests in our Excel sheet. In Excel sheet, we will keep the three columns TestID, TestName, and RunMode.

  • In file, RunMode will be Yes or No. If RunMode is yes then Test will execute else Test will be skipped.

 

So we have finalized the Requirements. Now we will see how can we implement these. We will read the POI file and Keep the code inside the Utility package inside the Xls_Reader class.

 

I have designed this Xls_Reader class which is an independent and Flexible class, you can download the code from here. (Xls_Reader)

NoteThis file is important to Execute the Framework.

Below we are going to define the Project Structure and later on, We will discuss all classes and their uses.

Test Paramerization in POM                   Test Paramerization in POM

 

Above we have two Images. In one, you can see the Project Structure. We kept the Xls_Reader.java file inside the Util Package. In this file we will keep the complete code through which we can read the Data from Excel data source.

 

In TestUtil.Java class, we will keep the code to decide what tests should be executed and What should be skipped.

In LoginPageTest.java class, we have kept the sample code for the Login functionality.

In the last, we have TestData.xls file. This is our Test data source, where we will keep the Test Data.

 

In the second Image, we have seen the structure of TestData sheet columns. In this sheet, we have two Test loginTest and forgotPassword tests and corresponding RunMode as well.

Now we will see the code of TestUtil and LoginTest class and see how these classes will behave at Runtime.

 

Now Let’s understand the Implementation of TestUtil.java class.

 

The above method isExecutable will accept the three parameters and return true if RunMode is “Yes” else it will retun false.

Now we will see the Implementation of LoginTest.java class implementation.

 

In the above class, we have declared a Method checkRunMode it will execute within the each Test and verify that is that Test should be Execute or not as mentioned in the TestData.xls file.

 

You can copy-paste the above code in your local machine and execute on your local machine. To execute this code you need to arrange the source code as per the structure we have declared in above in our POM_Framework project.

0 Comment

Leave a Reply