From your question, we have 2 parts as follow: Let me use C# .

  1. Organizing the Definition of test objects using .
    Please have a look in my answer at another thread

  2. for you test functions, and to handle this part we have to handle 2 points.

    1. Data management functions to handle use SQL queries to read/update Excel sheets.

Excel Connection String, to be stored in config file

<add name="MyExcelConn" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=[Path to Test Data Sheet];Extended Properties='Excel 12.0 Xml;HDR=YES';"/>

Sample Reading , function to return data table.

public static DataTable GetExcelDataTable(string query)
        {

            OleDbConnection conn = new OleDbConnection();
            if (ConfigurationManager.ConnectionStrings["MyExcelConn"] != null)
                conn.ConnectionString =ConfigurationManager.ConnectionStrings["MyExcelConn"].ConnectionString;
            DataTable dt = new DataTable();
            OleDbCommand cmd;
            try
            {
                conn.Open();
                cmd = new OleDbCommand(query, conn);
                dt.Load(cmd.ExecuteReader(CommandBehavior.CloseConnection));

                return dt;
            }
            catch (Exception ex)
            {

               // log error
                return null;
            }
            finally
            {
                conn.Close();
            }
        }

2. How to Drive the Test Data for you test functions.

Design of Excel Sheet

Excel sheet sample login test data

Test Function Design, After following the previous shared answer above. your function will looks like this

public static bool Login(DataRow loginTable)
        {
            bool retRes = true;
            try
            {
                Browser.pgLogin.txtUserName.SetValue(loginTable["userID"].ToString().Trim());                
                Browser.pgLogin.txtPassword.SetValue(loginTable["Password"].ToString().Trim());                
                Browser.pgLogin.btnSignin.Click();

                return retRes;
            }
            catch (Exception ex)
            {
               // Log error
                return false;
            }
        }

Data Table to hold Test Data

 DataRow loginRow = null;
loginRow = GetExcelDataTable("Select * from [Login$] where RowID = " + iLoginRow).Rows[0];

Calling the Test Function with Test Data

Login(loginRow );

I hope this helps you and answers your question. for more details we can chat.



Source link https://sqa.stackexchange.com/questions/18341/can-we-use-data-driven-approach-with-page---using-page-factory-any-e

LEAVE A REPLY

Please enter your comment!
Please enter your name here