In VS, how to write automate test cases through Selenium:
Download file "selenium-dotnet-2.20.0.zip" from https://code.google.com/p/selenium/downloads/detail?name=selenium-dotnet-2.20.0.zip&can=2&q= Unzip files and place it in new folder say 'Selenium'
Download NUnit (www.nunit.org) and TestDriven (http://testdriven.net/download.aspx) and install it.
Create new C# project in VS2010
Add References of dll files unzipped in step 2, say Webdriver etc.
Add Reference of Nunit.framework
Include namespaces accordingly in you CS file
- using System;
- using System.Threading; //include namespace (NS)
- using NUnit.Framework; //add reference and include NS
- using OpenQA.Selenium; //add reference and include NS
- using OpenQA.Selenium.Firefox; //add reference and include NS
- namespace Project1
- {
- [TestFixture]
- public class CTD
- {
- private IWebDriver _driver;// = new FirefoxDriver();
- [SetUp]
- public void Init()
- {
- _driver = new FirefoxDriver(); //you can use InternetDriver for IE
- _driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(100));
- //seconds you can define maximum time of any event to be executed so test shouldn't fail
- }
- [Test]
- public void TestCase1()
- {
- _driver.Navigate().GoToUrl("http://localhost:xxxxx/abc.aspx");
- //replace your localhost portno and mention startpage for test
- IWebElement query = _driver.FindElement(By.Id("txtFName));
- //Find element on webpage
- query.SendKeys("Sumit Jolly"); //fills data in textbox
- Assert.AreEqual ("Sumit Jolly", _driver.FindElement(By.Id("txtFName)));
- //Test whether data entered by you is right
- _driver.FindElement(By.Id("btnSubmit")).Click();
- }
- [Test]
- public void TestCase2()
- {
- }
- [TearDownAttribute]
- public void Clean()
- {
- Thread.Sleep(1000); //milliseconds
- // TODO add wait
- _driver.Quit();
- }
- }
- }
SubashPosted Sep 15, 2016, 7:59 AM
Nice one sir
Former memberPosted Jun 30, 2014, 7:42 AM
Its good !
Prerana TiwariPosted Jun 30, 2014, 7:29 AM
Nice explanation....