0

I have the following set up. I vagrant machine with d8 site setup. The files are common. I have replicated the DB in my laptop outside the host so I can run the behat tests faster. The DB is a dump of the one in the vagrant host.

Behat for host:

default:
  suites:
  default:
    contexts:
      - FeatureContext:
        - "/vagrant/images/behat"
        - 813
        - 1855
      - Drupal\DrupalExtension\Context\DrupalContext
      - Drupal\DrupalExtension\Context\MinkContext
      - Drupal\DrupalExtension\Context\MessageContext
      - Drupal\DrupalExtension\Context\DrushContext
  extensions:
    Behat\MinkExtension:
      selenium2: ~
      base_url: http://mysite.dev  # Replace with your site's URL
    Drupal\DrupalExtension:
      blackbox: ~
      api_driver: 'drupal'
      drush:
        alias: 'local'
      drupal:
        drupal_root: '/vagrant/drupal'

Behat for local:

default:
  suites:
    default:
      contexts:
        - FeatureContext:
          - "/vagrant/images/behat"
          - 813
          - 1855
        - Drupal\DrupalExtension\Context\DrupalContext
        - Drupal\DrupalExtension\Context\MinkContext
        - Drupal\DrupalExtension\Context\MessageContext
        - Drupal\DrupalExtension\Context\DrushContext
  extensions:
    Behat\MinkExtension:
      selenium2:
        browser: chrome
      base_url: http://mysite.dev  # Replace with your site's URL
    Drupal\DrupalExtension:
      blackbox: ~
      api_driver: 'drupal'
      drush:
        alias: 'local'
      drupal:
        drupal_root: '/home/user/Projects/myproject/vagrant/drupal'

When I run the following scenario on the vagrant I can log in while in my local machine it fails to log in.

 @node
 Scenario: Create a node
   Given I am logged in as a user with the "administrator" role
   When I am viewing an "article" content with the title "My article"
   Then I should see the heading "My article"

How can I resolve this?

1 Answer 1

1

The login step creates a user via the Drupal API, and logs in by manually submitting the form.

When you run from within the Vagrant machine, the process presumably has access to bootstrap Drupal, and create users. When you're running from your local machine, I think only 'blackbox' tests (eg, ones that don't require API access) will work.

One potential workaround for this would be to specify in your local behat file:

api_driver: drush
drush:
  alias: 'vagrant'

and then ensure your local machine had a drush alias @vagrant setup so that you could access your vagrant Drupal instance from your local machine.

1
  • This is what I do for local testing. I have a local alias that has the ssh key set to the vagrant boxes private key.
    – mradcliffe
    Commented Mar 3, 2017 at 23:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.