Selenium Framework Project and Folder Structure

By Vijay

By Vijay

I'm Vijay, and I've been working on this blog for the past 20+ years! I’ve been in the IT industry for more than 20 years now. I completed my graduation in B.E. Computer Science from a reputed Pune university and then started my career in…

Learn about our editorial policies.
Updated May 9, 2025

In the last tutorial, we familiarized you with the basics of test automation Frameworks, their components, and their types. The frameworks illustrated in the previous tutorial were a few of the most popular frameworks used by the testing fraternity.

We briefly discussed Module Frameworks, Library architecture-based frameworks, Keyword-driven frameworks, Data-driven frameworks, and Hybrid frameworks. There are various other frameworks also in place.

Please take note we will adopt a Data Driven Test Automation Framework for the rest of our tutorials.

Framework Creation and Accessing Test Data

Selenium Framework Creation and Accessing Test Data from Excel

In the current tutorial in this series, we will provide you with a sample framework, the Excels which would store the test data and their Excel manipulations. On the same lines, we would move forward and introduce new strategies and resources to mature our framework.

So let’s learn:

  • Framework creation strategy using a sample project.
  • Access the test data stored in the external data source.

Moving ahead, we will start with the description of the project hierarchy that we will create to segregate the various project components.

Refer to the below image for the project hierarchy created for the sample project. You can easily create the below Java project within Eclipse, following the same process we use in the earlier tutorials.

Selenium Framework

Selenium Project Folder Structure – Walkthrough

#1) src – The folder contains all the test scripts, generics, readers, and utilities. All these resources are nothing but simple Java classes. Under the source (src) folder, we have created a hierarchy of folders.

a) test – The “test” folder is constituted of majorly two ingredients–the test suite and the folders representing the various modules of the application under test. Thus, each of these folders contains the test scripts specific to the module to which it is associated.

Testsuite logically combines more than one test script. Thus, the user can mark an entry of any of the test scripts within the test suite that he/she desires to execute in the subsequent runs.

b) utilities – The “utilities” folder is constituted of various generics, constants, readers, and classes for implementing user-defined exceptions. Each of the folders under utilities has its significance.

  • Excel Reader: A generic and common class has been created to read the test data (input parameters and expected results) from the Excel sheets
  • EnvironmentConstants: The folder is an integration of the Java classes that store the static variables referencing the paths and other environmental details. These details can be the Application URL, URL to the Databases, Credentials for Databases, and URL to any third-party tool being used. The disparate application URLs can be set for different environments (dev, prod, test, master, slave, etc).
  • DataSetters: The folder incorporates the classes that implement the getters and setters of the test data fetched from Excel. To load multiple sets of Test data, we create ArrayLists.
  • UserRoles: The folder accommodates the classes that take care of the Role-based access criteria, if any, for instinct users.
  • FunctionLibrary: The folder is constituted of the classes that contain functions and methods that can be shared and used amongst the multiple classes. Very often, we are supposed to perform certain procedures before and aftermath of the actual test execution like login to the application, setting up environments, activities related to rolls, data manipulations, writing results, and methods that generate pre/post-conditions to other methods. Since we perform these activities for all or most of the test script. Thus, it is always recommended to create a separate class for such activities instead of coding them repeatedly in each of the test scripts.
    • PreConditionalMethods
    • PostConditionalMethods

Very often, we are supposed to perform certain procedures prior and aftermath to the actual test execution like login to the application, setting up environments, activities related to user roles, data manipulations, writing results, methods those generate pre/post-conditions to other methods.

Since we perform these activities for all or most of the test scripts, thus it is always recommended to create a separate class for such activities instead of coding them repeatedly in each of the test scripts.

CommonMethods

Like Pre and post-conditions, there may be methods and functions more than one test script can use these. Thus, these methods are grouped together in a class. The test script can access these methods using the object of the common class.

