Skip to content

Instantly share code, notes, and snippets.

@stevecooperorg
Created April 1, 2014 20:42
Show Gist options
  • Save stevecooperorg/9922745 to your computer and use it in GitHub Desktop.
Save stevecooperorg/9922745 to your computer and use it in GitHub Desktop.
Using initialized variables
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace GoogleTest
{
[TestClass]
public class SharingVariableTest
{
private string homePageUrl;
[TestInitialize]
public void Initialize()
{
this.homePageUrl = "http://www.google.co.uk"; ;
}
[TestMethod]
public void TestThatUsesInitializedVariable()
{
IWebDriver driver = new ChromeDriver();
//Notice navigation is slightly different than the Java version
//This is because 'get' is a keyword in C#
driver.Navigate().GoToUrl(this.homePageUrl);
// Find the text input element by its name
IWebElement query = driver.FindElement(By.Name("q"));
// Enter something to search for
query.SendKeys("Cheese");
// Now submit the form. WebDriver will find the form for us from the element
query.Submit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment