Extending @FindBy

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Extending @FindBy

Paul Hammant-3
I'm maintaining locators in Java for Angular in the ngWebDriver project (yes yes, it's just a wrapper for Protractor from the Angular team).

I'm wanting to make new page-object style annotations for it.  NgWebDriver like Protractor is going to the client via the JavascriptExecutor and interoperating with the inner workings of Angular in order to do things. That manifests itself as another series of things like By.id(..). Those would be ByAngular.model(..), ByAngular.repeater(..) and more.

The annotation @FindBy is fixed. Sure, I'd want a new @AngularFindBy. So, looking at Annotations.buildBy(..) I don't think it is open for alternates.

I'm pretty sure there is a backwards-compatible way of changing WebDriver to allow for new @FindBy inspired annotations via parent annotations:

    public @interface FindBy extends PageObjectAnnotation {...}

The logic in Annotations.buildBy(..) would change to looking PageObjectAnnotation and calling methods within that.

Thoughts?

- Paul

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/01b88876-b5ec-4d1a-bb46-b4973000b143%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Extending @FindBy

Krishnan Mahadevan
Paul,

Sometime back I created a blog post that talks about how to make use of the PageFactory and the PageObjects concept and work with external locators while still leveraging what the PageFactory provides as an infrastructure/base.


Please see if this is something that can be leveraged by you as a concept and get this done on your own in your project.

In short you would need a customized version of 
  • Sub-class of org.openqa.selenium.support.pagefactory.Annotations (For providing support to your new annotations viz., @AngularFindBy, wherein it would first invoke Annotations.buildBy() within a try..catch() block, gobbling all exceptions and if buildBy() returned null, then it would basically start parsing the annotation assuming it to be your @AngularFindBy variant.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Sat, Mar 4, 2017 at 3:55 PM, Paul Hammant <[hidden email]> wrote:
I'm maintaining locators in Java for Angular in the ngWebDriver project (yes yes, it's just a wrapper for Protractor from the Angular team).

I'm wanting to make new page-object style annotations for it.  NgWebDriver like Protractor is going to the client via the JavascriptExecutor and interoperating with the inner workings of Angular in order to do things. That manifests itself as another series of things like By.id(..). Those would be ByAngular.model(..), ByAngular.repeater(..) and more.

The annotation @FindBy is fixed. Sure, I'd want a new @AngularFindBy. So, looking at Annotations.buildBy(..) I don't think it is open for alternates.

I'm pretty sure there is a backwards-compatible way of changing WebDriver to allow for new @FindBy inspired annotations via parent annotations:

    public @interface FindBy extends PageObjectAnnotation {...}

The logic in Annotations.buildBy(..) would change to looking PageObjectAnnotation and calling methods within that.

Thoughts?

- Paul

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/01b88876-b5ec-4d1a-bb46-b4973000b143%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/CANikZL%3DDj7qOFo8eOvfCxzujPmCaPuC7AKpn9AHq3uZXOWExmQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Extending @FindBy

Paul Hammant-3
Good to know, Krishnan, thanks.

On Sat, Mar 4, 2017 at 9:59 AM, ⇜Krishnan Mahadevan⇝ <[hidden email]> wrote:
Paul,

Sometime back I created a blog post that talks about how to make use of the PageFactory and the PageObjects concept and work with external locators while still leveraging what the PageFactory provides as an infrastructure/base.


Please see if this is something that can be leveraged by you as a concept and get this done on your own in your project.

In short you would need a customized version of 
  • Sub-class of org.openqa.selenium.support.pagefactory.Annotations (For providing support to your new annotations viz., @AngularFindBy, wherein it would first invoke Annotations.buildBy() within a try..catch() block, gobbling all exceptions and if buildBy() returned null, then it would basically start parsing the annotation assuming it to be your @AngularFindBy variant.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Sat, Mar 4, 2017 at 3:55 PM, Paul Hammant <[hidden email]> wrote:
I'm maintaining locators in Java for Angular in the ngWebDriver project (yes yes, it's just a wrapper for Protractor from the Angular team).

