Skip to content

Instantly share code, notes, and snippets.

@krishna-acondy
Created June 26, 2019 09:50
Show Gist options
  • Save krishna-acondy/110cec7f7da126f1bad0ebfe252b60e9 to your computer and use it in GitHub Desktop.
Save krishna-acondy/110cec7f7da126f1bad0ebfe252b60e9 to your computer and use it in GitHub Desktop.
Base Component
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