#2) excel files – The excel files are considered to be the data source/data providers for test script execution. These files store the test data into key-value pairs. Make a note that we create a separate Excel sheet for each of the test script, i.e. each test script has its own test data file.

In order to maintain traceability, the name of the test script has been kept the same as the corresponding test data files or Excel sheet. Check out the sample test data format below:

Test Data Format:

Selenium Framework 2

Each of the columns represents a key and each of the rows represents a test data/value. Specify the multiple rows to execute the same test script with multiple data sets. Mark that the test data formats are solely user-defined. Thus based on your requirements, you can customize the test data files.

#3) library – The folder acts as a repository/artifactory for all the required jar files, libraries, drivers, etc to successfully build the test environment and to execute the test scripts. Refer to the following figure to check out the libraries we would be employed within our project.

Selenium Framework 3

#4) logs – The folder contains a .txt file that stores the logging information upon each execution.

#5) test material – The folder contains the actual test data that needs to be uploaded if any. This folder would come into picture when we come across test scenarios where the user is required to upload files, documents, pictures, reports, etc.

#6) build.xml – The XML file is used by the “Ant Server” to automate the entire build process.

#7) log4j.xml – This xml file is used by a Java-based utility named as “Log4j” to generate the execution logs.

Note: We will study more about the logs, user-defined exceptions and Ant in detail in the upcoming tutorials. So don’t panic if you get confused between the notions.

Now, as we move forward let us understand the phenomenon where we access the Excel files and populate the test data into our test scripts.

To comprehend the process easier, we would break down the process into the following steps.

Test Data Creation

Step #1: The first step is to create the test data with which we would be executing the test scripts. Considering the aforementioned test data format, let us create an Excel file named as “TestScript1”. Furnish the values in the elements.

Excel file

Step #2: The next step is to download a standard Java-based API/Library named as “Java excel Library” (jxl) to be able to access the already created generic methods for Excel Manipulation.

Step #3: Create a generic Excel reader class named as “ExcelReader.java”. Copy the below code in the ExcelReader.java.

package Utilities;
import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
 
/**
 * This is a utility class created to read the excel test data file before performing the test steps.
 * This class loads the excel file and
 * reads its column entries.
 *
 */
 
public class ExcelReader {
                /**
                 * The worksheet to read in Excel file
                 */
 
                public static Sheet wrksheet;
                /**
                 * The Excel file to read
                 */
 
                public static Workbook wrkbook = null;
                /**
                 * Store the column data
                 */
 
                public static Hashtable<String, Integer> dict = new Hashtable<String, Integer>();
                /**
                 * Create a Constructor
                 *
                 * @param ExcelSheetPath
                 * @throws BiffException
                 * @throws WeblivException
                 */
 
                public ExcelReader(String ExcelSheetPath) throws IOException, BiffException {
 
                            // Initialize
                                try {
                                               wrkbook = Workbook.getWorkbook(new File(ExcelSheetPath));
                                               wrksheet = wrkbook.getSheet("Sheet1");
                                } catch (IOException e) {
                                                throw new IOException();
                                }
                }
                /**
                 * Returns the Number of Rows
                 *
                 * @return Rows
                 */
 
                public static int RowCount() {
                                return wrksheet.getRows();
                }
                /**
                 * Returns the Cell value by taking row and Column values as argument
                 *
                 * @param column
                 * @param row
                 * @return Cell contents
                 */
 
                public static String ReadCell(int column, int row) {
                                return wrksheet.getCell(column, row).getContents();
                }
                /**
                * Create Column Dictionary to hold all the Column Names
                 */
                public static void ColumnDictionary() {
                                // Iterate through all the columns in the Excel sheet and store the
                                // value in Hashtable
                                for (int col = 0; col < wrksheet.getColumns(); col++) {
                                                dict.put(ReadCell(col, 0), col);
                                }
                }
                /**
                 * Read Column Names
                 *
                 * @param colName
                 * @return value
                 */
 
