Giter Site home page Giter Site logo

jhedstrom / drupalextension Goto Github PK

View Code? Open in Web Editor NEW
210.0 25.0 190.0 3.96 MB

An integration layer between Behat, Mink Extension, and Drupal.

License: GNU General Public License v2.0

PHP 84.08% HTML 0.97% Gherkin 14.95%
drupal behat behat-extension php

drupalextension's Introduction

Behat Drupal Extension

The Drupal Extension is an integration layer between Behat, Mink Extension, and Drupal. It provides step definitions for common testing scenarios specific to Drupal sites.

ci

The Drupal Extension 5.x supports Drupal 9 and 10, utilizes Behat 3.2+ and runs on:

  • PHP 7.4, 8.0, 8.1 with Drupal 9
  • PHP 8.1 with Drupal 10.

Latest Stable Version Total Downloads Latest Unstable Version License Scrutinizer Code Quality

Use it for testing your Drupal site.

If you're new to the Drupal Extension, we recommend starting with the Full documentation

Documentation Status

Quick start

  1. Install using Composer:

    mkdir projectdir
    cd projectdir
    curl -sS https://getcomposer.org/installer | php
    COMPOSER_BIN_DIR=bin php composer.phar require drupal/drupal-extension='~5.0'
  2. In the projectdir, create a file called behat.yml. Below is the minimal configuration. Many more options are covered in the Full documentation

    default:
      suites:
        default:
          contexts:
            - Drupal\DrupalExtension\Context\DrupalContext
      extensions:
        Drupal\MinkExtension:
          # Guzzle is used as HTTP client. You can configure the Guzzle request
          # options by setting `browserkit_http.guzzle_request_options`. For
          # instance the following configuration will disable SSL peer verification:
          # browserkit_http:
          #   guzzle_request_options:
          #     verify: false
          # See \GuzzleHttp\RequestOptions for all built-in Guzzle request options
          browserkit_http: ~
          base_url: http://example.org/  # Replace with your site's URL
        Drupal\DrupalExtension:
          blackbox: ~

1. In the projectdir, run

  ``` bash
  bin/behat --init
  ```

1. Find pre-defined steps to work with using:

  ```bash
  bin/behat -di
  ```

1. Define your own steps in `projectdir\features\FeatureContext.php`

