lando / docs

The main docs site for Lando
https://docs.lando.dev/
GNU General Public License v3.0
20 stars 57 forks source link

Drupal 7 multisite & behat tests #55

Closed BryanRice800 closed 5 years ago

BryanRice800 commented 5 years ago

Please complete the following:

Link to the page that needs to be updated or changed. https://docs.devwithlando.io/dev/testing.html

Describe the change you'd like I am currently using lando in s multisite setup and trying to use behat testing, however I can't find any relevant documentation other than the basic setup which is not working for this case.

Tell us about your setup

Version: v3.0.0-rc.16 OS:

Tell us about your .lando.yml

recipe: drupal7
config:
  drush: ^7
  databases:
    overrides:
      creds:
        user: root
        password: root
        database: nbcs_db
services:
  cache-service:
    portforward: true
    type: memcached
  node-service:
    command: tail -f /dev/null
    globals:
      gulp-cli: latest
    ssl: false
    type: node:11
  appserver:
    ssl: true
    config:
      php: lando/config/php/php.ini
    overrides:
      environment:
        AH_SITE_ENVIRONMENT: local
        BEHAT_PARAMS: '{"extensions" : {"Behat\\MinkExtension" : {"base_url" : "http://nbcs.lndo.stie:8080/"}, "Drupal\\DrupalExtension" : {"drush" : { "root": "/app/docroot" }}}}'
    php: 7.2
    via: apache:2.4
    webroot: docroot
    xdebug: true
proxy:
  appserver:
    - nbcs.lndo.site:80
    - bayarea.lndo.site:80
    - boston.lndo.site:80
    - chicago.lndo.site:80
    - philadelphia.lndo.site:80
    - northwest.lndo.site:80
    - washington.lndo.site:80
tooling:
  local-tasks:
    service: appserver
    cmd: /app/lando/scripts/local-tasks.sh
  custom-drush:
    service: appserver
    cmd: /app/lando/scripts/custom-drush.sh
  import-db:
    service: appserver
    cmd: /app/lando/scripts/import-db.sh
  configure-site:
    service: appserver
    cmd: /app/lando/scripts/configure-site.sh
  install-gulp:
    service: node-service
    cmd: /app/lando/scripts/install-gulp.sh
  behat:
    service: appserver
    description: Run behat tests locally.
    cmd: /app/lando/scripts/behat.sh
  drush-nbcs:
    service: appserver
    cmd: 
      - drush --root=/app/docroot --uri=http://nbcs.lndo.site:8080
  drush-rsnhub:
    service: appserver
    cmd: 
      - drush --root=/app/docroot --uri=http://rsnhub.lndo.site:8080
  drush-chicago:
    service: appserver
    cmd: 
      - drush --root=/app/docroot --uri=http://chicago.lndo.site:8080
  drush-northwest:
    service: appserver
    cmd: 
      - drush --root=/app/docroot --uri=http://northwest.lndo.site:8080
  drush-bayarea:
    service: appserver
    cmd: 
      - drush --root=/app/docroot --uri=http://bayarea.lndo.site:8080
  drush-washington:
    service: appserver
    cmd: 
      - drush --root=/app/docroot --uri=http://washington.lndo.site:8080
  drush-philadelphia:
    service: appserver
    cmd: 
      - drush --root=/app/docroot --uri=http://philadelphia.lndo.site:8080
  drush-boston:
    service: appserver
    cmd: 
      - drush --root=/app/docroot --uri=http://boston.lndo.site:8080
  drush:
    service: appserver
    cmd: 
      - drush --root=/app/docroot

behat.yml