                public static int GetCell(String colName) {
                                try {
                                                int value;
                                                value = ((Integer) dict.get(colName)).intValue();
                                                return value;
                                } catch (NullPointerException e) {
                                                return (0);
                                }
                }
}

Step #4: Create a generic class –“CommonMethods.java”. Create a common method within the class that would read the cells from the Excel sheet using the methods implemented in ExcelReader.java.

/**
* Read the test data from excel file
*
* @param data The TestData data object
*/
 
public void readExcelData (TestData data) {
       ArrayList<String> browser = new ArrayList<String>();
       ArrayList<String> username = new ArrayList<String>();
       ArrayList<String> password = new ArrayList<String>();
       ArrayList<String> element1 = new ArrayList<String>();
       ArrayList<String> element2 = new ArrayList<String>();
       ArrayList<String> element3 = new ArrayList<String>();
 
       // Get the data from excel file
       for (int rowCnt = 1; rowCnt < ExcelReader.RowCount(); rowCnt++) {
       browser.add(ExcelReader.ReadCell(ExcelReader.GetCell("Browser"), rowCnt));
       username.add(ExcelReader.ReadCell(ExcelReader.GetCell("User ID"), rowCnt));
                     password.add(ExcelReader.ReadCell(ExcelReader.GetCell("Password"), rowCnt));
                     element1.add(ExcelReader.ReadCell(ExcelReader.GetCell("Element1"), rowCnt));
                     element2.add(ExcelReader.ReadCell(ExcelReader.GetCell("Element2"), rowCnt));
       element3.add(ExcelReader.ReadCell(ExcelReader.GetCell("Element3"), rowCnt));
       }
       data.setBrowser(browser);
       data.setLoginUser(username);
       data.setPassword(password);
       data.setElement1(element1);
       data.setElement2(element2);
       data.setElement3(element3);
       }

Step #5: Create a new java class named as “TestData.java”. This class would act as a getter and setter for excel data. Copy and paste the following code in the TestData.java class.

package Utilities.dataSetters;
import java.util.ArrayList;
public class TestData {
       private ArrayList<String> loginUser = null;
       private ArrayList<String> password = null;
       private ArrayList<String> browser = null;
       private ArrayList<String> element1 = null;
       private ArrayList<String> element2 = null;
       private ArrayList<String> element3 = null;
       /**
        * @return loginUser
        */
       public ArrayList<String> getLoginUser() {
              return loginUser;
       }
       /**
        * @param loginUser
        */
       public void setLoginUser(ArrayList<String> loginUser) {
              this.loginUser = loginUser;
       }
       /**
        * @return password
        */
       public ArrayList<String> getPassword() {
              return password;
       }
       /**
        * @param password
        */
       public void setPassword(ArrayList<String> password) {
              this.password = password;
       }
       /**
        * @return browser
        */
       public ArrayList<String> getBrowser() {
              return browser;
       }
       /**
        * @param browser
        */
       public void setBrowser(ArrayList<String> browser) {
              this.browser = browser;
       }
       /**
        * @return element1
        */
       public ArrayList<String> getElement1() {
              return element1;
       }
       /**
        * @param element1
       */
       public void setElement1(ArrayList<String> element1) {
              this.element1 = element1;
       }     
       /**
        * @return element2
        */
       public ArrayList<String> getElement2() {
              return element2;
       }
       /**
        * @param element2
        */
       public void setElement2(ArrayList<String> element2) {
              this.element2 = element2;
      }
       /**
        * @return element3
        */
       public ArrayList<String> getElement3() {
              return element3;
       }
       /**
        * @param element3
       */
       public void setElement3(ArrayList<String> element3) {
              this.element3 = element3;
       }     
}

Step #6: The next step is to create instances of “TestData.java” and “CommonMethods.java” java classes within the test script to access and populate the test data. Refer to the below code snippet for object initialization, reading Excel data, and populating the values wherever required.

// Create Objects
public ExcelReader excelReaderObj;
CommonMethods commonMethodobj = new CommonMethods();
TestData td = new TestData();
 
