docksal / behat

A self-contained Docker image to run Behat with no external dependencies
34 stars 22 forks source link

Element not found with xpath, //html. Error present even when adding Behat configs suggested online. #15

Closed wah22 closed 3 years ago

wah22 commented 3 years ago

I have a D9 install with Docksal that will run behat, but I get this error:

    Element not found with xpath, //html
           (WebDriver\Exception\NoSuchElement)

I suspect it has to do with my behat configs.

I have done some research online with the error message and there were suggestions to do things like add this to my tests/behat/behat.yml file

        capabilities:
          browser: "chrome"
          version: "*"
          extra_capabilities:
            chromeOptions:
              w3c: false

But this didn't seem to work. I also added this to my docksal.yml file

      browser:
        hostname: browser
        # Pin selenium image to an older version
        # See https://github.com/docksal/docksal/issues/1096#issuecomment-543316840
        image: selenium/standalone-chrome-debug:3.141.59-oxygen
        dns:
          - ${DOCKSAL_DNS1}
          - ${DOCKSAL_DNS2}

I can see online that I should look at the D7 advanced boilerplate code for examples, but I am not sure which part of it is outdated.

What parts of D7 advanced boilerplate behat configs do I need to change if I am running Drupal 9?

Here is my behat.yml file: ( I am assuming that the base_url is the url I use in my browser when I look at the page )

    default:
      autoload:
        '': '%paths.base%/tests/behat/features/bootstrap'
      suites:
        default:
          contexts:
            - Drupal\FeatureContext
            - Drupal\DrupalExtension\Context\DrupalContext
            - Drupal\DrupalExtension\Context\MinkContext
            - Drupal\DrupalExtension\Context\MessageContext
            - Drupal\DrupalExtension\Context\DrushContext
          paths:
            features: '%paths.base%/tests/behat/features'
      extensions:
        Behat\MinkExtension:
          default_session: 'selenium2'
          goutte: ~
          selenium2: ~
          base_url: 'http://myprojectname.docksal'
        Drupal\DrupalExtension:
          blackbox: ~
          api_driver: 'drupal'
          drush:
            alias: 'local'
          drupal:
            drupal_root: '%paths.base%/docroot'

Here is my tests/behat/behat.yml file:

# Docker profile.
# For use inside the CLI container in Docksal.
docker:
  extensions:
    Behat\MinkExtension:
      # URL of the site when accessed inside Docksal.
      base_url: http://myprojectname.docksal
      # Configure browser to be used. Browser must be available on wd_host.
      # Stick with chrome by default. It's 2x faster than firefox or phantomjs (your results may vary).
      browser_name: chrome
      selenium2:
        wd_host: http://browser:4444/wd/hub
        capabilities:
          browser: "chrome"
          version: "*"
          extra_capabilities:
            chromeOptions:
              w3c: false
    Drupal\DrupalExtension:
      drupal:
        # Site docroot inside Docksal.
        drupal_root: /var/www/docroot
      drush:
        # Site docroot inside Docksal.
        root: /var/www/docroot

This is my docksal.yml file:

    version: "2.1"
    services:
      # Web
      web:
        extends:
          file: ${HOME}/.docksal/stacks/services.yml
          service: apache
        depends_on:
          - cli

      # DB
      db:
        extends:
          file: ${HOME}/.docksal/stacks/services.yml
          service: mysql

      # CLI
      cli:
        extends:
          file: ${HOME}/.docksal/stacks/services.yml
          service: cli

      # Browser
      browser:
        hostname: browser
        # Pin selenium image to an older version
        # See https://github.com/docksal/docksal/issues/1096#issuecomment-543316840
        image: selenium/standalone-chrome-debug:3.141.59-oxygen
        dns:
          - ${DOCKSAL_DNS1}
          - ${DOCKSAL_DNS2}

This is my docksal.env file:

    # This is a shared configuration file that is intended to be stored in the project repo.
    # To override a variable locally:
    # - create .docksal/docksal-local.env file and local variable overrides there
    # - add .docksal/docksal-local.env to .gitignore
    #
    # After editing, apply changes with 'fin up'

    # Use the default Docksal LAMP stack
    DOCKSAL_STACK=acquia

    DOCKSAL_DNS1=http://myproject.docksal
    # Lock images versions for LAMP services
    # This will prevent images from being updated when Docksal is updated
    #WEB_IMAGE='docksal/web:x.x-apache2.4'
    DB_IMAGE='docksal/mysql:5.7-1.4'
    #CLI_IMAGE='docksal/cli:x.x-php7.1'

    # Override virtual host (matches project folder name by default)
    #VIRTUAL_HOST=drupal8.docksal
    # Override document root ('docroot' by default)
    DOCROOT="docroot"

    # MySQL settings.
    # MySQL will be exposed on a random port. Use "fin ps" to check the port.
    # To have a static MySQL port assigned, copy the line below into the .docksal/docksal-local.env file
    # and replace the host port "0" with a unique host port number (e.g. MYSQL_PORT_MAPPING='33061:3306')
    MYSQL_PORT_MAPPING='0:3306'

    # Enable/disable xdebug
    # To override locally, copy the two lines below into .docksal/docksal-local.env and adjust as necessary
    XDEBUG_ENABLED=0
lmakarov commented 3 years ago

Dupe of #7. See https://github.com/docksal/behat/issues/7#issuecomment-741550871