I currently have a single class that gets a string which is the heading of a certain page. Depending on that heading, I need to call a method from the corresponding class. The button click method will be different depending on the page. These page classes will become quite big as there are plenty of controls on each page. My StepDefinitions
class will be receiving any action (e.g. a button click) and then needs to direct it to the right class to do the action.
PageClass one:
namespace MobileAppTesting.Pages
{
class LoginPage
{
public string PageName;
public void ClickButton()
{
//click button
}
}
}
PageClass two:
namespace MobileAppTesting.Pages
{
class HomePage
{
public string PageName;
public HomePage()
{
PageName = "Home";
}
public void ClickButton()
{
//click button
}
}
}
Generic Class:
namespace MobileAppTesting.Pages
{
class GenericPage
{
public GenericPage()
{
//empty constructor
}
public void ClickButton()
{
//click button
}
}
}
StepDefinitions:
namespace MobileAppTesting
{
class StepDefinitions
{
LoginPage _loginPage;
HomePage _homePage;
public StepDefinitions()
{
_loginPage = new LoginPage();
_homePage = new HomePage();
}
public GetCurrentClass()
{
string pageName = GetPageName(); //would return page name or empty if no pagename available
*HELP****************************************************************************
return single class where PageName of the Page Classes = pageName, if empty return GenericPage ?? <-- This is where I am stuck
}
public void ClickButton(string buttonName)
{
GetCurrentClass().ClickButton();
}
}
}