TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Selenium - Automation Testing
Guest User
Jun 29, 2014
4.4
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
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;
//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();
}
}
}
Follow me
@sumitjolly
selenium - automation testing
Next Recommended Reading
Live Unit Test In Visual Studio 2017