Skip to content

Instantly share code, notes, and snippets.

@johnmmoss
Created February 28, 2015 16:55
Show Gist options
  • Save johnmmoss/b74445923615d2ff99ad to your computer and use it in GitHub Desktop.
Save johnmmoss/b74445923615d2ff99ad to your computer and use it in GitHub Desktop.
Example Page Objects using Selenium WebDriver
public class HomePage
{
private readonly IWebDriver webDriver;
protected static string BaseUrl = ConfigurationManager.AppSettings["WebsiteUrl"];
public HomePage(IWebDriver webDriver)
{
this.webDriver = webDriver;
}
public RegisterPage GoToRegisterPage()
{
var registerLink = webDriver.FindElement(By.Id("registerLink"));
registerLink.Click();
return new RegisterPage(webDriver);
}
}
public class RegisterPage
{
private readonly IWebDriver webDriver;
protected static string BaseUrl = ConfigurationManager.AppSettings["WebsiteUrl"];
public RegisterPage(IWebDriver webDriver)
{
this.webDriver = webDriver;
}
public void EnterDetails(string username, string password)
{
webDriver.FindElement(By.Id("UserName")).SendKeys(username);
webDriver.FindElement(By.Id("Password")).SendKeys(password);
webDriver.FindElement(By.Id("ConfirmPassword")).SendKeys(password);
}
public void ClickRegister()
{
var elem = webDriver.FindElement(By.XPath("//input[@type='submit']"));
elem.Click();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment