Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Selenium - Automation Testing
WhatsApp
Guest User
11y
4.6
k
0
0
25
Blog
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
People also reading
Membership not found