sensiolabs / BehatPageObjectExtension

MIT License
116 stars 48 forks source link

Fatal error: Call to a member function createPage() on null (Behat\Testwork\Call\Exception\FatalThrowableError) #109

Closed bartonhammond closed 6 years ago

bartonhammond commented 6 years ago

My Context:

    /**
     * @When I go to the :arg1 page
     */
    public function iGoToThePage($arg1) {
        $this->currentPage = $this->getPage($arg1);
        assertTrue($this->currentPage->verifyPage());
    }

The Feature

   When I go to the "Home Page" page  

behat.yml

default:
  suites:
    home:
      paths:
         - "%paths.base%/features/home.feature"
      page:
        - ["%paths.base%/features/bootstrap/page-objects/page"]
      contexts:
        - HomeContext

My HomePage in features/bootstrap/page-objects/page/HomePage.php

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

When I run vendor/bin/behat --config behat.yml --colors --tags wip

~/projects/uwce/www (develop)$ vendor/bin/behat --config behat.yml --colors --tags wip
Feature: HomePage
  In order to navigate all the campuses
  As a visitor
  I want to access any campus

  Background

  @javascript @wip
  Scenario: I can login to my campus                     # features/home.feature:48
    Given I am a visitor                                 # HomeContext::iAmAVisitor()
    When I go to the "Home Page" page                    # HomeContext::iGoToThePage()
      Fatal error: Call to a member function createPage() on null (Behat\Testwork\Call\Exception\FatalThrowableError)
    And I click the "UW-Fond du Lac (Staging)" link      # HomeContext::iClickTheLink()
jakzal commented 6 years ago

Is the extension enabled?

bartonhammond commented 6 years ago

I did not do that...so I added the following to behat.yml

    SensioLabs\Behat\PageObjectExtension:
      namespaces:
        page: ["%paths.base%/features/bootstrap/page-objects/page"]

Same error:

 When I go to the "Home Page" page                    # HomeContext::iGoToThePage()
      Fatal error: Call to a member function createPage() on null (Behat\Testwork\Call\Exception\FatalThrowableError)
jakzal commented 6 years ago

@bartonhammond would you mind to put a simple project to github so i could reproduce? I think your problems are caused by misconfiguration, but I could use this opportunity to improve usability by providing better exception messages.

bartonhammond commented 6 years ago

@jakzal will do. thanks for the suggestion.

bartonhammond commented 6 years ago

@jakzal see https://github.com/bartonhammond/behatExampleProject

bartonhammond commented 6 years ago

I figured it out.
1) I was not extending my Context SensioLabs\Behat\PageObjectExtension\Context\PageObjectContext

2) Changed behat.yml by only adding this line: SensioLabs\Behat\PageObjectExtension: ~. Before I tried to define the path to the page.

jakzal commented 6 years ago

@bartonhammond that's great, I'm glad you fixed it!