lando / pantheon

The Official Lando Pantheon plugin.
https://docs.lando.dev/pantheon
GNU General Public License v3.0
11 stars 18 forks source link

Pantheon + Behat: Curl Error #56

Closed chrisroane closed 2 years ago

chrisroane commented 6 years ago

I'm getting this curl error when I try to run a simple test: https://www.dropbox.com/s/v19nda8c6vsrijw/Screenshot%202018-03-04%2016.44.06.png?dl=0

I searched the issue queue and the web with no luck. I was able to get a simple behat test running in lando using the vanilla drupal7 recipe, but I can't get it to work on this client site.

Here is the command I am using to run this test:

lando behat tests/features/publication.featured-buckets.feature
@node-0 @api @javascript @MEDSTAT @MEDSTAT-PUBLICATION-BUCKETS
Feature: Featured Bucket system should display content properly
  In order to view publications
  As an anonymous user
  I should see correct slot system page

  Scenario: An anonymous user views a top 25 publication # tests/features/publication.featured-buckets.feature:8
    When I visit "/edermatologynews"                     # Drupal\DrupalExtension\Context\MinkContext::assertAtPath()
      Could not open connection: Curl error thrown for http POST to https://nginx:4444/wd/hub/session with params: {"desiredCapabilities":{"browserName":"firefox","version":"9","platform":"ANY","browserVersion":"9","browser":"firefox","name":"Behat feature suite","deviceOrientation":"portrait","deviceType":"tablet","selenium-version":"2.31.0","tags":["e263cdf94b2f","PHP 7.0.27"],"ignoreZoomSetting":false}}

      Failed to connect to nginx port 4444: Connection refused (Behat\Mink\Exception\DriverException)
    │
    ╳  Fatal error: Call to a member function screenshot() on null (Behat\Testwork\Call\Exception\FatalThrowableError)
    │
    └─ @AfterStep # ErrorHandlingContext::printLastResponseOnError()
    Then I should see a ".medstat-overview-page" element #

.lando.yml

recipe: pantheon
config:
  framework: drupal
  site: [site]
  id: [site-id]
  env: dev
  webroot: build
  xdebug: true
services:
  appserver:
    build:
      - "cd $LANDO_MOUNT && composer install"
      - "mkdir -p ~/.drush/site-aliases"
      - "ln -sf /app/drush/medstat.aliases.drushrc.php ~/.drush/site-aliases/medstat.aliases.drushrc.php"
    overrides:
      services:
        environment:
          BEHAT_PARAMS: >-
            {"extensions" : {"Behat\\MinkExtension" : {"base_url" :
            "http://nginx/"}, "Drupal\\DrupalExtension" : {"drush" :   {
            "root":  "/app/build" }}}}
  phpmyadmin:
    type: phpmyadmin
  node:
    type: node:8.4
    build:
      - "cd $LANDO_MOUNT && npm install"
    globals:
      gulp-cli: "latest"
events:
  post-import-db:
    - echo "Obtaining database."
    - bash -c "test -f /app/db/tmp-db.sql.gz || terminus backup:get frontline-med.live --element=db --to=/app/db/tmp-db.sql.gz"
    - echo "Dropping old database."
    - drush @medstat.local sql-drop -y
    - echo "Importing database."
    - bash -c "gunzip -k < /app/db/tmp-db.sql.gz | drush @medstat.local sql-cli"
  post-import-db-fresh:
    - echo "Obtaining database."
    - bash -c "test -f /app/db/fresh-db.sql.gz || terminus backup:get frontline-med.fresh --element=db --to=/app/db/fresh-db.sql.gz"
    - echo "Dropping old database."
    - drush @medstat.local sql-drop -y
    - echo "Importing database."
    - bash -c "gunzip -k < /app/db/fresh-db.sql.gz | drush @medstat.local sql-cli"
  post-local:
    - drush @medstat.local dl registry_rebuild -n
    - drush @medstat.local rr
    - drush @medstat.local cc drush
    - drush @medstat.local en -y master
    - drush @medstat.local master-execute -y --scope=local
    - bash -c "drush @medstat.local updb -y || true"
    - drush @medstat.local fra -y
    - drush @medstat.local cc drush
tooling:
  drush:
    service: appserver
    cmd:
      - "drush"
      - "@medstat.local"
      - "--root=/app/build"
  behat:
    service: appserver
    cmd: /app/vendor/bin/behat
  npm:
    service: node
  node:
    service: node
  gulp:
    service: node
  import-db-fresh:
    description: Import the fresh backup database.
    cmd: true
    service: appserver
  import-db:
    description: Import the live backup database.
    cmd: true
    service: appserver
  local:
    description: Clear drupal caches.
    cmd: true
    service: appserver

behat.yml