# Default profile.
# Common settings for all profiles
default:
  suites:
    default:
      paths:
        analytics: '%paths.base%/features/Analytics'
        bootstrap: '%paths.base%/features/bootstrap'
        vod: '%paths.base%/features/VOD'
        security: '%paths.base%/features/Security'
        performance: '%paths.base%/features/Performance'
        functionality: '%paths.base%/features/Functionality'
        basic: '%paths.base%/features/Basic'
      contexts:
        - BlockManagerContext
        - MediaCardsContext
        - CustomDrupalContext
        - Drupal\DrupalExtension\Context\MinkContext
        - Drupal\DrupalExtension\Context\MessageContext
        - Drupal\DrupalExtension\Context\DrushContext
        - FeatureContext:
            parameters:
              screenshot_dir: '%paths.base%/screenshots'
              #for simplicity when generating the behat.yml file we call the parameters as drupal_root and base_url.
              drupal_root: /app/docroot
              # base_url: http://nbcs.lndo.site:8080/
  extensions:
    Behat\MinkExtension:
      base_url: http://nbcs.lndo.site:8080/
      browser_name: chrome
      goutte: ~
      selenium2:
        wd_host: http://chromedriver:4444/wd/hub
        capabilities: { "browser": "chrome", "version": "*" }
      # Use goutte (basic PHP browser, super fast) as the default driver.
      # default_session: goutte
      # For real browser testing and tests requiring JS use selenium2 driver.
      # Tag features/scenarious with @javascript to use the selenium2 driver.
      # javascript_session: selenium2
    Drupal\DrupalExtension:
      blackbox: ~
      # API driver [drupal|drush]
      api_driver: 'drupal'
      drupal:
        # Site docroot inside Lando.
        drupal_root: /app/docroot
      drush:
        # Site docroot inside Lando.
        root: /app/docroot
        global_options: '--uri=http://nbcs.lndo.site:8080'
      # Map template regions.
      region_map:
        header: "#nbcsports-fixed-header"
        content: "#nbcsports-content-wrapper"
        footer: "#nbcsports-footer"
      # Map selectors.
      selectors:
        message_selector: '.messages'
        warning_message_selector: '.messages.warning'
        error_message_selector: '.messages.error'
        success_message_selector: '.messages.status'

behat command

#!/usr/bin/env bash

## Run project's Behat tests.
##
## Usage: fin behat [--path=path] [arguments]
##
## path defaults to tests/behat

# Environment variables passed from fin:
#
#   $PROJECT_ROOT - (string) absolute path to NEAREST .docksal folder
#   $VIRTUAL_HOST - (string) ex. projectname.docksal
#   $DOCROOT - name of the docroot folder
#   $DOCKER_RUNNING - (string) "true" or "false"

params=''
path='tests/behat'
PROJECT_ROOT='/app/'

echo "$@"

function usage() {
  cat << EOF
  Run this script as:
  fin behat [<commands>] <site>

  VARIABLES
    path          Alternative path to use for finding behat .yml file
    environment   The environment to use for example: qa, dev, stage2, prod. 

  SITE:
    Any of the SKYBOX project: bcsports bayarea boston chicago philadelphia washington

  COMMANDS:
    Any of the behats commands, see http://docs.behat.org/en/v2.5/guides/6.cli.html. --colors will always be used.

  Examples:
    fin behat nbcsports run behat tests for nbcsports
    fin behat --environment=qa nbcsports
    fin behat --environment=qa washigton
    fin behat --format=pretty   Run behat tests with pretty format
    fin behat --format=junit --out=~/Downloads/results.out bayarea Run behats and output the results in ~/Downloads/results.out

  Notes:
    --colors will always be used.
EOF
}

drush_uri="nbcusports15.stage2";
boxenvironment="qa";
for i in "$@"; do
  case "$i" in
    --path=*)
      path="${i#*=}"
      ;;
    bayarea|boston|philadelphia|washington|chicago|nbcsports|csnhub|rsnhub|nbcsports)
      site=$i;
      shift;
      ;;
   --colors)
      #colors will always be included by default, just remove the parameter
      shift;
      ;;
   --environment=*)
      boxenvironment="${i#*=}"
      shift;
      ;;
   -h|--help)
      usage;
      exit 0;
      ;;
    *)
      params="$params$i "
      ;;
  esac;
done

