In this article, I would like to explain about performing data driven testing in Selenium using .Net.
In this article, I would like to explain about performing data driven testing in Selenium. I have used C# language and for IDE is Visual Studio 2010 Ultimate edition to achieve our aim. As we will proceed we will know, step by step how to Create a Data Driven Test method using Selenium in .Net. So for now, let's roll our sleeve and get going. Before going into details, it would be better to provide a synopsis of a few things so that even you can become familiar with everything. And as I will proceed you will not feel cut off from the main theme. Selenium Selenium is a portable software testing framework for web applications. Selenium provides a record/playback tool for authoring tests without learning a test scripting language (Selenium IDE). It also provides a test domain-specific language (Selenese) to write tests in a number of popular programming languages, including C#, Java, Groovy, Perl, PHP, Python and Ruby. The tests can then be run against most modern web browsers. Selenium deploys on Windows, Linux, and Macintosh platforms. (Source: http://en.wikipedia.org/wiki/Selenium_(software)) I will refrain from going into details about Selenium. Since there is tons of documentation and information available on the internet which already explain Selenium. You can go through over there. You can visit the Selenium official website for the documentation: http://seleniumhq.org/ Download the Selenium for .Net from here: http://seleniumhq.org/download/ Apart from that you can visit my blog also to get to know the Selenium web driver using .Net. http://seleniumdotnet.blogspot.com/. Data Driven Testing Data driven testing is an action through which a set of test input and/or output values are read from data files (ODBC source, CSV files, Excel files, DAO objects, ADO objects etc) and are loaded into variables in captured or manually coded script. Data-Driven testing generally means executing a set of steps with multiple sets of data. Selenium does not provide any out-of-the box solution for data driven testing but leaves it up to the user to implement this on his own. That is why we are here; to do out of box. Code: Prerequisites
So now our main coding will start from here: We will be using the Unit testing feature provided by VS2010 and C# code for the same.
Thread.Sleep(900);//Not a good practise to use Sleep //Get the screen shot of the web page and save it on local disk SaveScreenShot(WebDriver.Title); Assert.AreEqual(expectedValue, currencyValue.Trim()); }
var selectConvertItem=newSelectElement(setValueConvert); var selectIntoItem =newSelectElement(setValueInto); selectConvertItem.SelectByText(convertVal); selectIntoItem.SelectByText(inToVal); calculateButton.Click(); var currencyValue =outPutvalue.GetAttribute("value"); Thread.Sleep(900);//Not a good practise to use Sleep //Get the screen shot of the web page and save it on local disk SaveScreenShot(WebDriver.Title); Assert.AreEqual(expectedValue,currencyValue.Trim()); }
OOPs Principle and Theory