【发布时间】:2018-04-22 15:23:08
【问题描述】:
我在查看其中一堂课的方法时遇到了麻烦。 我创建了一个 MobileLoginPage 类,我想单击菜单按钮。 我注意到已经定义了一个方法来单击名为 MobileNavigationPage 的类中的菜单按钮。该方法称为 ClickMenuNavigation
由于这个方法已经存在,我应该可以从我的 MobileLoginPage 类中调用它。避免重复代码。 当我编写代码 MobileNavigationLogin 时,我无法调用它。 没有方法出现。 我什至尝试通过定义一个方法(getMenuNavigationElement)来调用定位器元素来返回定位器。我在 LoginPage 类中看不到这个定位器。
类已经在BasePage类中实例化了,不知道为什么看不到它的方法。
我的代码 sn-p 是:
BasePage 和我们所有的类都在这里实例化:
public class BasePage : SpecflowBaseTest
{
internal MobileNavigationPage MobileNavigationPage => new
MobileNavigationPage(Browser);
internal MobileLoginPage MobileLoginPage => new
MobileLoginPage(Browser);
}
MobileNavigationPage 是:
public void MobilenavigationPage : BasePage
{
#region Elements
[FindsBy(How = How.Id, Using = "MobileMenuNavigation")]
private IWebElement MenuButton {get; set;}
#endregion
#region Actions
private void ClickMenuNavigation()
{
Actions.Click.Element(Browser, MenuButton);
}
private IWebElement getMenuNavigationElement()
{
return MenuButton;
}
#endregion
}
MobileLoginPage 是:
public class MobileLoginPage : BasePage
{
# region Actions
public void ClickBrandFromMenuNavigation{}
{
// I want to call ClickMenuNavigation() from here
}
#endregion
}
如何从 LoginPage 类调用 MobileNavigationPage 中定义的方法?
【问题讨论】:
标签: c# selenium selenium-webdriver webdriver