Last active
August 29, 2015 13:57
-
-
Save k0stya/9674193 to your computer and use it in GitHub Desktop.
selenium playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using OpenQA.Selenium; | |
using OpenQA.Selenium.Chrome; | |
using OpenQA.Selenium.Support.UI; | |
namespace BEPlayGround1 | |
{ | |
public class Navigation | |
{ | |
private LoginPage _loginPage; | |
private IWebDriver _webDriver; | |
private ContentPage _contentPage; | |
public LoginPage LoginPage | |
{ | |
get | |
{ | |
return _loginPage = (_loginPage ?? new LoginPage(_webDriver)); | |
} | |
} | |
public ContentPage ContentPage | |
{ | |
get { return _contentPage = (_contentPage ?? new ContentPage(_webDriver)); } | |
} | |
public void CloseSession() | |
{ | |
_webDriver.Quit(); | |
} | |
public void OpenSession() | |
{ | |
_webDriver = new ChromeDriver(); | |
} | |
} | |
public class ContentPage | |
{ | |
private readonly IWebDriver _webDriver; | |
public ContentPage(IWebDriver chromeDriver) | |
{ | |
_webDriver = chromeDriver; | |
} | |
public ContentPage Navigate() | |
{ | |
_webDriver.Navigate().GoToUrl(@"http://bddplayground.azurewebsites.net/admin/#/content"); | |
return this; | |
} | |
public ContentPage GoToWriteNewPostScreen() | |
{ | |
var wait = new WebDriverWait(_webDriver, TimeSpan.FromSeconds(10)); | |
var el = wait.Until(drv => drv.FindElement(By.ClassName("btn-header"))); | |
el.Click(); | |
return this; | |
} | |
public ContentPage Publish() | |
{ | |
var wait = new WebDriverWait(_webDriver, TimeSpan.FromSeconds(10)); | |
var el = wait.Until(drv => drv.FindElement(By.PartialLinkText("Publish"))); | |
el.Click(); | |
return this; | |
} | |
public ContentPage CheckIfPostPublished(string postTitle) | |
{ | |
var wait = new WebDriverWait(_webDriver, TimeSpan.FromSeconds(10)); | |
wait.Until(drv => drv.PageSource.Contains(postTitle)); | |
return this; | |
} | |
public ContentPage PostTitle(string title) | |
{ | |
var wait = new WebDriverWait(_webDriver, TimeSpan.FromSeconds(10)); | |
var el = wait.Until(drv => drv.FindElement(By.Name("txtTitle"))); | |
el.SendKeys(title); | |
return this; | |
} | |
public ContentPage PostBody(string body) | |
{ | |
var wait = new WebDriverWait(_webDriver, TimeSpan.FromSeconds(10)); | |
var el = wait.Until(drv => drv.FindElement(By.Id("editor"))); | |
el.SendKeys(body); | |
return this; | |
} | |
} | |
public class LoginPage | |
{ | |
private IWebDriver _webDriver; | |
public LoginPage(IWebDriver webDriver) | |
{ | |
_webDriver = webDriver; | |
} | |
public LoginPage Navigate() | |
{ | |
_webDriver.Navigate().GoToUrl(@"http://bddplayground.azurewebsites.net/Account/login.aspx"); | |
return this; | |
} | |
public LoginPage EnterCredentials(string login, string password) | |
{ | |
var log = _webDriver.FindElement(By.Id("UserName")); | |
log.SendKeys(login); | |
var pwd = _webDriver.FindElement(By.Id("Password")); | |
pwd.SendKeys(password); | |
return this; | |
} | |
public LoginPage ClickLogin() | |
{ | |
_webDriver.FindElement(By.Id("LoginButton")).Click(); | |
return this; | |
} | |
public LoginPage ShouldContainLogOffLink() | |
{ | |
_webDriver.FindElement(By.PartialLinkText("Log off")); | |
_webDriver.FindElement(By.PartialLinkText("Content")); | |
return this; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment