Created
June 26, 2019 09:50
-
-
Save krishna-acondy/110cec7f7da126f1bad0ebfe252b60e9 to your computer and use it in GitHub Desktop.
Base Component
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; | |
namespace AutomatedUiTests.Components | |
{ | |
public interface IComponent | |
{ | |
void WaitFor(TimeSpan timeSpan); | |
void WaitUntil(Func<bool> condition, int timeoutValue); | |
void Hover(); | |
} | |
public abstract class BaseComponent : IComponent | |
{ | |
public virtual bool IsDisabled => !WebElement.Enabled; | |
public bool IsDisplayed => WebElement.Displayed; | |
public virtual string Text => WebElement.Text; | |
protected IWebElement WebElement { get; } | |
protected IWebDriver WebDriver => ((IWrapsDriver) WebElement).WrappedDriver; | |
protected BaseComponent(IWebElement element) | |
{ | |
WebElement = element; | |
} | |
public string GetAttributeValue(string name) | |
{ | |
return WebElement.GetAttribute(name); | |
} | |
public virtual void Hover() | |
{ | |
var action = new Actions(WebDriver); | |
action.MoveToElement(WebElement).Build().Perform(); | |
} | |
public void WaitUntil(Func<bool> condition, int timeoutValue = 30) | |
{ | |
var wait = new WebDriverWait(WebDriver, TimeSpan.FromSeconds(timeoutValue)); | |
wait.Until(driver => condition.Invoke().Equals(true)); | |
} | |
public void WaitFor(TimeSpan timeSpan) | |
{ | |
Thread.Sleep(timeSpan); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment