PageFactory doesn't seem to work for child class of PageObject's child

55 views
Skip to first unread message

binni...@gmail.com

unread,
Sep 30, 2014, 7:40:59 PM9/30/14
to wtfra...@googlegroups.com
Let's say I have a hierarchy like so:

- PageObject
- ChildObject
- AnotherObject

If I create a PageFactory of AnotherObject, I get something like NoMatchingPageError: There's, no matching classes to this page.

But it works fine when the PageFactory is for ChildObject

Is there a workaround for this?

Message has been deleted

David Lai

unread,
Oct 1, 2014, 8:35:14 PM10/1/14
to wtfra...@googlegroups.com
I haven't tried that use case.

In the past (I'm working at a C# shop now porting some of this stuff to dotnet), generally I've been using that mechanism with interfaces to handle page variants.  

IAdminPage:
 
def method1:
     
pass
 
def method2:
     
pass

class FreeAdminPage(IAdmin):
 
...

class Premium(IAdmin):
 
...



I think a hackish workaround could be to create an interface and have all 3 implement it.  But I wonder what the underlying issue really is.  Maybe the reflection on the PageFactory isn't picking up subclasses.

binni...@gmail.com

unread,
Oct 2, 2014, 1:37:14 PM10/2/14
to wtfra...@googlegroups.com
It seems to happen not only for subclasses

e.g

class AdminPage(PageObject):
...

class FirstPage(AdminPage):
...

class SecondPage(AdminPage):
...

This is what I originally had. So I was getting that NoMatchingPageError: There's, no matching classes to this page. error when I did this:

navigator = PageFactory.create_page(SecondPage, driver)

But I just found out it happens for classes that inherit from PageObject as well.

e.g

class AdminPage(PageObject):
...

class FirstPage(PageObject):
...

class SecondPage(PageObject):
...

Now, if I do:

navigator = PageFactory.create_page(AdminPage, driver)

It works fine. But if it's something like

navigator = PageFactory.create_page(FirstPage, driver) # or SecondPage

I get that same error

David Lai

unread,
Oct 2, 2014, 1:40:23 PM10/2/14
to wtfra...@googlegroups.com
Python I believe their reflection will only look through classes that are imported at run time.  In the past I worked around this by just creating some sort of __init__.py file on a same folder level as the test and added all the possible page objects that test may use.
Message has been deleted

binni...@gmail.com

unread,
Oct 2, 2014, 2:11:45 PM10/2/14
to wtfra...@googlegroups.com
Do you mean initialize them in the __init__.py? Can you provide an example of what you mean, as I might not be understanding you correctly

These classes are already imported.

In my Test file:

from tests.pages.admin_page import AdminPage
from tests.pages.first_page import FirstPage
...

class Test(WTFBaseTest):

...
navigator = PageFactory.create_page(SecondPage, driver)

David Lai

unread,
Oct 6, 2014, 6:41:48 PM10/6/14
to wtfra...@googlegroups.com
yup, initialize them in the __init__.py file that's on the same directory as all those page objects.

say you have 3 variants,
/pages_objects/admin_page/admin_page_base.py (the others are derivatives or indirect derivatives of this object)
/pages_objects/admin_page/free_admin_page.py
/pages_objects/admin_page/premium_admin_page.py
/pages_objects/admin_page/gold_admin_page.py

then you could create a file like
/pages_objects/admin_page/__init__.py, which contains import statement,

import free_admin_page from free_admin_page.py
,..

Then any time you import any one of those pages (like the base page) to use by the PageFactory, it'll import all the other classes as well so they'll be available to be picked up by the PageFactory via reflection.

binni...@gmail.com

unread,
Oct 7, 2014, 2:32:38 PM10/7/14
to wtfra...@googlegroups.com
It doesn't work, I'm still getting the no matching classes found on this page

David Lai

unread,
Oct 8, 2014, 3:27:38 PM10/8/14
to wtfra...@googlegroups.com
That should work.  You might want to try adding some break points into your page constructors and seeing if they're getting called.  Maybe it's flaw in the page match logic.
Reply all
Reply to author
Forward
0 new messages