I'm wanting to make new page-object style annotations for it.  NgWebDriver like Protractor is going to the client via the JavascriptExecutor and interoperating with the inner workings of Angular in order to do things. That manifests itself as another series of things like By.id(..). Those would be ByAngular.model(..), ByAngular.repeater(..) and more.

The annotation @FindBy is fixed. Sure, I'd want a new @AngularFindBy. So, looking at Annotations.buildBy(..) I don't think it is open for alternates.

I'm pretty sure there is a backwards-compatible way of changing WebDriver to allow for new @FindBy inspired annotations via parent annotations:

    public @interface FindBy extends PageObjectAnnotation {...}

The logic in Annotations.buildBy(..) would change to looking PageObjectAnnotation and calling methods within that.

Thoughts?

- Paul

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/01b88876-b5ec-4d1a-bb46-b4973000b143%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/CANikZL%3DDj7qOFo8eOvfCxzujPmCaPuC7AKpn9AHq3uZXOWExmQ%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/CA%2B298UhPrHmw6ypLiLCR1crciSy5xB0bDgxbbrdOqSmFjB3b6g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Extending @FindBy

Simon Stewart
In reply to this post by Paul Hammant-3
Hi Paul,

What are you trying to do? Get the same behaviour as the Annotations class? That code is trivial to write, especially for someone of your experience. Don't try and extend it --- ignore it and do something appropriate for your particular testing domain.

For a bit of history, the support package started off as a set of examples of how you might want to use WebDriver as a building block for more sophisticated tooling. Naively, I never thought people would actually use the APIs as anything other than inspiration. It's my own fault for not really considering the audience of the code. I think that attitude started to change with the Wait class in 2009 once I understood what was happening, but PageFactory dates to 2007. If you'd like to refactor the heck out of and keep the public-facing APIs pin-compatible, go for it.

Simon 


On Sat, Mar 4, 2017 at 10:25 AM, Paul Hammant <[hidden email]> wrote:
I'm maintaining locators in Java for Angular in the ngWebDriver project (yes yes, it's just a wrapper for Protractor from the Angular team).

I'm wanting to make new page-object style annotations for it.  NgWebDriver like Protractor is going to the client via the JavascriptExecutor and interoperating with the inner workings of Angular in order to do things. That manifests itself as another series of things like By.id(..). Those would be ByAngular.model(..), ByAngular.repeater(..) and more.

The annotation @FindBy is fixed. Sure, I'd want a new @AngularFindBy. So, looking at Annotations.buildBy(..) I don't think it is open for alternates.

I'm pretty sure there is a backwards-compatible way of changing WebDriver to allow for new @FindBy inspired annotations via parent annotations:

    public @interface FindBy extends PageObjectAnnotation {...}

The logic in Annotations.buildBy(..) would change to looking PageObjectAnnotation and calling methods within that.

Thoughts?

- Paul

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/01b88876-b5ec-4d1a-bb46-b4973000b143%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/CAOrAhYF%3Dp22jwhwhbVa91XsyQTLz4Frfpcu7_PA5wcCpRiie-A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Extending @FindBy

Paul Hammant-3
Hi Simon,

You're saying that rather than rework things to get PageFactory.initElements(driver, objectThatCouldHaveMoreGeneralFindBys), I should consider AngularPageFactory.initElements(driver, objectThatHasAngularFindBys), and in some cases, end users would call both PageFactory.initElements(..) and AngularPageFactory.initElements(..)

And you're right, I don't really use the PageFactory stuff myself. I try to facilitate other peoples use cases, though.

- Paul

On Mon, Mar 6, 2017 at 3:50 AM, Simon Stewart <[hidden email]> wrote:
Hi Paul,

What are you trying to do? Get the same behaviour as the Annotations class? That code is trivial to write, especially for someone of your experience. Don't try and extend it --- ignore it and do something appropriate for your particular testing domain.

