Skip to content

Instantly share code, notes, and snippets.

@tarun3kumar
Created January 4, 2012 06:46
Show Gist options
  • Save tarun3kumar/1558847 to your computer and use it in GitHub Desktop.
Save tarun3kumar/1558847 to your computer and use it in GitHub Desktop.
Selenium C# test
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;
namespace SeleniumTests
{
[TestFixture]
public class NewTest
{
private ISelenium selenium;
private StringBuilder verificationErrors;
[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", 4444, "*iehta",
"http://www.google.com/");
selenium.Start();
verificationErrors = new StringBuilder();
}
[TearDown]
public void TeardownTest()
{
try
{
selenium.Stop();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
[Test]
public void TheNewTest()
{
selenium.Open("http://www.google.com/");
Assert.AreEqual("Google", selenium.GetTitle());
selenium.Type("q", "Selenium OpenQA");
Assert.AreEqual("Selenium OpenQA", selenium.GetValue("q"));
selenium.Click("btnG");
selenium.WaitForPageToLoad("5000");
Assert.IsTrue(selenium.IsTextPresent("www.openqa.org"));
Assert.AreEqual("Selenium OpenQA - Google Search",
selenium.GetTitle());
}
}
}
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;
namespace SeleniumTests
{
[TestFixture]
public class NewTest
{
private ISelenium selenium;
private StringBuilder verificationErrors;
[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", 4444, "*iehta",
"http://www.google.com/");
selenium.Start();
verificationErrors = new StringBuilder();
}
[TearDown]
public void TeardownTest()
{
try
{
selenium.Stop();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
[Test]
public void TheNewTest()
{
selenium.Open("http://www.google.com/");
Assert.AreEqual("Google", selenium.GetTitle());
selenium.Type("q", "Selenium OpenQA");
Assert.AreEqual("Selenium OpenQA", selenium.GetValue("q"));
selenium.Click("btnG");
selenium.WaitForPageToLoad("5000");
Assert.IsTrue(selenium.IsTextPresent("www.openqa.org"));
Assert.AreEqual("Selenium OpenQA - Google Search",
selenium.GetTitle());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment