Added extension methods for handling webfields
This commit is contained in:
35
EATestFramework/Extensions/WebElementExtension.cs
Normal file
35
EATestFramework/Extensions/WebElementExtension.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using OpenQA.Selenium;
|
||||||
|
using OpenQA.Selenium.Support.UI;
|
||||||
|
|
||||||
|
namespace EATestFramework.Extensions
|
||||||
|
{
|
||||||
|
public static class WebElementExtension
|
||||||
|
{
|
||||||
|
|
||||||
|
public static void SelectDropDownByText(this IWebElement element, string text)
|
||||||
|
{
|
||||||
|
var select = new SelectElement(element);
|
||||||
|
select.SelectByText(text);
|
||||||
|
}
|
||||||
|
public static void SelectDropDownByValue(this IWebElement element, string value)
|
||||||
|
{
|
||||||
|
var select = new SelectElement(element);
|
||||||
|
select.SelectByValue(value);
|
||||||
|
}
|
||||||
|
public static void SelectDropDownByIndex(this IWebElement element, int index)
|
||||||
|
{
|
||||||
|
var select = new SelectElement(element);
|
||||||
|
select.SelectByIndex(index);
|
||||||
|
}
|
||||||
|
public static void ClearAndEnterText(this IWebElement element, string value)
|
||||||
|
{
|
||||||
|
element.Clear();
|
||||||
|
element.SendKeys(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetSelectedDropDownValue(this IWebElement element)
|
||||||
|
{
|
||||||
|
return new SelectElement(element).SelectedOption.Text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using EATestFramework.Driver;
|
using EATestFramework.Driver;
|
||||||
|
using EATestFramework.Extensions;
|
||||||
using EATestProject.Model;
|
using EATestProject.Model;
|
||||||
using OpenQA.Selenium;
|
using OpenQA.Selenium;
|
||||||
using OpenQA.Selenium.Support.UI;
|
using OpenQA.Selenium.Support.UI;
|
||||||
@ -26,8 +27,7 @@ namespace EATestProject.Pages
|
|||||||
txtName.SendKeys(product.Name);
|
txtName.SendKeys(product.Name);
|
||||||
txtDescription.SendKeys(product.Description);
|
txtDescription.SendKeys(product.Description);
|
||||||
txtPrice.SendKeys(product.Price.ToString());
|
txtPrice.SendKeys(product.Price.ToString());
|
||||||
var select = new SelectElement(ddlProductType);
|
ddlProductType.SelectDropDownByText(product.ProductType.ToString());
|
||||||
select.SelectByText(product.ProductType.ToString());
|
|
||||||
btnCreate.Click();
|
btnCreate.Click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user