sensiolabs / BehatPageObjectExtension

MIT License
117 stars 48 forks source link

Decouple PageObjects from Behat Implementation? #61

Open ghost opened 8 years ago

ghost commented 8 years ago

Hi there,

I have been thinking of using the page object pattern in a way to share the Objects with Symfony Webtestcases and found that the entire SensioLabs\Behat\PageObjectExtension\PageObject namespace could become an own library, making it possible to build Pageobjects for an application reusable among different test suites.

Technically it is already possible to use the PageObject Namespace in any context, however putting them in their own lib would be cleaner and not needed, Behat specific classes are not included in the project.

What do you think?

jakzal commented 8 years ago

I actually have done this partly few months ago. I just haven't finished nor published it.

I'm pretty busy till SymfonyCon. I'll be catching up with my open source stuff in December :)

ghost commented 8 years ago

Awesome, looking forward to it :)

jakzal commented 8 years ago

I'm not sure if you'll be able to use it Symfony test cases easily yet as currently page objects are heavily based on Mink. It might be the next step though. I'll give it a thought.

ghost commented 8 years ago

There is a Browserkit driver for mink https://github.com/minkphp/MinkBrowserKitDriver

A Symfony specific implementation could be created as well, in order to configure the factory and if needed extend the WebTestCase analog to the Behat PageObjectAware contexts

ghost commented 8 years ago

As I see it, the building blocks are there, we only need to put them together and extract the PageObjects from this repo :)

ghost commented 8 years ago

Here is an approach to integrate the POP into Symfony WebTestCase. This is by no means a final approach, just a demo.

https://github.com/mozzymoz/e2eTests/tree/master/src/E2eTests/PopBundle

DonCallisto commented 6 years ago

Yes, that's interesting even for "non-test" scenarios: I would like to scrape a site for a service on which there's any rest API or WS in general. I can use Mink, Symfony and this extension to obtain what I need but, sadly, this extension is too bounded to Behat and this would not be suitable for a Symfony Bundle.

@jakzal any thoughts?

jakzal commented 6 years ago

@DonCallisto I did some work which I haven't released in the end. I tried to make this in a real BC way, but since breaking changes in Mink (see #92), perhaps it's time to take this opportunity to rethink the design and come up with something new.

Page objects currently extend Mink elements, which was a cautious decision. The extensions initial focus group was testers with only basic coding experience. I don't think this is our user base at the moment.

One thing that's been in my head for quite some time is removing necessity to extend Mink elements, but provide tools to inject them directly into page object properties. We'd describe how to query elements with annotations:

class SearchPage
{
    /**
     * @FindBy(name="search_box")
     */
    private $searchInput;

    /**
     * @FindBy(id="search")
     */
    private $submit;

    /**
     * @FindBy(css=".container .message")
     */
    private $message;

    /**
     * @FindBy(xpath="//div//h1")
     */
    private $title;
}

We could start fresh by implementing this approach as a library, and then integrate it with Behat in this extension in a next major version.

DonCallisto commented 6 years ago

@jakzal

Cool: only thing that "worry" me is about "collections", so dynamic selectors or something like this. Of course we can put placeholders and so on, of course, but I suppose it could require a studying phase before try this.

If you want, I'm in for doing some work with you.

Just let me know when and how 😄