// Load the excel file for testing
excelReaderObj = new ExcelReader(Path of the excel);
 
// Load the Excel Sheet Col in to Dictionary for use in test cases
excelReaderObj.ColumnDictionary();
 
// Get the data from excel file
commonMethodobj.readExcelData (td);
 
// Populate the username
driver.findElement(By.id("idofElement")).sendKeys(data.getLoginUser().get(0));

Therefore using the instance of testData.java class in conjunction with getters, any test data value can be populated within the script.

Conclusion

The tutorial mainly revolved around the notions like Framework Creation and Accessing test data from the excels. We made you acquainted with the Framework creation strategy using a sample project. We briefly laid the light on the various components and aspects of our framework.

To access the test data stored in the external data source, we used a java-based API – jxl. We also created the sample code for reading and populating the Excel data into the test scripts.

Next Tutorial #22: In the next tutorial, we will base our tutorial on the concepts of generics and their accessibility mechanism. We would create a few sample generic methods and then access them within the test scripts. We would also introduce you to the concept of Testsuite and the sample code development.

Was this helpful?

Thanks for your feedback!

Recommended Reading

  • Data Driven Framework in Selenium using Apache POI

    How to work on Data Driven Framework in Selenium Using Apache POI? Data Driven Framework is one of the most popular Automation Testing Frameworks in the current market. Data Driven automated testing is a method in which the test data set is created in the excel sheet, and is then…

  • what is Data driven testing

    In this tutorial, we will discuss Data Driven Testing in an extensive manner.  We include what it is, how it works, pros & cons, etc. Let's get started.  Often, there are a number of data sets that we have to run the same tests on. Also, creating a different test…

  • Hybrid Driven Framework In Selenium

    This Informative Tutorial Explains What a Hybrid Framework, the Uses and Components of Selenium Hybrid Driven Framework, and How to Implement it is: What is a Hybrid Framework? Hybrid Driven Framework is a combination of both the Data-Driven and Keyword-Driven framework. Here, the keywords, as well as the test data, are externalized.…

  • Keyword Driven Framework In Selenium

    This Comprehensive Tutorial on Keyword Driven Framework Explains Various Components of the Framework & How to Create One in Selenium: In general, Framework is a set of guidelines, which when followed will give beneficial results. The Keyword-Driven framework is a technique to externalize keywords/actions that are used in the script…


READ MORE FROM THIS SERIES:



