MinkContext 未加载和使用

问题描述 投票:0回答:1

当我从 behat/bin 运行 behat 会话时,它显示仅使用在 FeatureContext 中定义的步骤。当我尝试 beta -dl 时,这一点得到了证实。我的 MinkContext 显然没有加载,因此无法使用。这些是我的composer.json、behat.yml 和FeatureContext 文件

Composer json
=================

{
    "require-dev": {
        "behat/behat": "~3.0.13",
        "behat/mink": "~1.6.0",
        "behat/mink-extension": "~2.0.0",
        "behat/mink-goutte-driver": "~1.1.0",
        "behat/mink-selenium2-driver": "*",
        "peridot-php/webdriver-manager": "dev-master",
        "bossa/phpspec2-expect": "1.*"
    },
    "config": {
        "bin-dir": "bin"

    }
}
behat.yml
=====================
    default:
    autoload: [ %paths.base%/contexts ]
    extensions:
        Behat\MinkExtension\Extension:
            base_url: http://www.google.com
            sessions:
                default:
                    selenium2: ~
        Sanpi\Behatch\Extension: ~
    suites:
        default:
            paths:    [ %paths.base%/features ]
            filters:
            contexts:
                - FeatureContext
                - Drupal\DrupalExtension\Context\DrupalContext
                - Drupal\DrupalExtension\Context\MinkContext
                - Drupal\DrupalExtension\Context\MessageContext
                - Drupal\DrupalExtension\Context\DrushContext
                - Behat\MinkExtension\Context\MinkContext


FeatureContext.php
====================
<?php

use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkContext;
use Behat\MinkExtension\Context\RawMinkContext;

use Drupal\DrupalExtension\Context\RawDrupalContext;
use Behat\Mink\Mink,
Behat\Mink\Session,
Behat\Mink\Selenium2Driver;


/**
 * Defines application features from the specific context.
 */
class FeatureContext extends RawMinkContext implements SnippetAcceptingContext
{
    public $mink;
    public $driver;
    public $session;
    private $contactName;
    private $nodeId;

    /**
     * Initializes context.
     *
     * Every scenario gets its own context instance.
     * You can also pass arbitrary arguments to the
     * context constructor through behat.yml.
     */
    public function __construct()
    {
        // $this->driver = new \Behat\Mink\Driver\Selenium2Driver();
        // $this->getSession() = new \Behat\Mink\getSession()($this->driver);
        // $this->getSession()->start();
    }

        /**
         * Opens homepage.
         *
         * @Given /^(?:|I )am on (?:|the )homepage$/
         * @When /^(?:|I )go to (?:|the )homepage$/
         */
        public function iAmOnHomepage()
        {
            $this->visitPath('/');
        }
    /**
     * @param string $name
     *   An iframe name (null for switching back).
     *
     * @Given /^(?:|I )switch to an iframe "([^"]*)"$/
     * @Then /^(?:|I )switch back from an iframe$/
     */
    public function iSwitchToAnIframe($name = NULL)
    {
        $this->getSession()->switchToIFrame($name);
    }

    /**
     * @Given /^I set browser window size to "([^"]*)" x "([^"]*)"$/
     */
    public function iSetBrowserWindowSizeToX($width, $height)
    {
        $this->getSession()->resizeWindow((int)$width, (int)$height, 'current');
    }

    /**
     * @Given I click the element :arg1
     */
    public function iClickTheElement($selector)
    {
        $page = $this->getSession()->getPage();
        $element = $page->find('css', $selector);

        if (empty($element)) {
            throw new Exception("No html element found for the selector ('$selector')");
        }

        $element->click();
    }
    //
    /**
     * @When /^wait (\d+) seconds?$/
     */
    public function waitSeconds($seconds)
    {
        $this->getSession()->wait(1000 * $seconds);
    }

    /**
     * @Given /^I remember the name in "([^"]*)"$/
     */
    public function iRememberTheNameIn($selector)
    {
        $element = $this->assertgetSession()->elementExists('css', $selector);
        $this->contactName = $element->getText();
    }

    /**
     * @Then /^element "([^"]*)" should contain the name I remembered$/
     */
    public function elementShouldContainTheNameIRemembered($selector)
    {
        $element = $this->assertgetSession()->elementExists('css', $selector);
        $contactName = $element->getText();
        if ($contactName != $this->contactName) {
            throw new Exception("The contact name '$contactName' is not equal to the original name '$this->contactName'");
        }
    }

    /**
     * @Given /^I set the value "([^"]*)" for the cookie "([^"]*)"$/
     */
    public function iSetTheValueForTheCookie($value, $cookie)
    {
        $this->getSession()->setCookie($cookie, $value);
    }

    /**
     * @Given /^My "([^"]*)" content:$/
     */
    public function myContent($type, TableNode $nodesTable)
    {
        $saved = false;
        foreach ($nodesTable->getHash() as $nodeHash) {
            $node = (object)$nodeHash;
            $node->type = $type;
            $saved = $this->nodeCreate($node);
        }
        if ($saved) {
            $this->nodeId = $saved->nid;
        }
    }

    /**
     * @Given /^I fill in the input field "(?P<field>(?:[^"]|\\")*)" with the last nid$/
     */
    public function iFillInTheInputFieldWithTheLastNid($field)
    {
        $value = 'node/' . $this->nodeId;
        $field = $this->fixStepArgument($field);
        $value = $this->fixStepArgument($value);
        $this->getSession()->getPage()->fillField($field, $value);
    }

     /**
     * Returns fixed step argument (with \\" replaced back to ")
     *
     * @param string $argument
     *
     * @return string
     */
    protected function fixStepArgument($argument)
    {
      return str_replace('\\"', '"', $argument);
    }

    /**
     * @Given /^I place an image in my local file system$/
     */
    public function iPlaceAnImageInMyLocalFileSystem() {
      $url = 'https://www.portofrotterdam.com/sites/all/themes/custom/portofrotterdam/favicon-128.png';
      $img = '/tmp/testimage.png';
      file_put_contents($img, file_get_contents($url));
    }

    /**
     * @Given /^I cleanup database table entries for the subsite test$/
     * @Given /^I cleanup database table entries for the downloads test$/
     */
    public function iCleanupDatabaseTableEntriesForTheSubsiteTest() {
      db_query("DELETE FROM {filehash} WHERE md5 = 'bb7c2beef51b3be866a18292aa46a084'");
      db_query("DELETE FROM {file_managed} WHERE filename = 'testimage.png'");
    }


}
php behat mink
1个回答
2
投票

MinkExtension 已更改其命名空间。而不是

Behat\MinkExtension\Extension
尝试使用
Behat\MinkExtension

    default:
    autoload: [ %paths.base%/contexts ]
    extensions:
        Behat\MinkExtension:
            base_url: http://www.google.com
            sessions:
                default:
                selenium2: ~
        Sanpi\Behatch\Extension: ~
© www.soinside.com 2019 - 2024. All rights reserved.