Selenium - Automation Testing
In this blog you will learn about automate test cases through Selenium.
Automation Testing
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;
- using NUnit.Framework;
- using OpenQA.Selenium;
- using OpenQA.Selenium.Firefox;
- namespace Project1
- {
- [TestFixture]
- public class CTD
- {
- private IWebDriver _driver;
- [SetUp]
- public void Init()
- {
- _driver = new FirefoxDriver();
- _driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(100));
-
- }
- [Test]
- public void TestCase1()
- {
- _driver.Navigate().GoToUrl("http://localhost:xxxxx/abc.aspx");
-
- IWebElement query = _driver.FindElement(By.Id("txtFName));
-
- query.SendKeys("Sumit Jolly");
- Assert.AreEqual ("Sumit Jolly", _driver.FindElement(By.Id("txtFName)));
-
- _driver.FindElement(By.Id("btnSubmit")).Click();
- }
- [Test]
- public void TestCase2()
- {
- }
- [TearDownAttribute]
- public void Clean()
- {
- Thread.Sleep(1000);
-
- _driver.Quit();
- }
- }
- }
Follow me @sumitjolly