For a bit of history, the support package started off as a set of examples of how you might want to use WebDriver as a building block for more sophisticated tooling. Naively, I never thought people would actually use the APIs as anything other than inspiration. It's my own fault for not really considering the audience of the code. I think that attitude started to change with the Wait class in 2009 once I understood what was happening, but PageFactory dates to 2007. If you'd like to refactor the heck out of and keep the public-facing APIs pin-compatible, go for it.

Simon 


On Sat, Mar 4, 2017 at 10:25 AM, Paul Hammant <[hidden email]> wrote:
I'm maintaining locators in Java for Angular in the ngWebDriver project (yes yes, it's just a wrapper for Protractor from the Angular team).

I'm wanting to make new page-object style annotations for it.  NgWebDriver like Protractor is going to the client via the JavascriptExecutor and interoperating with the inner workings of Angular in order to do things. That manifests itself as another series of things like By.id(..). Those would be ByAngular.model(..), ByAngular.repeater(..) and more.

The annotation @FindBy is fixed. Sure, I'd want a new @AngularFindBy. So, looking at Annotations.buildBy(..) I don't think it is open for alternates.

I'm pretty sure there is a backwards-compatible way of changing WebDriver to allow for new @FindBy inspired annotations via parent annotations:

    public @interface FindBy extends PageObjectAnnotation {...}

The logic in Annotations.buildBy(..) would change to looking PageObjectAnnotation and calling methods within that.

Thoughts?

- Paul

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/01b88876-b5ec-4d1a-bb46-b4973000b143%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/CAOrAhYF%3Dp22jwhwhbVa91XsyQTLz4Frfpcu7_PA5wcCpRiie-A%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/CA%2B298UiY012M3ojfMFXbbrwKbu4A8C45AJH8nDY6iBKZq%3D%3DfXQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Extending @FindBy

Simon Stewart
I was suggesting writing your own class that folks should use all the time instead of PageFactory (you can delegate to pieces of it if you felt like it, just as Krishnan suggested)

If we were smart, you'd be able to register locator strategies that look for particular annotations/field types/whatever and apply the first matching one to that. Obviously, the old code shows that I wasn't thinking like that at the time :)

Simon

On Mon, Mar 6, 2017 at 10:13 AM, Paul Hammant <[hidden email]> wrote:
Hi Simon,

You're saying that rather than rework things to get PageFactory.initElements(driver, objectThatCouldHaveMoreGeneralFindBys), I should consider AngularPageFactory.initElements(driver, objectThatHasAngularFindBys), and in some cases, end users would call both PageFactory.initElements(..) and AngularPageFactory.initElements(..)

And you're right, I don't really use the PageFactory stuff myself. I try to facilitate other peoples use cases, though.

- Paul

On Mon, Mar 6, 2017 at 3:50 AM, Simon Stewart <[hidden email]> wrote:
Hi Paul,

What are you trying to do? Get the same behaviour as the Annotations class? That code is trivial to write, especially for someone of your experience. Don't try and extend it --- ignore it and do something appropriate for your particular testing domain.

For a bit of history, the support package started off as a set of examples of how you might want to use WebDriver as a building block for more sophisticated tooling. Naively, I never thought people would actually use the APIs as anything other than inspiration. It's my own fault for not really considering the audience of the code. I think that attitude started to change with the Wait class in 2009 once I understood what was happening, but PageFactory dates to 2007. If you'd like to refactor the heck out of and keep the public-facing APIs pin-compatible, go for it.

Simon 


On Sat, Mar 4, 2017 at 10:25 AM, Paul Hammant <[hidden email]> wrote:
I'm maintaining locators in Java for Angular in the ngWebDriver project (yes yes, it's just a wrapper for Protractor from the Angular team).

I'm wanting to make new page-object style annotations for it.  NgWebDriver like Protractor is going to the client via the JavascriptExecutor and interoperating with the inner workings of Angular in order to do things. That manifests itself as another series of things like By.id(..). Those would be ByAngular.model(..), ByAngular.repeater(..) and more.

The annotation @FindBy is fixed. Sure, I'd want a new @AngularFindBy. So, looking at Annotations.buildBy(..) I don't think it is open for alternates.