default:
  autoload:
    '': '%paths.base%/tests/features/bootstrap'
  gherkin:
    cache: ~
  formatters:
    pretty: true
  suites:
    default:
      paths: [ '%paths.base%/tests/features' ]
      filters:
        tags: ~@wip
      contexts:
        - MedstatFeatureContext
        - MedstatDrupalContext
        - MedstatRestfulContext:
            base_url: 'https://nginx'
            files_path: '%paths.base%/tests/assets'
            api_role: 'api write client'
        - ErrorHandlingContext
        - Drupal\DrupalExtension\Context\MinkContext
        - Drupal\DrupalExtension\Context\MessageContext
        - Drupal\DrupalExtension\Context\DrushContext
  extensions:
    Behat\MinkExtension:
      goutte: ~
      javascript_session: selenium2
      selenium2:
        wd_host: 'https://nginx:4444/wd/hub'
      base_url: 'https://nginx'
      files_path: '%paths.base%/tests/assets'
      sessions:
        default:
          goutte:
            guzzle_parameters:
              verify: false
    Drupal\DrupalExtension:
      blackbox: ~
      api_driver: 'drupal'
      drupal:
        drupal_root: '/app/build'
      drush:
        alias: 'medstat.local'
      selectors:
        message_selector: '.messages'
        error_message_selector: '.messages.error'
        success_message_selector: '.messages.status'
      region_map:
        hidden_nav: '.nav-hidden'
        header: '#header'

Any tips you can give me in helping me get this to work? This is my first time using lando on a client project and I love everything about this project! Thanks for the help.

dustinleblanc commented 6 years ago

Hey @chrisroane!

Wowzers! Those are some heavy duty files!

I've definitely gotten Pantheon/Behat to work in a much simpler setup, but I usually add in Chromedriver or PhantomJS in an extra container to make this work.

This exact thing is going to be our next major focus after we firm up this next release. Aaron Wolfe at Capellic and I have been discussing Behat JS tests a lot lately using Lando and Pantheon and we finally got a dialed setup that uses Chromedriver to handle the control of the browser (so it can access JS and handle sessions). I'd suggest hopping into the #lando channel in our slack instance (https://launchpass.com/kalabox) and pinging @Aaron to discuss. I have a good example for Laravel Dusk which I'll share to give you an idea, but Behat's config is obviously a little different:

https://gist.github.com/dustinleblanc/c49b020419e70f70b40353b3d05a9735

chrisroane commented 6 years ago

@dustinleblanc Thanks for your response.

After many hours in trying to get something to work, I finally came up with a solution that seems to work well. This is what I did:

imports:
  - behat.yml

default:
  suites:
    default:
      contexts:
        - MedstatFeatureContext
        - MedstatDrupalContext
        - MedstatRestfulContext:
            base_url: 'https://192.168.1.17:32811'
            files_path: '%paths.base%/tests/assets'
            api_role: 'api write client'
        - Drupal\DrupalExtension\Context\MinkContext
        - Drupal\DrupalExtension\Context\MessageContext
        - Drupal\DrupalExtension\Context\DrushContext
  extensions:
    Drupal\MinkExtension:
      base_url: 'https://192.168.1.17:32811'
      selenium2:
        wd_host: 'http://192.168.1.17:4444/wd/hub'
        capabilities:
          browser: 'chrome'
          browserVersion: '65.0.3325.146'
          extra_capabilities:
            selenium-version: '3.10.0'
            screenResolution: '1920x1600'
            tz: 'America/New_York'
            recordVideo: 'true'
    Drupal\DrupalExtension:
      drupal:
        drupal_root: '/app/build'
      drush:
        root: '/app/build'
    Bex\Behat\ScreenshotExtension:
      image_drivers:
        local:
          screenshot_directory: /app/tests/behat_screenshots

The only minor annoyance with this is that when I reboot the lando box the ports change + if I change local networks my host computer ip address changes. I tried many different combinations with urls and the only thing I could get work was using the host ip directly.

If you have any ideas in what I could use in my local.behat.yml file to make this work without having to use the host ip + lando port, that would be appreciated.

I'm sure there is a more integrated way I could get this setup using docker compose, and I may play with that again at some point, but this is what we got working for the time being and it seems to work well enough for now. Your laraval example provides some good insight in what I can try next. :)

dustinleblanc commented 6 years ago

Hey @chrisroane

Wow yeah that still looks more complex than I'd want to deal with.

I think the reason you need to use the randomly changing port business is precisely that you aren't using an integrated docker-compose.yml file.

Doing it the way I did adds the chromedriver container to the network of your app, giving both chromedriver and php access to the same internal network being set up by docker compose.

I think if you just refactor that to use the container within a docker-compose file, that gets included in the .lando.yml, you will have all the internal networking magic needed to just use the service hostnames.

aaron-capellic commented 6 years ago

