Wednesday 23 November 2011

Data Driven using SQL database in selenium webdriver with CSharp

driver.Navigate().GoToUrl(baseURL);
SqlCommand comm = new SqlCommand();
comm.Connection = new SqlConnection("Data Source=DANJANEYULU\\SQLEXPRESS;" + "Initial Catalog=Userdata; Trusted_Connection=Yes"); //Windows Authentication
string sql = @"select Username,Password from Userdata";
comm.CommandText = sql;
comm.Connection.Open();
SqlDataReader cursor = comm.ExecuteReader();
while (cursor.Read())
{
  string username=cursor["Username"].ToString();
  string password = cursor["Password"].ToString();
  driver.Navigate().GoToUrl(baseURL);
  driver.FindElement(By.LinkText("REGISTER")).Click();
  driver.FindElement(By.Name("email")).SendKeys(username);
  driver.FindElement(By.Name("password")).SendKeys(password);
  driver.FindElement(By.Name("confirmPassword")).SendKeys(password);
}
comm.Connection.Close();



3 comments:

  1. Thanks Man. I am looking for this type of example from long time. your effort is much Appreciated.

    ReplyDelete
  2. thank you so much :)

    ReplyDelete
  3. Hi Anjaneyulu thanks for this small tutorial.can you help me how to do same data driven testing using excel sheet

    ReplyDelete