致命错误:在非对象上调用成员函数press()

时间:2017-03-20 18:18:09

标签: php behat mink

我打算用symfony中的behat做一个测试添加文章,但我应该这个错误:

enter image description here

这是AjouterContext.php:

<?php

namespace test\MedBundle\Behat\Context;

use Behat\Behat\Context\Context;
use Behat\Behat\Context\BehatContext;
use Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkContext;
use test\MedBundle\Entity\Apps;
use test\MedBundle\Entity\Product;

/**
 * Defines application features from the specific context.
 */
class AjouterContext extends MinkContext
{

     /**
     * @When I press on :arg1
     */
    public function iPressOn($arg1)
    {
            $element = $this->getSession()->getPage()->findById($arg1);
            if (null === $element) {
                var_dump('error');
            }
            $element->press();

    }

    /*
    public function iClickOn2($arg1)
    {

    }  */

     /**
     * @Then I wait :arg1 seconds
     */
    public function iWaitSeconds($arg1)
    {
        $this->getSession()->wait($arg1 * 1000);
    }

这是ajouter.feature:

Feature: dossiertest

@javascript

Scenario: List 2 files in a directory

  Given I am on the homepage
  Then I should see "hello"
  When I go to "/ajoutermed"
  Then I should see "ajouter"
  And I wait 2 seconds
  And I fill in "test_medbundle_med_section" with "test section"
  And I fill in "test_medbundle_med_info" with "test info"
  And I press on "test_medbundle_med_submit"
  Then I should see "ajouter"

这是behat.yml:

default:
    suites:
        default:
            bundle: MedBundle
            contexts:
                - test\MedBundle\Behat\Context\FeatureContext
                - test\MedBundle\Behat\Context\AjouterContext
    extensions:
        Behat\Symfony2Extension: ~
        Behat\MinkExtension:
            base_url: http://localhost/test/web/app_dev.php
            goutte: ~
            javascript_session: selenium2
            selenium2:
                wd_host: http://localhost:4444/wd/hub
            sessions:
                default:
                    symfony2: ~      

帮助我,谢谢你

0 个答案:

没有答案