@chrisroane Here are my files. Maybe they will help. behat.yml

#
# behat.yml file for testing on Pantheon.
#
default:
  suites:
    default:
      paths:
        - %paths.base%/features
      contexts:
        - FeatureContext
        - ClientHelperContext
        - ClientContext
        - Drupal\DrupalExtension\Context\DrupalContext
        - Drupal\DrupalExtension\Context\MinkContext
  extensions:
    Behat\MinkExtension:
      files_path: "%paths.base%/features/fixtures/"
      base_url: http://nginx
      browser_name: chrome
      sessions:
        default:
          goutte:
            guzzle_parameters:
              verify: false
        javascript:
          selenium2:
            wd_host: http://chromedriver:4444/wd/hub
    Bex\Behat\ScreenshotExtension:
      image_drivers:
        local:
          screenshot_directory: /app/tmp
          clear_screenshot_directory: false
      screenshot_taking_mode: failed_scenarios
    Drupal\DrupalExtension:
      drupal:
        drupal_root: '/app/web'
      blackbox: ~
      region_map:
        system: '.region-system'
        horizontaltabs: '.horizontal-tabs'
        activetab: '.horizontal-tabs-pane:not(.horizontal-tab-hidden)'
        header: '.top-nav'
        footertop: '.footer-top'
        footerbottom: '.footer-bottom'
      api_driver: 'drupal'

lando.yml

name: client
recipe: pantheon

compose:
  - docker-compose.yml

config:
  framework: drupal8
  env: dev
  site: client
  id: 3913120e-xxxxx-46ce-a987-xxxxx
  web: web
  xdebug: false
events:
  post-db-import:
    - appserver: cd $LANDO_MOUNT && composer install
services:
  appserver:
    extras:
      - "apt-get update"
      - "apt-get install -y apt-utils"
      - "curl -sL https://deb.nodesource.com/setup_6.x | bash"
      - "apt-get install -y nodejs"
      - "npm install --global gulp-cli"
    build:
      - "cd $LANDO_MOUNT && cd web/themes/custom/client/patternlab && composer install"
      - "cd $LANDO_MOUNT && cd web/themes/custom/client && npm install"
      - "cd $LANDO_MOUNT && cd web/themes/custom/client && gulp build"
      - "cd $LANDO_MOUNT && cd web/themes/custom/client && gulp translate"
    overrides:
      services:
        environment:
          BEHAT_PARAMS: >-
            {"extensions" : {"Behat\\MinkExtension" : {"base_url" :
            "http://nginx/", "files_path" : "/app/web/tests/features/fixtures/"}, "Drupal\\DrupalExtension" : {"drush" :   {
            "root":  "/app/web" }}}}
          CI_ENV: ci-${CIRCLE_BUILD_NUM}
          PANTHEON_SITE: ${TERMINUS_SITE}
          CIRCLE_BRANCH: ${CIRCLE_BRANCH}
          CIRCLE_USERNAME: ${CIRCLE_USERNAME}
          GIT_EMAIL: ${GIT_EMAIL}
tooling:
  phplint:
    service: appserver
    cmd: /app/vendor/bin/phplint
  phpcs:
    service: appserver
    cmd: /app/vendor/bin/phpcs
  phpunit:
    service: appserver
    cmd: /app/vendor/bin/phpunit
  behat:
    service: appserver
    cmd: /app/vendor/bin/behat

docker-compose.yml

version: '3'

services:
  chromedriver:
    image: robcherry/docker-chromedriver:latest
    volumes:
      - ${LANDO_APP_ROOT}/:/app/
    expose:
      - "4444"
    environment:
      CHROMEDRIVER_WHITELISTED_IPS: ""
      CHROMEDRIVER_URL_BASE: "/wd/hub"
    security_opt:
      - seccomp:unconfined
chrisroane commented 6 years ago

Thanks everyone! I'll give this a shot this week. This is all great. This clears up some things in using docker compose that I couldn't figure out from the docs. But I'm a docker noob and might be missing some basic info. :)

dustinleblanc commented 6 years ago

Awesome @chrisroane! Join us in the slack instance, its a great place to fire off some questions and share ideas as you go.

brooke-heaton commented 5 years ago

I'm getting a similar error when trying to run Behat to reach the url of one of my multisites. I'm hosted on Acquia not Pantheon. My local does not use nginx so I'm not sure what my base_url should be.

Given I am on "/"                           # Drupal\DrupalExtension\Context\MinkContext::visit()
      GuzzleHttp\Exception\ConnectException: cURL error 7: Failed to connect to naswa.lndo.site port 443: Connection refused (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in /app/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:185
dustinleblanc commented 5 years ago

@brooke-heaton with no nginx the appserver is typically your serving container, so http://appserver is a good assumption. Since you have Multi-site, that's probably going to screw with things in a big way.