Extending WebElementFacade - page object looks dodgy

3,231 views
Skip to first unread message

Ilyas Patel

unread,
Jul 22, 2013, 11:35:19 AM7/22/13
to thucydid...@googlegroups.com
I want to try and extend WebElementFacade to add custom methods. I have:

public class CustomWebElementFacade extends WebElementFacadeImpl {
    public CustomWebElementFacade(WebDriver driver, ElementLocator locator, long timeoutInMilliseconds) {
        super(driver, locator, timeoutInMilliseconds);
    }
}


When I try to run the tests I get

net.thucydides.core.pages.WrongPageError: The page object class com.company.myefc.desktop.ProfilePage looks dodgy:


Am I missing something?

Alex Okrushko

unread,
Jul 22, 2013, 12:03:48 PM7/22/13
to Ilyas Patel, thucydid...@googlegroups.com
Hi Ilyas,

Here is how to extend the WebElementFacade:

1) Create interface

@ImplementedBy(MyInputImpl.class)
public interface MyInput extends WebElementFacade {

public void doSomething();
}

2) Create implementation

public class MyInputImpl extends WebElementFacadeImpl implements MyInput {

public MyInputImpl(WebDriver driver, ElementLocator locator, int timeout){
   super(driver, locator, timeout);
}

public void doSomething(){
    element.type("done");
}

3) Use it

public class MyPage extends PageObject {

    @FindBy(jquery = "#myelement")
    public MyInput myInput;
}

Let me know if you have any problems with it.


Alex





--
You received this message because you are subscribed to the Google Groups "Thucydides Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thucydides-use...@googlegroups.com.
To post to this group, send an email to thucydid...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ilyas Patel

unread,
Jul 23, 2013, 12:25:15 PM7/23/13
to thucydid...@googlegroups.com
Hi Alex

Thanks for the help. After following the steps, I now get this error:

MyInputImpl.java:[14,8]  \MyInputImpl.java:14: com.efinancialcareers.myefc.core.MyInputImpl is not abstract and does not override abstract method getLocationOnScreenOnceScrolledIntoView() in org.openqa.selenium.internal.Locatable


Alex Okrushko

unread,
Jul 23, 2013, 12:38:55 PM7/23/13
to Ilyas Patel, thucydid...@googlegroups.com

What Selenium version are you using?

Ilyas Patel

unread,
Jul 24, 2013, 5:18:46 AM7/24/13
to thucydid...@googlegroups.com
I'm using the latest Thucydides version which I think encapsulates Selenium.  I get the error at compile time.

<dependency>
            <groupId>net.thucydides</groupId>
            <artifactId>thucydides-core</artifactId>
            <version>0.9.131</version>
</dependency>


[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project PageObjects: Compilation failure: Compilation failure:
[ERROR] /C:/development/redesign_trunk/QA/PageObjects/src/main/java/com/company/myefc/core/MyInputImpl.java:[14,8] C:\development\redesign_trunk\QA\PageObjects\src\main\java\com\company\myefc\core\MyInputImpl.java:14: com.company.myefc.core.MyInputImpl is not abstract and does not override abstract method getLocationOnScreenOnceScrolledIntoView() in org.openqa.selenium.internal.Locatable

Alex Okrushko

unread,
Jul 24, 2013, 9:40:27 AM7/24/13
to Ilyas Patel, thucydid...@googlegroups.com
Hi Ilyas,

This method was removed from the latest Selenium version, but it is still implemented in Thucydides. I'll remove it, so next version should be working fine.

Alex


Ilyas Patel

unread,
Jul 24, 2013, 12:09:35 PM7/24/13
to thucydid...@googlegroups.com
Thank you

Александр Звонов

unread,
Oct 11, 2013, 5:01:26 AM10/11/13
to thucydid...@googlegroups.com, Ilyas Patel
HI,

I did this and got NullPointerException on myInput.
I guess I should make shome changes to PageFactory

Alex Okrushko

unread,
Oct 11, 2013, 7:04:39 AM10/11/13
to Александр Звонов, thucydid...@googlegroups.com, Ilyas Patel

Yes, you need a constructor for the MyPage.

Public MyPage(WebDriver driver) { super(driver); }

Александр Звонов

unread,
Oct 11, 2013, 11:13:18 AM10/11/13
to thucydid...@googlegroups.com, Александр Звонов, Ilyas Patel
It goes without saying that I need a constructor :) 
but how will the system know that it should init a new type.. 

And if it's the only code to implement to get new types worked, how can I trace it? 
What class is responsible for webElements initialisation or how does this process go? 

Alex Okrushko

unread,
Oct 11, 2013, 11:37:01 AM10/11/13
to Александр Звонов, thucydid...@googlegroups.com, Ilyas Patel
> And if it's the only code to implement to get new types worked, how can I trace it? 
What class is responsible for webElements initialisation or how does this process go? 

https://github.com/thucydides-webtests/thucydides/blob/master/thucydides-core/src/main/java/net/thucydides/core/annotations/locators/SmartFieldDecorator.java

This goes through the PageObject and creates the Proxy for each element (that is annotated with FindBy's)


This one intercepts the calls to your proxy, creates the actual instance that is specified in ImplementedBy (ImplementedBy implBy = interfaceType.getAnnotation(ImplementedBy.class);) and calls the method that you called on the proxy.

Here I used the the same logic (or very-very similar) that WebDriver uses with it's PageFactory and what it does when you call initElements(Page.class).

Just by googling I found this article that does similar things.

In any case, if you need more help you can google  "WebDriver locator decorator handler" :)

Alex


Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages