Behat Integration with Drupal using drupalextension module

Follow the http://behat-drupal-extension.readthedocs.io/en/3.1/requirements.html for requirements and run the Selenium server

$ mkdir /Users/gopi/behat

$  cd /Users/gopi/behat

$ curl http://getcomposer.org/installer | php
Composer (version 1.3.2) successfully installed to: /Users/gopi/behat/composer.phar
Use it: php composer.phar

$ sudo vim composer.json

{
  "require": {
    "drupal/drupal-extension": "~3.0"
},
  "config": {
    "bin-dir": "bin/"
  }
}

save the above code in composer.json

$ php composer.phar install

$ sudo vim 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://develop
    Drupal\DrupalExtension:
      blackbox: ~
      api_driver: 'drupal'
      drupal:
        drupal_root: '/Applications/MAMP/htdocs/develop'


  Save the above code in behat.yml

  $ sudo vim feature/first.feature


  Feature: first
  My first Behat try. Don’t laugh :)

  Scenario: The Drupal installer should enable the footer block
    Given I am an anonymous user
    Given I am on the homepage
    Then I should see "Drupal"

Save the above code in first.feature


$ bin/behat features/first.feature


Feature: first
  My first Behat try. Don’t laugh :)

  Scenario: The Drupal installer should enable the footer block # features/first.feature:4
    Given I am an anonymous user                                # Drupal\DrupalExtension\Context\DrupalContext::assertAnonymousUser()
    Given I am on the homepage                                  # Drupal\DrupalExtension\Context\MinkContext::iAmOnHomepage()
    Then I should see "Beleggen"                                # Drupal\DrupalExtension\Context\MinkContext::assertPageContainsText()

1 scenario (1 passed)
3 steps (3 passed)
0m1.53s (71.29Mb)


Following is an example to run chrome:



$ brew install chromedriver

$ sudo vim 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: ~
         javascript_session: selenium2
         selenium2:
           browser: 'chrome'
           wd_host: http://127.0.0.1:4444/wd/hub
         base_url: http://develop
       Drupal\DrupalExtension:
         blackbox: ~
         api_driver: 'drupal'
         drupal:
           drupal_root: '/Applications/MAMP/htdocs/develop'

$ sudo vim first.feature

@api
Feature: first
  My first Behat try. Don’t laugh :) 

  Scenario: The Drupal installer should enable the footer block
    Given I am an anonymous user   
    Given I am on the homepage
    Then I should see "Beleggen"

 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"

 Scenario: Create and view a node with fields
   Given I am viewing an "Article" content:
     | title | My article with fields! |
     | body  | A placeholder           |
   Then I should see the heading "My article with fields!"
   And I should see the text "A placeholder"

@javascript
 Scenario: Create a node
 Given I am logged in as a user with the "Content Manager" role
 When I am viewing an "article" content with the title "My article"

 Then I should see the heading "My article"

Comments

Popular posts from this blog

Programatically create layout builder section in Drupal

Code quality analysis of Drupal. Can I use Sonar?

Set up Drupal7 to Drupal8 migration in simple steps (using Drush)