我正在与.NET 4.5
,VS2013
和Selenium
一起工作。分组扩展方法
我正在为其页面流结构和字段结构有点类似的产品编写硒测试。
将值设置为我使用的扩展方法的领域上IWebDriver
例子:
private void WillsCustomerDetail(IWebDriver driver)
{
driver.WillsSetMainCustomerTitle("Dr");
driver.WillsSetMainCustomerGender("Male");
driver.WillsSetMainCustomerName("Liufa");
driver.WillsSetMainCustomerSurname("Afuil");
driver.WillsSetMainCustomerDateOfBirth(new DateTime(1955, 12, 26));
...
}
public static IWebElement WillsSetMainCustomerName(this IWebDriver driver, string value)
{
return driver.SetText(value, WillsElements.CustomerDetails.MainCustomer.Firstname);
}
public static IWebElement SetText(this IWebDriver driver, string value, string selector)
{
var element = driver.FindElement(By.CssSelector(selector));
element.SendKeys(value);
return element;
}
public static class WillsElements
{
public static class CustomerDetails
{
public static class MainCustomer
{
public static string Title
{
get { return "#Customers-0--Title"; }
}
...
}
}
}
什么我有问题就是我的方法命名
WillsSetMainCustomerTitle
- 在现实中是串联
Wills - product(web journey),
MainCustomer - partial page,
标题 - 字段,
和下一个产品我将有LpaSetMainCustomerName
和大多数其他领域,使它成为一个巨大的混乱。
我想有是
driver.Wills.MainCustomer.SetTitle("Dr");
为扩展方法
是否有实现分组扩展方法的一种方式? (或者获得类似的东西,这样可以在仍然有扩展方法的情况下进行良好的分组)。
为什么不能扩展'MainCustomer'的类型? – haim770 2015-01-21 09:51:07
'WillsElements'的字段是什么? – Codor 2015-01-21 09:51:46
@ haim770我可以,但是我必须将'IWebDriver'传入每个调用'Wills.MainCustomer.SetTitle(driver,“Dr”); '或者我误解了你的问题? – 2015-01-21 09:56:50