1. Start adding your [feature files](http://behat.org/en/latest/user_guide/gherkin.html)
 to the `features` directory of your repository.

## Credits

* Originally developed by [Jonathan Hedstrom](https://github.com/jhedstrom) with great help from [eliza411](https://github.com/eliza411)
* Maintainers
 * [Pieter Frenssen](https://github.com/pfrenssen)
 * [All these great contributors](https://github.com/jhedstrom/drupalextension/graphs/contributors)

## Additional resources

* [Behat Drupal Extension documentation](https://behat-drupal-extension.readthedocs.org)
* [Behat documentation](http://docs.behat.org)
* [Mink documentation](http://mink.behat.org)
* [Drupal Behat group](http://groups.drupal.org/behat)

## Examples and code snippets

* [Complex node creation, with field collections and entity references](https://gist.github.com/jhedstrom/5708233)
* [Achievements module support](https://gist.github.com/jhedstrom/9633067)
* [Drupal form element visibility](https://gist.github.com/pbuyle/7698675)
* [Track down PHP notices](https://www.godel.com.au/blog/use-behat-track-down-php-notices-they-take-over-your-drupal-site-forever)
* [Support for sites using basic HTTP authentication](https://gist.github.com/jhedstrom/5bc5192d6dacbf8cc459)

## Release notes

See [CHANGELOG](CHANGELOG.md).

## Contributing

Features and bug fixes are welcome! First-time contributors can jump in with the
issues tagged [good first issue](https://github.com/jhedstrom/drupalextension/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22).

See [CONTRIBUTING.md](https://github.com/jhedstrom/drupalextension/blob/master/CONTRIBUTING.md) for more information.

drupalextension's People

Contributors

acbramley avatar ademarco avatar aronbeal avatar berdir avatar cboyden avatar claudiu-cristea avatar clemens-tolboom avatar dawehner avatar eliza411 avatar grasmash avatar greg-1-anderson avatar greggles avatar haringsrob avatar idimopoulos avatar jhedstrom avatar jonathanjfshaw avatar jose-carmona avatar lionsad avatar lotyrin avatar m4olivei avatar mikemadison13 avatar pfrenssen avatar shaundychko avatar stmh avatar stof avatar stopfstedt avatar subhojit777 avatar tanarurkerem avatar tizzo avatar webflo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

drupalextension's Issues

Anonymous User Session Handling

I'm building a commerce site and I need to be able to test the anonymous checkout case, but in order to do this I need to be able to pass a cookie to the js-aware mink driver after staging a cart with the drupal api, or I guess write up some janky module that makes a path available for an anonymous user to claim the last created cart.

A good intermediary for passing a session ID between drivers like this is not obvious to me. It seems like a bit of a kludge to just stick a sessions array on DrupalContext or the FeatureContext that extends it, but that's all I can see to do.

Moreover, I don't see a good event to react to, because we actually need to do this session trading dance before and after every step....

Is there a better way?

Snippets are missing in v3

--- Snippets for the following steps in the default suite were not generated (check your configuration):

    Given I visit "/user"
    Then I should see "Log in"

This seems like a "regression" from previous version, where it provided the snippet. Not sure yet how to enable this feature.

The testsuite setup should be improved

Currently, the Behat testsuite is done in a weird way (to be honest, Symfony2Extension was done this way as well until I rewrote it for 2.0, and MinkExtension is still done this way): it does not test the extension. It runs a feature suite against drupal and expects it to pass (meaning we cannot test for failure conditions, and

Scenario: try text matching with no drush command return an error.
is really weird and does not fail but marks the test as pending).
Instead, the feature suite should test the DrupalExtension itself (and so for instance the DrupalExtension should probably not be registered in the behat.yml of its own feature suite, as this extension is about testing a Drupal app and you would not be testing a Drupal app but a Behat extension). You can have a look at Symfony2Extension for a better way to do it

Drupal 7 errors

There is something wrong with the roles in drupal 7

 Given users:                                               # Drupal\DrupalExtension\Context\DrupalContext::createUsers()
      | name     | mail            | status |
      | Joe User | [email protected] | 1      |
    And I am logged in as a user with the "administrator" role # Drupal\DrupalExtension\Context\DrupalContext::assertAuthenticatedByRole()
      Failed to log in as user 'd78tLg7Y' with role 'administrator' (Exception)
    When I visit "admin/people"                                # Drupal\DrupalExtension\Context\MinkContext::assertAtPath()
    Then I should see the link "Joe User"                      # Drupal\DrupalExtension\Context\MinkContext::assertLinkVisible

Problem with Drupal driver in version 3.0

When I want to use the Drupal driver as documented in version 3.0, then Behat doesn't find any test anymore. My behat.yml looks like this:

default:
  suites:
    default:
      contexts:
        - FeatureContext
        - Drupal\DrupalExtension\Context\DrupalContext
        - Drupal\DrupalExtension\Context\MinkContext
  extensions:
    Behat\MinkExtension:
      goutte: ~
      selenium2: ~
      base_url: http://localhost/
    Drupal\DrupalExtension:
      blackbox: ~
      api_driver: "drupal"
      drupal:
        drupal_root: "/var/www/t/crm/htdocs"
      subcontexts:
        paths:
          - "/path/to/my/subcontexts"

When I call Behat with that, just nothing happens. When I then remove drupal.drupal_root from the yml file, then behat runs my tests but the drupal driver is not loaded then and hence I can't use the subcontext either.

I did some debugging and when drupal_drupal_root is defined then \Drupal\Driver\DrupalDriver gets initiated and it finds the correct Drupal version. But it doesn't run any tests without any error messages.

What am I doing wrong?

Problem with array short syntax

It is real issue with array short syntax in php 5.3
According to requirements for drupal extenstion needed php 5.3.5
http://behat-drupal-extension.readthedocs.org/en/3.0/requirements.html
Short array syntax starts from php 5.4.0
http://php.net/manual/en/migration54.new-features.php
23.12.14 was commited row with short array syntax
585f289

After composer up it is error like:
Parse error: syntax error, unexpected '[' in behat\vendor\drupal\drupal-extension\src\Drupal\DrupalExtension\Context\DrupalContext.php on line 56

Please, fix it.

Error cleaning users with Drush

I set up a remote server to run tests against a D8 site on Pantheon. Using the Drush driver, I get the following:

  @api
  Scenario: Auth                                               # features/homepage.feature:9
    Given I am logged in as a user with the administrator role # FeatureContext::assertAuthenticatedByRole()
    When I am on the homepage                                  # FeatureContext::iAmOnHomepage()
    Then I should see "Log out"                                # FeatureContext::assertPageContainsText()
    And I should not see "Log in"                              # FeatureContext::assertPageNotContainsText()
  โ”‚
  โ•ณ  (RuntimeException)
  โ”‚
  โ””โ”€ @AfterScenario # FeatureContext::cleanUsers()

Feature request: Add menu map support

Similar to the support provided for region mapping in behat.yml, it would be great if we could also add menu path support, so that rather than write physical paths to pages in your steps (like "When I visit "/user/register"), we could write a step in a fashion such as:

When I visit the "User Registration" page

You can then configure the 'User Registration' page the way region mapping is configured, something like this:

Drupal\DrupalExtension:
  ...
  menu_map:
    User Registration: "/user/register"
    User Login: "/user/login"

Placement of FeatureContext.php

Now that the Drupal Extension creates a properly set FeatureContext.php file, when I run bin/behat --init FeatureContext.php is placed in the vendor folder.

If that's actually where it belongs, best practices wouldn't have me commit the vendor folder to the Git repository. What's the recommendation for custom step definitions?

Does drupal_root work?

In step 7 of drupalextension's documentation you call referring to an existing drupal 7 site as the drupal_root. When I do this I get the error:

PHP Fatal error: Class 'Symfony\Component\Finder\Finder' not found

I wasn't getting that error before step 7. Everything works up to step 6.

Can't get it working in Behat 3

I was able to get this working last year under Behat 2, but just did a fresh install, and cannot get it to work. I feel like I cannot get the driver to find my local site.

Here is my composer.json:

{
  "name": "test/test",
  "description": "drupal7",
  "require": {
    "drupal/drupal-extension": "~3.0"
  }
}

Here is my behat.yml:

default:
   suites:
     default:
       contexts:
         - FeatureContext
         - Drupal\DrupalExtension\Context\RawDrupalContext
         - Drupal\DrupalExtension\Context\DrupalContext
         - Drupal\DrupalExtension\Context\MinkContext
       extensions:
           Behat\MinkExtension:
             goutte: ~
             javascript_session: selenium2
             selenium2:
               wd_host: http://local.d7sandbox.com:8643/wd/hub
             base_url: http://local.d7sandbox.com
           Drupal\DrupalExtension:
             blackbox: ~
             api_driver: 'drupal'
             drupal:
               drupal_root: '/var/www/site/docroot'

Here is my feature context:

<?php

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

/**
 * Defines application features from the specific context.
 */
class FeatureContext implements Context, 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()
    {
    }
}

I can see the custom step definitions with bin/behat -di. Here is the output when I try a simple scenario:

Feature: Content Management
  When I log into the website
  As an administrator
  I should be able to create, edit, and delete page content

  Scenario: An administrative user should be able create page content
    Given I am logged in as a user with the "administrator" role
    When I go to "node/add/page"
    Then I should not see "Access denied"

Here is the error output:

Feature: Content Management
  When I log into the website
  As an administrator
  I should be able to create, edit, and delete page content

  Scenario: An administrative user should be able create page content # features/test.feature:6
PHP Fatal error:  Call to a member function getSession() on a non-object in /Users/kevinquillen/Sites/drupal7/vendor/behat/mink-extension/src/Behat/MinkExtension/Context/RawMinkContext.php on line 101

I feel like I have ran into this before with a similar error a while ago but don't recall how I fixed it.

Does vendor and behat features need to reside outside of the Drupal docroot? I currently have them within. I am not sure where I messed up, but I feel like I am very close I just cannot communicate with the virtualized site in Vagrant.

Testing multilingual sites

Using 3.0 of the Drupal Extension I recently ran into trouble with a client's site which is multi-lingual. It happens that basic tests are failing because e.g. content or error messages no longer match the tests when the tests are written in English and the site defaults to German.

I was trying to change the base URL in behat.yml of the project to http://www.exampl.com?language=en which is a valid URL that forces the site to switch to the English context, but that breaks the tests as well as they then seem to be appending the path like "/user" to the base URL which then makes that http://www.exampl.com?language=en/user which is no longer valid.

I wonder what's the best approach here. We could either support queries in the base URL, then the approach like desribed above would already work, or there might be a new setting in the behat.yml that forces the site to a certain context or sends HTTP headers that help to set the language context. Maybe that's already possible and I just haven't found it?

Figure out phpunit dependencies

We seem to have an indirect dependency on phpunit/phpunit and phpunit/php-code-coverage which don't get pulled in with composer.

Test for a 403 HTTP response code

The following scenario should test that node/add can not be accessed:

  Scenario: Anonymous user should not be able to add a node
    Given I visit "/"
    When I visit "node/add"
    Then I should get a "403" HTTP response
    And I should see the text "Access denied"

Running behat with drupal-extension version 1.0.5 outputs "Current response status code is 403, but 200 expected." and skips subsequent steps.

Changing the scenario into:

  Scenario: Anonymous user should not be able to add a node
    Given I visit "/"
    Then I should get a "403" HTTP response
    And I should see the text "Access denied"

then I get "Current response status code is 200, but 403 expected.". Almost feels like a catch 22.

What is the correct way of testing this?

BeforeStep and AfterStep no longer support tags in Behat 3

Tags can no longer be used on BeforeStep and AfterStep hooks. This means that this code in MinkContext.php:

/**
   * For javascript enabled scenarios, always wait for AJAX after clicking.
   *
   * @AfterStep @javascript
   */
  public function afterJavascriptStep($event) {
    $text = $event->getStep()->getText();
    if (preg_match('/(follow|press|click|submit)/i', $text)) {
      $this->iWaitForAjaxToFinish();
    }
  }

is failing silently - the function is never called.

See Behat/Behat#650 and Behat/Behat#653.

Message assertion fails for certain markup

By default, Drupal delivers all messages of a certain type (error, warning, success) in a single container that can be identified per type. But if each message happens to be in their own container, then the assertErrorVisible() (and similar functions) won't recognize all of the error messages but only the last one of each type.

If you're using findAll() instead of just find() then that'll be solved. Here is the slightly changed code that does the job properly:

  public function assertErrorVisible($message) {
    $errorSelector = $this->getDrupalSelector('error_message_selector');
    $errorSelectorObjects = $this->getSession()->getPage()->findAll("css", $errorSelector);
    if(empty($errorSelectorObjects)) {
      throw new \Exception(sprintf("The page '%s' does not contain any error messages", $this->getSession()->getCurrentUrl()));
    }
    foreach ($errorSelectorObjects as $errorSelectorObj) {
      $text = $errorSelectorObj->getText();
      if (strpos(trim($errorSelectorObj->getText()), $message) !== FALSE) {
        return;
      }
    }
    throw new \Exception(sprintf("The page '%s' does not contain the error message '%s'", $this->getSession()->getCurrentUrl(), $message));
  }

Auto-discovery discovers outdated documentation snippet, causes fatal PHP error

If you set the subcontext search path to a path that includes the vendor directory, you'll get a fatal error. This is because the file doc/_static/snippets/beanslide.behat.inc is included in the search. It tries to extend Behat\Behat\Context\BehatContext, which doesn't exist anymore in Behat 3.0.

Possible solutions:

  1. Change the filename of the snippet so it's not included automatically (doesn't match *.behat.inc);
  2. Update the snippet so it points at a class that exists (the doc is wrong for this version anyway, in v3 there aren't subcontexts anymore and there's no getMainContext function);
  3. Don't point any subcontext search paths at a directory that includes the vendor directory - document this for users of the extension.

Probably all three are worth doing.

Login fails

I'm trying to get a simple logged in test case going for a D8 site.

It seems I can't get any user successfully logged in however.

My composer.json

{
    "config": {
        "bin-dir": "bin/"
    },
    "require": {
        "drupal/drupal-extension": "3.0.*@dev",
        "drupal/drupal-driver": "1.0.*@dev"
    }
}

My feature:

Feature: Create content
  In order to add content
  As an admin
  I need to have access to the right forms.

  @api
  Scenario: Ability to create a page
    Given I am logged in as a user with the "authenticated" role
    When I go to "/"
      And click "Add content"
    Then I should see a link titled "Page"

This fails as follows:

  @api
  Scenario: Ability to create a page                             # features/admin.feature:7
    Given I am logged in as a user with the "authenticated" role # FeatureContext::assertAuthenticatedByRole()
      Failed to log in as user 'sm1yJhuJ' with role 'authenticated' (Exception)

I see the check for "logged in", is to look for a "Log out" link, this check fails as expected, because the returned page actually contains a "Log in" link. I check this by var_dump($element); just before the logged in check is done.

But beyond this, I'm at a at how to proceed.
Also in the var_dump, I find

object(Symfony\Component\BrowserKit\CookieJar)#3365 (1) {
  ["cookieJar":protected] => array(1) {
    [".mydomain.com"]=> array(1) {
      ["/"]=>array(1) {        
        ["__cfduid"]=> object(Symfony\Component\BrowserKit\Cookie)#3639 (8) {
          ["name":protected]=>string(8) "__cfduid"
          ["value":protected]=>string(46) "d2affc543c5376b605f296d138282bb021413750749447"
          ["expires":protected]=>int(1577145000)
          ["path":protected]=>string(1) "/"
          ["domain":protected]=>string(11) ".mydomain.com"
          ["secure":protected]=>bool(false)
          ["httponly":protected]=>bool(true)                 
          ["rawValue":protected]=> string(46) "d2affc543c5376b605f296d138282bb021413750749447"
          }
        }
      }
    }
  }

I'm not familiar enough with the session handling in Drupal to say what that means, but I take it to mean a session has been established, and we're trying to use it to log in.

However, if I look in the DB for the session that get's created, I can't match up the values above with anything I see in the sessions table.

Any thoughts on where I can debug this further?

Can't use "drupal" driver

On this configuration

default:
  suites:
    default:
      contexts:
        - Drupal\DrupalExtension\Context\DrupalContext
  extensions:
    Behat\MinkExtension:
      goutte: ~
      selenium2: ~
      base_url: 'http://localhost:9050/'
    Drupal\DrupalExtension:
      api_driver: 'drupal'
      drupal:
        drupal_root: "/var/www/my-site/www"

Upon bin/behat -di I get:

[InvalidArgumentException]            
Driver "blackbox" is not registered.

But I add the "blackbox"

    # ...
    Drupal\DrupalExtension:
      blackbox: ~
      api_driver: 'drupal'
      drupal:
        drupal_root: "/var/www/my-site/www"

Upon bin/behat -di I get:

Fatal error: Class 'Behat\Behat\Context\BehatContext' not found in /.../behat/vendor/drupal/drupal-extension/doc/_static/snippets/beanslide.behat.inc on line 10

Cannot login with new user

My files based on docs:
behat.yml

default:
  suites:
    default:
      contexts:
        - FeatureContext
        - Drupal\DrupalExtension\Context\DrupalContext
        - Drupal\DrupalExtension\Context\MinkContext
        - Drupal\DrupalExtension\Context\MessageContext
        - Drupal\DrupalExtension\Context\DrushContext
  extensions:
    Behat\MinkExtension:
      goutte: ~
      selenium2: ~
      base_url: http://local.dev
    Drupal\DrupalExtension:
      blackbox: ~
      api_driver: 'drupal'
      drupal:
        drupal_root: /var/www/html

features/bootstrap/FeatureContext.php

class FeatureContext extends RawDrupalContext implements SnippetAcceptingContext {
  public function __construct() {
  }
}

features/test.feature

  @api
  Scenario: Test a logged in user.
    Given users:
    | name  | mail              | status | role |
    | behat | [email protected] | 1      | authenticated user |
    When I am logged in as "behat"
    And I go to /track
    Then I should see "History"

This fails with:

  @api
  Scenario: Test a logged in user. # features/test.feature:11
    Given users:                   # Drupal\DrupalExtension\Context\DrupalContext::createUsers()
      | name  | mail              | status | role               |
      | behat | [email protected] | 1      | authenticated user |
    When I am logged in as "behat" # Drupal\DrupalExtension\Context\DrupalContext::assertLoggedInByName()
      Failed to log in as user 'behat' with role 'authenticated user' (Exception)
    And I go to /track
    Then I should see "History"    # Drupal\DrupalExtension\Context\MinkContext::assertPageContainsText()

--- Failed scenarios:

    features/test.feature:11

2 scenarios (1 passed, 1 failed)
7 steps (4 passed, 1 failed, 1 undefined, 1 skipped)
0m1.84s (39.89Mb)

Split DrupalContext into 4 contexts

The DrupalContext class is composed of 4 distinct parts:

  • Helper steps/non-API
  • Node
  • User
  • Taxonomy

Splitting these into separate contexts will mainly serve as an example to contrib module authors on how to write their own contexts that integrate into the Drupal Extension.

Problem installing the 3.0 version

When following the instructions in the readme, I'm requiring "drupal/drupal-extension": "~3.0" which results in The requested package drupal/drupal-extension could not be found in any version

Changing the requirement to "drupal/drupal-extension": "~3.0@dev" I will get this error instead:

    - Installation request for drupal/drupal-extension ~3.0@dev -> satisfiable by drupal/drupal-extension[3.0.x-dev].
    - drupal/drupal-extension 3.0.x-dev requires drupal/drupal-driver 1.0.*@dev -> no matching package found.

Any idea on how I could resolve this?

Problem with context namespacing

I added this to my main composer file:

 "autoload": {
    "psr-0": {
      "Emuse": "emuse/"
    }
  }

I added a folder emuse in my root and created a Context file:

namespace Emuse;

class EmuseContext extends DrupalContext {}

When I set behat to use this context it says it cannot be found, although when I look in my composer namespace files, everything seems to be ok:

suites:
    default:
      contexts:
        - Emuse\EmuseContext
        - Drupal\DrupalExtension\Context\MinkContext
        - Drupal\DrupalExtension\Context\MessageContext
        - Drupal\DrupalExtension\Context\DrushContext

How to use MinkContext along with DrupalContext?

I would like to use a method from MinkContext. based on this comment in the docs:

To add in support for additional web-based step definitions add the extended Drupal\DrupalExtension\Context\MinkContext:

I thought I would be able to, but PHP fails Call to undefined method FeatureContext::assertAtPath(). Is there a way to extend DrupalContext but also use MinkContext?

Require more specific versions in composer.json

I'm currently attempting to add this extension to Drupal 8 core's composer.json, and running into issues with the package versions defined in this project's composer.json.

    - Installation request for drupal/drupal-extension dev-master#fad51a12a90f5b7db0cab9f972e8415113bf0222 -> satisfiable by drupal/drupal-extension[dev-master].
    - drupal/drupal-extension dev-master requires behat/mink-extension 2.0.x-dev -> no matching package found.

I am assuming this is because:

- The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.

Rather than specifying "*" for behat/mink-extension, it may be better to specify a stable tag. E.g.,
"behat/mink-extension": "v1.3.3" or "behat/mink-extension": "~v1.3.3"

This update should also be applied to:

    "behat/mink-goutte-driver": "*",
    "behat/mink-selenium2-driver": "*",

Nothing happens ...

Hi, sorry for this rather empty support request - I am a little new to this.

When I run with the blackbox driver everything appears to work as expected except many steps are unavailable such as:

# ~/Sites/mysite.localhost $ bin/behat --profile=default --tags="test"
  @test
  Scenario: Lets test this                                      # features/tests.feature:6
    Given I am logged in as a user with the "member admin" role # Drupal\DrupalExtension\Context\DrupalContext::iAmLoggedInWithRole()
      No ability to create users in Drupal\Driver\BlackboxDriver

1 scenario (1 failed)
1 step (1 failed)
0m0.102s
# ~/Sites/mysite.localhost $ 

So I'd like to use the Drupal7 driver. I've created a drupal 7 profile in my composer.json (see below) but when I run the command there is not output at all, no errors, nothing (I've tried with and without the tags filer) ...

  drupal7:
    filters:
      tags: "@api"
    extensions:
      Behat\MinkExtension\Extension:
        base_url: http://mysite.localhost:8082
      Drupal\DrupalExtension\Extension:
        api_driver: "drupal"
        drupal:
          # Change this to the absolute path to Drupal install.
          drupal_root: "/Users/me/Sites/mysite.localhost/docroot"
        region_map:
          left sidebar: "#sidebar-first"
          content: "#content"
  # ~/Sites/mysite.localhost $ bin/behat --profile=drupal7
  # ~/Sites/mysite.localhost $ 

Kind regards,

John

Unimplemented step in api.feature

Scenario: Find a heading in a region                                      # features/api.feature:24
  Given I am not logged in                                                # Drupal\DrupalExtension\Context\DrupalContext::assertAnonymousUser()
  When I am on the homepage                                               # Drupal\DrupalExtension\Context\MinkContext::iAmOnHomepage()
  Then I should see the heading "User login" in the "left sidebar" region

Returns:

 --- Snippets for the following steps in the default suite were not generated (check your configuration):
  Then I should see the heading "User login" in the "left sidebar" region

Are there plans to implement this or should it be removed from the API tests and docs examples?

Improve performance of logout

No pull requests yet, I'm experimenting with some changes in overridden methods but not all of that can be assumed to be generally true.

Here's what I'm currently doing/thinking about:

  1. For logout, instead of doing a real logout, I just do $this->getSession()->reset(), which drops any session cookies.
  2. For loggedIn(), I'm not doing the initial request to the frontpage and instead just assume that the page I'm on has the logout link. This has a few problems, notably that some of the assert logged in as user with role and so on methods initially call loggedIn() to check if already logged in with a user that matches the condition. In this case, I'm currently just catching the thrown exception and consider it to be not logged in.
  3. However, I think those checks are not necessary anyway. I don't know how others structure their tests, but having multiple identical "Given I am logged in as a user with role "X" seems very unlikely and currently (without my hack from above), the overhead of doing an additional frontpage request is way bigger than a few saved user creations here and there.
  4. A problem I had with my pretty big test suite (currently 185 scenarios, 2.2k steps, doing sometimes pretty crazy stuff) was that I had some "Given I am an anyomous user" checks on some admin pages, which had no Log Out link. However, similar to 3., with the fast "logout" from 1., just calling logout() should be faster than loading the frontpage to avoid calling it if we're not logged in.

Thoughts?

I'm currently doing 1, 2 and 4 (didn't bother updating all the methods for 3, just catching the exception for now) and that saves me 2 requests for the first login and three for any following (due to the logout) in the same scenario. That sums up quite nicely.

Update xliff for i18n

Since #72 went in, the existing xliff files need to be updated (they were incredibly out of date anyway).

Symfony Translator missing

Hi, I installed the module and behat, but when I run the behat --init command I get this error:

[ReflectionException]
Class Symfony\Component\Translation\Translator does not exist

I am using the latest release of drupal 8

Which api_driver is the fastest?

I wanted to add a note on the driver comparison about which one is faster. The Drupal API driver says that it is faster but in a quick local test that covered 8 scenarios and 182 steps it took 3m49.735s with api_driver: "drush" and 4m2.933s with api_driver: "drupal". I wasn't strict about running this in an isolated environment and the difference isn't huge (~5%) but...is there a definitive sense of which one is faster? :)

This is awesome stuff

This is not an issue... just a support request :)

I just have a configuration/setup question. Where do you put all the composer stuff? I've added features/ and behat.yml and composer.json and everything in the drupal root. That works fine, but when I use drush to upgrade drupal core it usually wipes out everything not under sites/all... I'm sure I could use version control to restore whatever drush wipes out, but I was just wondering where you put your awesome behat stuff.

Thanks,

Upgrade hook system to Behat 3

Behat 3 changed how hooks are managed. The Drupal Extension provides the following annotated hooks that need to be ported to the new system:

  • afterNodeCreate
  • afterTermCreate
  • afterUserCreate
  • beforeNodeCreate
  • beforeTermCreate
  • beforeUserCreate

Error message is a little less useful

In Version 1, running an untagged @api step like this:

Given I am logged in as a user with the "authenticated user" role

Produced the message:

  No ability to create users in Drupal\Driver\BlackboxDriver. 
  Put `@api` into your feature and add an api driver 
  (ex: `api_driver: drupal`) in behat.yml.

In Version 3 the output says:

No ability to generate random in Drupal\Driver\BlackboxDriver.
Put `@api` into your feature and add an api driver
(ex: `api_driver: drupal`) in behat.yml. (Drupal\Driver\Exception\UnsupportedDriverActionException)

The former seems slightly more meaningful even if the latter is more exact. I'm find just closing this as "wontfix" if you prefer but wanted to make sure it was on purpose before I update the docs accordingly.

Split Drupal drivers into separate repositories

The current Drupal drivers (Blackbox, Drupal API, and Drush) are not specific to Behat. Splitting these into separate repositories would allow them to be used, for instance, directly with Mink, PHPUnit, or other testing frameworks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.