Guys,
Here I have mentioned some ideas about how to do data driven test in selenium tool with selenium RC libraries.
Here is some sample code and you can pickup from here...
- using System;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using Microsoft.VisualStudio.TestTools.UnitTesting.Web;
- using NUnit.Framework;
- using Selenium;
- namespace SELENIUM
- {
- [TestClass]
- public class SEL_TEST2
- {
- private DataSet getData()
- {
- string connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='D:\Selenium\TESTDATA.xlsx';Extended Properties='Excel 12.0;HDR=Yes;IMEX=1'";
- OleDbConnection conn = new OleDbConnection(connString);
- OleDbDataAdapter adp1 = new OleDbDataAdapter("Select * from [GmailLogin$]", conn);
- OleDbDataAdapter adp2 = new OleDbDataAdapter("Select * from [GmailSend$]", conn);
- DataSet DS = new DataSet();
- DataTable DT1 = new DataTable("TABLE1");
- DT1.Columns.Add("UserName");
- DT1.Columns.Add("Password");
- DS.Tables.Add(DT1);
- adp1.Fill(DS.Tables["TABLE1"]);
- DataTable DT2 = new DataTable("TABLE2");
- DT2.Columns.Add("ToAddress");
- DT2.Columns.Add("Subject");
- DT2.Columns.Add("MailBody");
- DS.Tables.Add(DT2);
- adp2.Fill(DS.Tables["TABLE2"]);
- adp1.Dispose();
- adp2.Dispose();
- conn.Close();
- return DS;
- }
- [TestMethod]
- public void TestGmailSend()
- {
- ISelenium RC;
- StringBuilder verificationErrors;
- string[] Browsers = { "*iehta", "*firefox", "*googlechrome" };
- DataSet TD = new DataSet();
- TD = getData();
- for (int b = 0; b < Browsers.Length; b++) // for each browser execute all
- {
- RC = new DefaultSelenium("localhost", 4444, Browsers[b], "http://www.google.co.in/");
- RC.Start();
- Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual("", verificationErrors.ToString());
- for (int a = 0; a < TD.Tables["TABLE1"].Rows.Count; a++) // No of users - Email Accounts
- {
- RC.Open("");
- RC.Click("//a[text()=\"Gmail\"]");
- RC.WaitForPageToLoad("30000");
- RC.Click("//input[@type=\"submit\" and @value=\"Sign in\"]");
- if (RC.IsElementPresent("link=Load Basic HTML"))
- {
- RC.Click("link=Load Basic HTML");
- }
- RC.WaitForPageToLoad("120000");
- for (int i = 0; i < TD.Tables["TABLE2"].Rows.Count; i++) // Test data iterations - Send Mail
- {
- //selenium.Open("https://mail.google.com/mail/?hl=en&shva=1#compose");
- //selenium.Click("");
- RC.Click("link=Compose Mail");
- RC.WaitForPageToLoad("60000");
- RC.Click("//form[1]/table/tbody/tr/td/input[@name='nvp_bu_send']");
- RC.WaitForPageToLoad("30000");
- }
- RC.Click("link=Sign out");
- RC.WaitForPageToLoad("30000");
- }
- RC.Stop();
- Console.WriteLine("{1}: Passed"+ Browsers[b]);
- }
- getData().Dispose();
- TD.Dispose();
- }
- }
- }
and finally my test data file looks like,
have 2 sheets in TestData.xlsx file --- GmailLogin and GmailSend
GmailLogin sheet contains 2 columns
UserName
Password
GmailSend sheet contains 2 columns
ToAddress
Subject
MailBody
These are the columns which are referred in above code to take test data from these mentioned sheets...
Hope these info will lead to start data driven selenium RC tests....
வாழ்க வளமுடன்....
Comments
Post a Comment