Running selenium tests using Behat Drupal Extension inside DDEV containers
Asked Answered
A

2

8

Problem: Get Behat Drupal Extension based testing working inside of ddev containers. This includes adding a separate selenium container to the existing configuration, being able to run Behat tests, and having the be able to reference the web host container.

According answered 25/7, 2018 at 21:7 Comment(0)
A
6

Prerequisites: have a working ddev instance hosting Drupal. There are examples already to set that up, so I won't repeat that here.

The above task required the following additions:

  • selenium container: The container running selenium. I used the chrome standalone version. Add the following to your .ddev folder:

File: docker-compose.selenium.yml

version: '3.6'

services:
  selenium:
    container_name: ddev-${DDEV_SITENAME}-selenium
    image: selenium/standalone-chrome-debug:3.13.0-argon
    networks:
      default:
        aliases:
          - web

The last bit is critical; the selenium container needs to know about the web container running the drupal instance to connect to it, but as it is a dependency of the web container, you can't use 'links'. You have to use the aliases approach, using the default network.

  • compose override: A file overriding the defaults for the web container to link the selenium container to it.

File: docker-compose.override.yml

version: '3.6'

services:
  web:
    depends_on:
      - db
      - selenium
    links:
      - db:db
      - selenium:selenium
  • Behat configuration: The following Behat configuration for MinkExtension worked for me:

(modify file behat.yml)

default:
  extensions:
    "Behat\\MinkExtension":
      goutte: null
      base_url: 'http://web'
      javascript_session: selenium2
      selenium2:
        browser: "chrome"
        wd_host: http://selenium:4444/wd/hub
        capabilities:
          extra_capabilities:
            idle-timeout: 50

base_url and wd_host entries were critical in getting this to work.

For more information on the last, see step 5 in the Behat Drupal Extension docs:

Configure your testing environment by creating a file called behat.yml with the following. Be sure that you point the base_url at the web site YOU intend to test. Do not include a trailing slash:

default:
  suites:
    default:
      contexts:
        - FeatureContext
        - Drupal\DrupalExtension\Context\DrupalContext
        - Drupal\DrupalExtension\Context\MinkContext
        - Drupal\DrupalExtension\Context\MessageContext
        - Drupal\DrupalExtension\Context\DrushContext
  extensions:
    Drupal\MinkExtension:
      goutte: ~
      selenium2: ~
      base_url: http://seven.l
    Drupal\DrupalExtension:
      blackbox: ~
According answered 25/7, 2018 at 21:8 Comment(2)
Thx! With this I managed to setup codeception testing with selenium for a CakePHP App.Sundaysundberg
The correct answer is still valid or has it changed in something about how to configure ddev drupal with behat selenium?Riti
N
2

A current way to run Behat on Drupal with DDEV is via the ddev-selenium-standalone-chrome

Steps

  1. Install the addon and restart DDEV
ddev get ddev/ddev-selenium-standalone-chrome
ddev restart
  1. Update behat.yml to use the addon.
  extensions:
    Drupal\MinkExtension:
      base_url: https://web
      selenium2:
        wd_host: http://selenium-chrome:4444/wd/hub
        capabilities:
          chrome:
            switches:
              - "--ignore-certificate-errors"
              - "--disable-gpu"
              - "--headless"
              - "--no-sandbox"
              - "--disable-dev-shm-usage"
Nies answered 9/3, 2023 at 8:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.