Selenium Test Data Excel vs Database

I use Selenium scripts to do regression testing and I have all the test data in excel. This helps me manage the test data.
When doing regression testing you should have a standard data to test your application. If you are getting the data from the database to run the regression suite and if something fails you are not sure if its because of the test data from the database or because of the changes to the application.

So, I prefer to keep the test data in excel and use it in my selenium scripts.
I hope this will give you an idea of preparing the test data.
Here is code for you to read the data from excel:


string CPPath = @"c:\TestData\HFControlPanel.xls";
Microsoft.Office.Interop.Excel.Application CPapp = new excel.Application();
// create the workbook object by opening the excel file.
excel.Workbook CPworkBook = CPapp.Workbooks.Open(CPPath, 0, true, 5, "", "", true, excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
// Get The Active Worksheet Using Sheet Name Or Active Sheet
ObjectReference ObjectRef = new ObjectReference();
excel.Worksheet CPworkSheet = (worksheet)CPworkBook.Worksheets.get_Item("ControlPanel");
string CPCountry = ((excel.Range)CPworkSheet.get_Range("SelectCountry", Type.Missing)).Value2 as string;

3 thoughts on “Selenium Test Data Excel vs Database

  1. Raju says:

    hi Pavandeep,

    I am new to selenium and not planning to automate the application.
    could you send the scripts which could read from excel data?

    • Pavandeep Puddupakkam says:

      ObjectRef class to read the data from excel:

      [code]
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using excel = Microsoft.Office.Interop.Excel;
      using worksheet = Microsoft.Office.Interop.Excel.Worksheet;
      using workbook = Microsoft.Office.Interop.Excel.Workbook;

      namespace Testing
      {
      public class ObjectReference
      {
      public string login_xp { get; set; }
      public string login_tx { get; set; }

      public static ObjectReference GetTestData()
      {

      string CPPath = @”C:\\Selenium\\TestData\\testing.xls”;

      Microsoft.Office.Interop.Excel.Application CPapp = new excel.Application();
      // create the workbook object by opening the excel file.
      excel.Workbook CPworkBook = CPapp.Workbooks.Open(CPPath, 0, true, 5, “”, “”, true, excel.XlPlatform.xlWindows, “\t”, false, false, 0, true, 1, 0);
      // Get The Active Worksheet Using Sheet Name Or Active Sheet
      var ObjectRef = new ObjectReference();
      excel.Worksheet CPworkSheet = (worksheet)CPworkBook.Worksheets.get_Item(“Sheet1″);
      ObjectRef.login_xp = ((excel.Range)CPworkSheet.get_Range(“login_xp”, Type.Missing)).Value2 as string;
      ObjectRef.login_tx = ((excel.Range)CPworkSheet.get_Range(“login_tx”, Type.Missing)).Value2 as string;

      CPworkBook.Close(false, false, false);
      CPapp.Quit();

      return ObjectRef;
      }
      }
      }
      [/code]
      —————————————————————————————————————–
      Test class to use the data defined in the ObjectRef class
      [code]
      [Test]

      public void LoginTest()
      {

      var ObjectRef = ObjectReference.GetTestData();

      selenium.DeleteAllVisibleCookies();
      selenium.Open(“/Login.aspx”);
      selenium.Type(ObjectRef.login_xp, ObjectRef.login_tx);
      [/code]

  2. Devan says:

    My page is going from one page to another page. The another page is authenticated login page. Can we get the control of that page in selenium.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>