[英]C#: How do I call a static method of a base class from a static method of a derived class?
[英]Selenium C# How do I call a method from another class both classes inherit from a base class
我在查看其中一類的方法時遇到麻煩。 我已經創建了MobileLoginPage類,我想單擊菜單按鈕。 我注意到已經定義了一種方法,該方法可以從名為MobileNavigationPage的類中單擊“菜單”按鈕。 該方法稱為ClickMenuNavigation
由於此方法已經存在,因此我應該可以從MobileLoginPage類中調用它。 避免重復代碼。 當我編寫代碼MobileNavigationLogin時,我無法調用它。 沒有方法出現。 我什至嘗試通過定義方法(getMenuNavigationElement)來返回定位器來調用locator元素。 我無法從LoginPage類看到此定位器。
該類已在BasePage類中實例化,我不知道為什么我看不到它的方法。
我的代碼段是:
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中定義的方法?
該方法是private
,這意味着它只能在MobilenavigationPage
。
您可以將其public
,然后它會顯示-
public void ClickBrandFromMenuNavigation()
{
base.MobileNavigationPage.ClickMenuNavigation();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.