Create an instance of a class with Graphene @Page

95 Views Asked by At

Create an instance of a class with Graphene @Page

I have a requirement where I am finding the classes at runtime and invoking its methods at runtime. While invoking its method (using reflection java), everything gets initialize except the pages/classes injected in the searched class.

Say for example I am finding a class XYZ which contains injected grpahene @Page ABC abc; apart from other variables and methods. I am able to find XYZ class at runtime using ClassLoader and get class which I use to create an instance and invoke its methods. While calling its methods, abc is null

How can i load abc while doing this? Is there a way load a class/create an instance in a graphene way?

Furthermore Can I normal java class be injected programmatically with @Page?

1

There are 1 best solutions below

0
vins On

We can create page objects at run time using Graphehe & its context.

PageObjectEnricher.setupPage(GrapheneContext.lastContext(),
                                     GrapheneContext.lastContext().getWebDriver(),
                                     klass);