I'm pretty sure there is a backwards-compatible way of changing WebDriver to allow for new @FindBy inspired annotations via parent annotations:

    public @interface FindBy extends PageObjectAnnotation {...}

The logic in Annotations.buildBy(..) would change to looking PageObjectAnnotation and calling methods within that.

Thoughts?

- Paul

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/01b88876-b5ec-4d1a-bb46-b4973000b143%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/CAOrAhYF%3Dp22jwhwhbVa91XsyQTLz4Frfpcu7_PA5wcCpRiie-A%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/CA%2B298UiY012M3ojfMFXbbrwKbu4A8C45AJH8nDY6iBKZq%3D%3DfXQ%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/CAOrAhYHiUkNm0VxvYBuvZeTFmEwXs5BXgp9Msb7OAes3Lj0aVQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Extending @FindBy

Paul Hammant-3

- Paul

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/CA%2B298UiZBtvj%3DXvhOgaXRTyRwhRabDgAx0fhP1-DNpioDvVpqQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Extending @FindBy

Serguei Kouzmine
In reply to this post by Paul Hammant-3
Hello Paul

Does https://github.com/henrrich/jpagefactory accomlish what you intend ?
 

Thanks,

Serguei Kouzmine

On Saturday, March 4, 2017 at 5:25:57 AM UTC-5, Paul Hammant wrote:
I'm maintaining locators in Java for Angular in the ngWebDriver project (yes yes, it's just a wrapper for Protractor from the Angular team).

I'm wanting to make new page-object style annotations for it.  NgWebDriver like Protractor is going to the client via the JavascriptExecutor and interoperating with the inner workings of Angular in order to do things. That manifests itself as another series of things like By.id(..). Those would be ByAngular.model(..), ByAngular.repeater(..) and more.

The annotation @FindBy is fixed. Sure, I'd want a new @AngularFindBy. So, looking at Annotations.buildBy(..) I don't think it is open for alternates.

I'm pretty sure there is a backwards-compatible way of changing WebDriver to allow for new @FindBy inspired annotations via parent annotations:

    public @interface FindBy extends PageObjectAnnotation {...}

The logic in Annotations.buildBy(..) would change to looking PageObjectAnnotation and calling methods within that.

Thoughts?

- Paul

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/27c9478d-170e-4fda-ad18-df131fed07cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Extending @FindBy

Paul Hammant-3
It could do, and I was unaware of that, but I've coded a solution within Selenium - https://github.com/SeleniumHQ/selenium/pull/3680

On Fri, Apr 21, 2017 at 12:21 AM, Serguei Kouzmine <[hidden email]> wrote:
Hello Paul

Does https://github.com/henrrich/jpagefactory accomlish what you intend ?
 

Thanks,

Serguei Kouzmine

On Saturday, March 4, 2017 at 5:25:57 AM UTC-5, Paul Hammant wrote:
I'm maintaining locators in Java for Angular in the ngWebDriver project (yes yes, it's just a wrapper for Protractor from the Angular team).

I'm wanting to make new page-object style annotations for it.  NgWebDriver like Protractor is going to the client via the JavascriptExecutor and interoperating with the inner workings of Angular in order to do things. That manifests itself as another series of things like By.id(..). Those would be ByAngular.model(..), ByAngular.repeater(..) and more.

The annotation @FindBy is fixed. Sure, I'd want a new @AngularFindBy. So, looking at Annotations.buildBy(..) I don't think it is open for alternates.

I'm pretty sure there is a backwards-compatible way of changing WebDriver to allow for new @FindBy inspired annotations via parent annotations:

    public @interface FindBy extends PageObjectAnnotation {...}

The logic in Annotations.buildBy(..) would change to looking PageObjectAnnotation and calling methods within that.

Thoughts?

- Paul

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/27c9478d-170e-4fda-ad18-df131fed07cf%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/CA%2B298Ug%3DawBGg8WhO9mOLpFjCV8-QnL8a9rV8jGK6Qcc%3DPdbjA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...