sensiolabs / BehatPageObjectExtension

MIT License
117 stars 48 forks source link

User Notice: Undefined property: Page\HomePage::$factory #107

Closed bartonhammond closed 6 years ago

bartonhammond commented 6 years ago

The entire error message:

 User Notice: Undefined property: Page\HomePage::$factory in vendor/sensiolabs/behat-page-object-extension/src/SensioLabs/Behat/PageObjectExtension/PageObject/Page.php on line 132 in /private/var/folders/8w/4f5rtpzx61dcskp4ysvp18fr0000gn/T/ProxyManagerGeneratedProxy__PM__PageHomePageGenerateddf1a4d12fa9461ec568e547ef31a67a0.php line 446

My behat.yml is

default:
  suites:
    features:
      paths:
         - "%paths.base%/features/"
      contexts:
        - HomeContext
  extensions:
    Behat\MinkExtension:
      browser_name: 'chrome'
      goutte: ~
      javascript_session: selenium2
      selenium2:
        wd_host: http://0.0.0.0:4444/wd/hub
        capabilities: { "browser": "chrome", "version": "", 'chrome': {'switches':['--start-maximized']}}
      base_url: https://www.twlw.dev
    SensioLabs\Behat\PageObjectExtension: ~
    LeanPHP\Behat\CodeCoverage\Extension:
      auth:       ~
      drivers:
        - local
      filter: 
        whitelist:
          include:
            directories:
              'src':
                prefix: 'src'
              'tests':
                prefix: 'src'      
      report:
        format:   html
        options:
          target: coverage/behat

My HomeContext is

<?php
require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/../../vendor/phpunit/phpunit/src/Framework/Assert/Functions.php';
require_once __DIR__ . '/../../src/page-objects/page/HomePage.php';

use Behat\Behat\Context\Context;
use Page\HomePage;
use Page\ContactPage;
use Page\ContactConfirmation;
use SensioLabs\Behat\PageObjectExtension\PageObject\Page;

class HomeContext extends FeatureContext {
    protected $homepage;

    public function __construct(HomePage $homepage) {
        $this->homepage = $homepage;
    }
    /**
     * @When I go to the :arg1 page
     */
    public function iGoToThePage($arg1) {
        if ($arg1 === 'home') {
            $this->homepage->open();            
            assertTrue($this->homepage->verifyPage());
        }        
    }
    /**
     * @Then I should see :arg1 link
     */
    public function iShouldSeeLink($arg1)
    {
        //\Psy\Shell::debug(get_defined_vars(),$this);
        assertNotNull($this->homepage->hasElement($arg1));
    }
}

My FeatureContext:

<?php
require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/../../vendor/phpunit/phpunit/src/Framework/Assert/Functions.php';
require_once __DIR__ . '/../../src/page-objects/page/HomePage.php';

use Behat\Behat\Context\Context;
use Page\HomePage;
use Page\ContactPage;
use Page\ContactConfirmation;
use SensioLabs\Behat\PageObjectExtension\PageObject\Page;

class FeatureContext extends Page implements Context, \Behat\Behat\Context\SnippetAcceptingContext
{

    /**
     * @param Session $session
     * @param Factory $factory
     * @param array   $parameters
     */
    public function __construct(Session $session, Factory $factory, array $parameters = array())
    {
        parent::__construct($session, $factory, $parameters);
    }

    /**  @BeforeScenario   */
    public function before( $scope)  {
        $this->driver = new \Behat\Mink\Driver\Selenium2Driver('chrome');
        $this->session = new \Behat\Mink\Session($this->driver);
        $this->session->start();

    }
    /**   @AfterScenario  */
    public function after($scope)
    {
        $this->session->stop();
    }
    /**
     * @Given I am a visitor
     */
    public function iAmAVisitor()
    {
        return true;
    }

}

My HomePage:

<?php
namespace Page;
use SensioLabs\Behat\PageObjectExtension\PageObject\Page;
class HomePage extends Page {
    protected $path='/';

    protected $elements = array(
          'My Account' => 
        [
            'xpath' => '//a[contains(text(),"My Account")]'
        ],
        'Dashboard' => 
        [
            'xpath' => '//a[contains(text(),"Dashboard")]'
        ],
        'Log out' => 
        [
            'xpath' => '//a[contains(text(),"Log out")]'
        ]
    );

    public function verifyPage() {
        return ($this->getDriver()->getCurrentUrl()
                ===
                $this->getParameter('base_url')
                . $this->path);
    }
}
jakzal commented 6 years ago

Why does your FeatureContext extend the Page?

bartonhammond commented 6 years ago

Hi @jakzal - It wasn't yesterday and I fixed it last night. It's working now. Thanks.