I'm trying to use the Blackbox driver with an already existing (real) user but get the error message in the title. My questions:

  1. Can the Blackbox driver handle logged in users at all?
  2. If yes, how do I register a user with the driver?
  3. If not, how do I register a user with the API and/or Drush driver?

Any hints welcome as I haven't found any information about registering users in either the documentation or the source code.

TIA
Frank

Comments

jhedstrom’s picture

By default, the Blackbox driver has no way of dealing with users. The Drupal.org BDD used to have some logic for dealing with a list of pre-defined users (see the behat.local.yml.example file that comes with it, where a drupal_users parameter is set). While I don't think this is being used anymore, at one time they had a custom step along the lines of:

Given I am logged in as "..." user

The step definition then retrieved the username/pass combo from the preset parameter, and walked through the steps needed to log the user in on d.o.

Frank Ralf’s picture

Thanks for the quick reply. I'll have a look at the Doobie code.

Just for the curious here's an excerpt from behat.local.yml.example

# Local configuration.
default:
  context:
    parameters:
      drupal_users:
        drupal:
          'drupal'
        site user:
          'site user pass here'
        git user:
          'git user pass here'
        git vetted user:
          'git vetted user pass here'
        docs manager:
          'docs moderator pass here'
        admin test:
          'admin test pass here'
        site maintainer:
          'site maintainer pass here'
      #git usernames don't always match the drupal username
      git_users:
        gituser:
          'gituser pass here'
        gitvetteduser:
          'gitvetteduser pass here'

And here's the step definition from \doobie\features\bootstrap\FeatureContext.php

/**
   * Authenticates a user with password from configuration.
   *
   * @Given /^I am logged in as the "([^"]*)"$/
   */
  public function iAmLoggedInAs($username) {
    $password = $this->fetchPassword('drupal', $username);
    $this->iAmLoggedInAsWithThePassword($username, $password);
  }
Frank Ralf’s picture

JFTR

I think I will solve the problem by using meta steps as described at http://knplabs.pl/blog/behat-like-a-boss-meta-steps

EDIT 1:
Following the instructions from the above URL I came up with the following feature using steps provided by the Mink extension.
(This is not yet a real meta step):

Feature: User login to Drupal
  In order test features only available to registered users
  As a user
  I need to be able to log in to the Drupal site

  Scenario: Log in to the Drupal site as user Dagobert Duck
    Given I am on the homepage
    When I fill in the following:
        | Benutzername | Dagobert |
        | Passwort | test |
    And press "Log in"
    Then I should see the text "Prof. Dagobert Duck" in the "header"
Frank Ralf’s picture

Issue summary: View changes

Added links to already researched resources.

Albert Volkman’s picture

Issue summary: View changes

Above link to KNPLabs' blog is broken. Here's the updated link-

http://knplabs.com/blog/2011/12/15/behat-like-a-boss-meta-steps/

jhedstrom’s picture

Status: Active » Closed (works as designed)

Closing out for now. Thanks for those links!

boinkster’s picture