我正在與.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