sensiolabs / BehatPageObjectExtension

MIT License
116 stars 48 forks source link

PageObjectAware interface must not be deprecated #71

Closed spolischook closed 8 years ago

spolischook commented 8 years ago

In our application we have many bundles. Each of bundle can have own Pages (suppose 3 page for every entity that have CRUD). We develop Common context that can interact with any page:

class FeatureContext extends MinkContext implements Context, SnippetAcceptingContext, PageObjectAware
{
    /** @var  SensioLabs\Behat\PageObjectExtension\PageObject\Factory */
    protected $pageObjectFactory;

    /** @var  \SensioLabs\Behat\PageObjectExtension\PageObject\Page */
    protected $currentPage;

    public function setPageObjectFactory(PageObjectFactory $pageObjectFactory)
    {
        $this->pageObjectFactory = $pageObjectFactory;
    }

    /**
     * @Given /^(?:|I )open (?:|the )"(?P<pageName>.*?)" page$/
     * @Given /^(?:|I )visited (?:|the )"(?P<pageName>.*?)"$/
     */
    public function iOpenPage($pageName)
    {
        $this->currentPage = $this->pageObjectFactory->createPage($pageName);
        $this->currentPage->open();
    }
}

So we strongly needed PageObjectAware interface. Page constructor injection it's great feature, but it is not necessary to oppose - we need both approach for retrieve page objects in context.

jakzal commented 8 years ago

The interface was deprecated as I think it's better to have one way of doing things. However, I can see how the factory can be useful and I'll probably remove the deprecation as 2.0 wasn't released yet.

@spolischook is this the only case where you find the factory useful?

spolischook commented 8 years ago

@jakzal this is the only way that we can interact with all pages in one context - it's perfect case because inject more then 100 pages in constructor is weird.

tikolakin commented 8 years ago

100 pages in constructor is weird.

Or context can be organized in a better way to avoid to many parameter.

spolischook commented 8 years ago

@tikolakin It's ok if you have isolate your context in that layer. Ok, let say that, the main disadvantage of DI way with injecting pages in context it's context by itself. I need to create context that can be extended by MinkContext even if it will be empty. Is it ok?

spolischook commented 8 years ago

any suggestions?

jakzal commented 8 years ago

@spolischook never extend the MinkContext. You can only do it once as otherwise you'll be duplicating step definitions (Behat won't let you). Use the RawMinkContext or MinkAwareContext.

jakzal commented 8 years ago

I'll bring back the PageObjectAware before the stable release.

old-town commented 8 years ago

Sorry to interrupt, but when exactly are you going to revert the deprecation? The problem is that we also use your library but can not adopt it to its full extent because of PageObjectAware being deprecated. Thanks in advance.

jakzal commented 8 years ago

@old-town @spolischook I'd appreciate if you tested the latest dev-master with your apps. Cheers!

spolischook commented 8 years ago

@jakzal we decide use own implementation of ElementFactory. But I still sure that factory is needed, I use it in elements for getting other elements