Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to configure behat tests properly with behat 3 and drupalextension 3.1 #255

Closed
mradcliffe opened this issue Feb 29, 2016 · 2 comments
Closed

Comments

@mradcliffe
Copy link

I must be missing something obvious as I have not been able to find any information regarding not recognizing any step definitions when running behat despite seeing all of DrupalExtension's step definitions with behat -dl. :(

Is there somewhere else that I can look? Some configuration option I am missing that's not in the docs? Some behat/mink/whatever library I am missing? Missing namespaces? Autoload problems? I have no idea what to do next other than re-write everything myself which seems like the worst option.

I've tried running this within a vagrant virtual machine or outside of one, but I get the same result with behat:

./vendor/bin/behat
Feature: Anonymous Users

  Scenario: User visits front page     # features/platform/anonymous.feature:3
    Given I am not logged in
    When I visit "/"
    Then I should see a "name" element
    And I should see a "pass" element

1 scenario (1 undefined)
4 steps (4 undefined)
0m0.09s (12.32Mb)

--- FeatureContext has missing steps. Define them with these snippets:

    /**
     * @Given I am not logged in
     */
    public function iAmNotLoggedIn()
    {
        throw new PendingException();
    }

    /**
     * @When I visit :arg1
     */
    public function iVisit($arg1)
    {
        throw new PendingException();
    }

    /**
     * @Then I should see a :arg1 element
     */
    public function iShouldSeeAElement($arg1)
    {
        throw new PendingException();
    }
./vendor/bin/behat -dl | grep "I am not logged in"
default | Given I am not logged in

behat.yml

default:
  suites:
    default:
      contexts:
        - FeatureContext
        - Drupal\DrupalExtension\Context\DrupalContext
        - Drupal\DrupalExtension\Context\MinkContext
      filters:
        tags: "@blackbox"
    extensions:
      Behat\MinkExtension:
        goutte: ~
        base_url: 'https://local.my.site.com'
      Drupal\DrupalExtension:
        api_driver: 'drupal'
        blackbox: ~
        drupal:
          drupal_root: '/var/www/my.site.com/webroot'

features/platform/anonymous.feature

Feature: Anonymous Users

  Scenario: User visits front page
    Given I am not logged in
    When I visit "/"
    Then I should see a "name" element
    And I should see a "pass" element

features/bootstrap/FeatureContext.php

use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Drupal\DrupalExtension\Context\RawDrupalContext;

class FeatureContext extends RawDrupalContext implements SnippetAcceptingContext {
  /**
   * 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() {
  }
}

My test directory structure:

behat.yml
composer.json
composer.lock
features/bootstrap/FeatureContext.php
features/platform/anonymous.feature
vendor

composer.json:

{
    "require": {
        "behat/mink": "~1.0",
        "behat/mink-goutte-driver": "~1.0",
        "behat/mink-selenium2-driver": "~1.1",
        "behat/mink-extension": "~2.0",
        "drupal/drupal-extension": "~3.1",
        "jcalderonzumba/mink-phantomjs-driver": "~0.3.1"
    }
}
@mradcliffe
Copy link
Author

Extending RawDrupalContext causes none of the step definitions to be found, but every other project/example i've seen extends it. So confusing.

But now with the same thing, I cannot get the Mink session to instantiate. It just complains with a very unintuitive error message: Mink instance has not been set on Mink context class. Have you enabled the Mink Extension? Why, yes, I do have MinkExtension in my behat.yml file.

I tried changing my behat.yml instead of what I had above (for the relevant section):

Behat\MinkExtension:
  sessions:
    default:
      goutte: ~

but mink still complains about not having an Mink instance.

I still must be missing something pretty big in the instructions or documentation about Behat/MinkExtension/DrupalExtension. Every blog post seems to skip over actually instantiating a Mink session or assumes that it just works.

@mradcliffe
Copy link
Author

I found a couple of issues with what I had done:

  • The composer dependencies seem to be the root of the issue, and I started from scratch with Composer on a linux box (and then replicating it back on my mac):
    • I set minimum-stability to stable
    • I used ^3.1 instead of ~3.1 for drupal\drupal-extension
    • I used ^0.1.3 instead of ~0.3.1 for jcalderonzumba/behat-phantomjs-extension
  • Finally after I got some progress I found that the @blackbox tag under filters caused my feature to disappear until I added that tag above the feature. This was not explained anywhere that I could find. I finally understood what to do because I got the PhantomJS bit working which had some examples with @javascript boilerplate at the top of the feature file.

xurizaemon pushed a commit to xurizaemon/drupalextension that referenced this issue Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant