I'm a learner and a absolute beginner to Java. I'm learning to create a automation framework. I have started building a frame work by watching a online tutorial. But the tutorial was in C# and I was trying to build that in Java. So, I was stuck and not able to figure out what's wrong with my code.
Here is the C# code which I'm referring to:
namespace DemoFramework
{
public static class Pages
{
private static T GetPage<T>() where T : new()
{
var page = new T();
PageFactory.InitElements(Browser.Driver, page);
return page;
}
public static AboutPage About
{
get { return GetPage<AboutPage>(); }
}
public static TopNavigationPage TopNavigation
{
get { return GetPage<TopNavigationPage>(); }
}
}
Here is the Java code which I'm writing:
public class Pages {
static WebDriver driver;
private static Pages GetPage() {
Pages page = new Pages();
PageFactory.initElements(driver,page);
return page;
}
public static AboutPage About {
return return GetPage<AboutPage>();
}
public static TopNavigationPage TopNavigationPage {
return Pages.GetPage<TopNavigationPage>();
}
Could you help me with figuring out what's how to fix this. I'm not able to get how to return for ex. AboutPage.
public static AboutPage About {
return GetPage<AboutPage>();
}
Here's an example of a base page object in java:
Here's an example of a specific page object. The "helper" references are a group of helper methods I have and are declared in my original base page object, but I removed above since implementing your selenium wrapper methods is not what I'm trying to show here. Just know that the helper methods help wrap the selenium methods with exception handling and logging.
Finally, a snippet of the code that implements the above page object:
The following code uses JUnit and JBehave (BDD)