drupal_root="nbcsports.com";
case "$site" in
  --bayarea)
  drush_uri="rsn.csnbayarea.${boxenvironment}";
  drupal_root="csnbayarea"
  ;;
  --boston)
  drush_uri="rsn.csnne.${boxenvironment}";
  drupal_root="csnne"
  ;;
  --philadelphia)
  drush_uri="rsn.csnphilly.${boxenvironment}";
  drupal_root="csnphilly"
  ;;
  --washington)
  drush_uri="rsn.csnma.${boxenvironment}";
  drupal_root="csnma"
  ;;
  --chicago)
  drush_uri="rsn.csnchicago.${boxenvironment}";
  drupal_root="csnchicago"
  ;;
  --northwest)
  drush_uri="rsn.csnnw.${boxenvironment}";
  drupal_root="csnnw"
  ;;
  --csnhub)
  drush_uri="rsn.csnhub.${boxenvironment}";
  drupal_root="csnhub"
  ;;
  --rsnhub)
  drush_uri="rsn.csnhub.${boxenvironment}";
  drupal_root="csnhub"
  ;;
esac;

behat_yml_path="$PROJECT_ROOT/$path/behat.yml";
behat_common_yml_path="$PROJECT_ROOT/$path/behat.common.yml";

cp -f $behat_common_yml_path $behat_yml_path;

# Make sure Composer dependencies are installed
if [[ ! -d "$path/vendor" ]]; then
  cd $PROJECT_ROOT/$path && composer install --prefer-source --no-interaction
fi

if [[ "$site" == "nbcsports" || "$site" == "" ]]; then
  site="nbcs.";
  if [[ "$boxenvironment" == "qa" ]]; then
    drush_uri="nbcusports15.stage2";
  fi
else 
  site="${site}.";
fi 

cd /app/tests/behat && composer install

cd $PROJECT_ROOT;

echo "Running with params: $params";
echo "Running for site ${site}";

cp -f $PROJECT_ROOT/${path}/behat.common.yml $PROJECT_ROOT/${path}/behat.yml
#We need to make some changes in the behat.yml file to be able to run the tests, we will reset it latter.
# Update base url in behat.yml file, set it to our http://nbcs.docksal url (or any custom path defined by your local configuration).
sed -i "s/base_url:.*\$/base_url: http:\/\/${site}lndo.site:8080\//g" $PROJECT_ROOT/${path}/behat.yml
# Update docroot in behat.yml file, set it to our $PROJECT_ROOT/docroot docroot (or any custom path defined by your local configuration).
#sed -i "s/drupal_root:.*\$/drupal_root: \/app\/docroot\/sites\/nbcsports\.com/g" $PROJECT_ROOT${path}/behat.yml
# Update docroot in behat.yml file, set it to our $PROJECT_ROOT/docroot docroot (or any custom path defined by your local configuration).
#sed -i "s/drush_uri:.*\$/drush_uri: $drush_uri/g" $PROJECT_ROOT/${path}/behat.yml
# Launch Behat tests
cd $PROJECT_ROOT/$path && vendor/behat/behat/bin/behat --colors $params

Tell us about the error you got lando behat nbcsports --tags=@some-tag Feature: Confirm media cards functionality

Background: The media card admin form should be accessible # features/Functionalitymy-feature.feature:3 Given I am logged in as a user with the "administrator" role # CustomDrupalContext::assertAuthenticatedByRole() Form field with id|name|label|value|placeholder "Username" not found. (Behat\Mink\Exception\ElementNotFoundException) And I am on "/block/add/media-card" # Drupal\DrupalExtension\Context\MinkContext::visit()


Looks like behat can't connect to selenium server.

**Tell us generally about your bug**
- I run` lado rebuild -y`
- Then run `lando behat <site> <tags>`
- Behat doesn't seem to connect to selenium server
- I also have an `AfterStep` to save screenshots, but the images generated are 0 bytes.

**Tell us more**

It would be useful to have a woking example of a multisite setup working with behat
stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions and please check out this if you are wondering why we auto close issues.