70 thoughts on “Selenium Framework Project and Folder Structure”

  1. I need the framework steps like folder structured framework, as where we will write all types of actions, test cases description, keywords etc., in the excel sheet for ex : keyword driven framework.

    Reply
  2. Thanks so much for the efforts in putting these wonderful tutorials together.Very easy to follow and self explanatory.Please, for the purpose of some us who are new to java, could you please shed more light on this particular tutorial(21).If you can explain some of the code as you have done for previous tutorials.

    Reply
  3. Thanks a lot for including this. But please please please could you please have a full-length example especially for this tutorial which will help many for creating their framework as people struggle a lot for the creation of Framework.

    It’s a request if this tutorial can be covered in detail. So we will start implementing our programs with framework going forward.

    Again a heartful thanks to Shruti and STH

    Reply
  4. Hi, I am new to automation, firstly forgive me for any dumb question. I’m at Step 6 in the above tutorial, and not sure on how to create instances of “TestData.java” and “CommonMethods.java”. Do i have to create a new class or just copy the code within already created classes ?

    Reply
  5. Hi,

    I would like to download the entire sample project explained in this tutorial.

    Request you to send me or let me know the location from where I can download.

    Really good tutorial. Keep up the good work.

    Thanks

    Reply
  6. Hello,
    if anybody know sites like beta sites that new testers can create framework for them in order to help new testers to learn automation with selenium deeply please let me know

    Reply
  7. Thank you very much shruti
    Nice Explanation This site is very useful to gain much knowledge on selenium and better to serve in interview process.

    Note : I have two questions on selenium.

    1. How to write bulk of names in excel sheet in a perticular column?
    2. Difference between FileInputStream concept and BufferReadered Concept?

    Reply
  8. Hi shruti,

    One more question – If we use Apache Poi java libraries then what should be the changes in the code of read and write Excel file ?

    – JJ

    Reply
  9. I used ODBC connection with excel to create data pool using Array list and avoided the usage of excel functions, hashtable

    public static void readExcelDataContact (TestData data)
    {
    Connection c = null;
    Statement stmnt = null;
    ArrayList Name = new ArrayList();
    ArrayList Email = new ArrayList();
    ArrayList Phone = new ArrayList();
    ArrayList City = new ArrayList();
    try
    {
    Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
    c = java.sql.DriverManager.getConnection(“jdbc:odbc:Driver={Driver do Microsoft Excel(*.xls)};DBQ=D:\\TestData.xlsx;ReadOnly=0”);
    stmnt = c.createStatement();
    String query = “select * from [Contact$]”;
    ResultSet rs = stmnt.executeQuery( query );
    while(rs.next())
    {
    Name.add(rs.getString(“Name”));
    Email.add(rs.getString(“Email”));
    Phone.add(rs.getString(“Phone”));
    City.add(rs.getString(“City”));
    }
    }
    catch( Exception e )
    {
    System.err.println( e );
    }
    finally
    {
    try
    {
    stmnt.close();
    c.close();
    }
    catch( Exception e )
    {
    System.err.println( e );
    }
    }

    data.setName(Name);
    data.setEmail(Email);
    data.setPhone(Phone);
    data.setCity(City);

    }

    Reply
  10. Very good and brief review of the framework is worth taking before any interview which will cover most of the automation interview questions and will give us big structure behind the framework.
    Very well presented..
    Thanks for sharing.

    Reply
  11. i have implented code for facebook login very useful guide from u ,without understanding the concept i can not dot ……thanks for explainig about selenium.

    Reply
  12. I want to write script for automatic filling different contact form , access link (URls) by Excel sheet ..please tell me how to do , how to collect all id’s in that dynamic form and hot to access ..using java selenium

    Reply
  13. Hi,
    I am working on Hybrid framework and I am not able to split a text which is of stored in a variable of type webelement.
    Can someone help me?

    Reply
  14. Hi Shruti,

    From where i can download the Java excel Library ?
    Any official site or to download any particular library or version ?

    Thanks in advance…. 🙂

    Reply
  15. Hi, I have gone through all the tutorials and I must commend you for the effort you put in preparing this.

    However, amongst all the tutorials, I found myself struggling with understanding no #21. It isn’t as self-explanatory as other tutorials.

    Because it is really an important topic for test automation, is it possible to be a little bit more clearer with the explanations you provided in that section.

    Thanks again for putting this tutorial together which happens to be the best amongst other online tutorials I have stumbled into.

    Reply
  16. How to iterate until the last row of data in excel? for example i have 10 rows on my data table(excel) and I want to execute my scenario 10 times, so after executing the first row, it will then execute the next and succeeding rows up to the last.

    Reply
  17. hi, where we get id which is “idofElement” and string which we have passed using the method data.getLoginUser().get(0) in the line driver.findElement(By.id(“idofElement”)).sendKeys(data.getLoginUser().get(0)); ??.. sorry ididn’t get this.

    Reply
  18. Hi, I have some doubt. Please clearify it.

    Suppose, in our excel sheet, we have 10 combinations of username and password. In the script, we are entering username and password for one username and password. To run for other username and password, we need to change the data.setLloginUser(1) and data.getPassword().get(1) in send keys .
    Is there any efficient way by which it will run automatically for all the username and password.

    Reply
  19. Thanks for putting all this up, but this particular tutorial is really not very learner-friendly as there are few explantions.
    The code itself seems to be all out of alignment, which makes it difficult to understand for novices like me.

    Reply

Leave a Comment