Thursday 27 October 2011

Writing tests using Selenium WebDriver

using System;
using System.Text;
using System.Threading;
using OpenQA.Selenium;
using NUnit.Framework;
using OpenQA.Selenium.IE;     // For IE include this name space
using OpenQA.Selenium.Support.UI;   //To setup execution speed include this name space
namespace SeleniumWebdriverExample
{
[TestFixture]
public class WebDriverExample
{
IWebDriver driver;

[SetUp]
public void SetupTest()
{
driver = new InternetExplorerDriver();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));  //Time in Seconds

}
[TearDown]
public void TeardownTest()
{
driver.Quit();
}
[Test]
public void TheUntitledTest()
{

driver.Navigate().GoToUrl("http://www.google.co.in/");
IWebElement query = driver.FindElement(By.Name("q"));    // Identifying by name
query.SendKeys("Cheese");                            // Type string into Textbox
IWebElement btnclick = driver.FindElement(By.Name("btnG"));
btnclick.Click();                                              // Button Click
}

}
}

No comments:

Post a Comment