Created
June 26, 2019 10:01
-
-
Save krishna-acondy/f43e3e5dbe5424f471e524bcb919f8c2 to your computer and use it in GitHub Desktop.
Base Page
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
namespace AutomatedUiTests.Pages | |
{ | |
public abstract class BasePage | |
{ | |
public string Url => WebDriver.Url; | |
public void Close() | |
{ | |
WebDriver.Close(); | |
} | |
public void Refresh() | |
{ | |
WebDriver.Navigate().Refresh(); | |
} | |
public virtual bool HasLoaded() | |
{ | |
var result = DocumentReady((IJavaScriptExecutor) driver); | |
return result.Equals("complete"); | |
} | |
public virtual void WaitFor(TimeSpan timeSpan) | |
{ | |
Thread.Sleep(timeSpan); | |
} | |
public virtual void WaitUntil(Func<bool> condition, int timeoutValue = 30) | |
{ | |
var wait = new WebDriverWait(WebDriver, TimeSpan.FromSeconds(timeoutValue)); | |
wait.Until(driver => condition.Invoke().Equals(true)); | |
} | |
public virtual void WaitUntilLoaded() | |
{ | |
var wait = new WebDriverWait(WebDriver, TimeSpan.FromSeconds(10)); | |
wait.Until(driver => DocumentReady((IJavaScriptExecutor) driver)); | |
} | |
public string Title => Header.Title; | |
protected BasePage(IWebElement element) | |
{ | |
_webElement = element; | |
} | |
protected IWebElement FindElement(By locator) | |
{ | |
var wait = new WebDriverWait(WebDriver, TimeSpan.FromSeconds(30)); | |
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(locator)); | |
WebDriver.ExecuteJavaScript("arguments[0].scrollIntoView();", _webElement.FindElement(locator)); | |
return _webElement.FindElement(locator); | |
} | |
protected IEnumerable<IWebElement> FindElements(By locator) | |
{ | |
return _webElement.FindElements(locator); | |
} | |
protected Header Header => | |
new Header(_webElement.FindElement(By.TagName("xpl-header"))); | |
private readonly IWebElement _webElement; | |
private IWebDriver WebDriver => ((IWrapsDriver) _webElement).WrappedDriver; | |
private static bool DocumentReady(IJavaScriptExecutor executor) => | |
executor.ExecuteScript("return document.readyState").Equals("complete"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment