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 #7

Closed stevenlafl closed 3 years ago

stevenlafl commented 5 years ago

I'm not certain what is the problem here, considering this is inside a container. Just using it as-is I can't run the example that comes with it.

    Given I am on "http://getbootstrap.com/"                                                                                                                                                                                       # Drupal\DrupalExtension\Context\MinkContext::visit()
    Then I should see text matching "Bootstrap is an open source toolkit for developing with HTML, CSS, and JS. Quickly prototype your ideas or build your entire app with our Sass variables and mixins, responsive grid system." # Drupal\DrupalExtension\Context\MinkContext::assertPageMatchesText()
      Element not found with xpath, //html
       (WebDriver\Exception\NoSuchElement)
stevenlafl commented 5 years ago

This may be due to https://github.com/minkphp/Mink/issues/778 and https://github.com/Behat/MinkExtension/issues/312 and the solution in https://github.com/jhedstrom/drupalextension/issues/535 is to reflect behat.yml:

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

This fixes this error. I suspect it is due to using selenium/standalone-chrome without a version number.

Now I get Unable to complete AJAX request. (RuntimeException) which is a separate error. Still tracking down information.

stevenlafl commented 5 years ago

https://medium.com/@alex.designworks/chromedriver-75-enforces-w3c-standard-breaking-behat-tests-460cad435545

@lmakarov Combining these two and using "selenium/standalone-chrome:3.141.59-oxygen" specifically works. A note about this might be cool for the readme. These were recent changes by selenium and break lots of packages across the github and the web.

stevenlafl commented 5 years ago

Side note, updating to "emuse/behat-html-formatter": "0.2.*", eliminates the count() errors.

lmakarov commented 5 years ago

@stevenlafl I have not used Behat in a while. If you submit a PR with the fix, I can review and accept it.

aczietlow commented 5 years ago

After a couple evenings of digging into this further I had some success passing the following the chrome driver configuration while using the latest selenium docker image.

        extra_capabilities:
          chromeOptions:
            args: ['--headless', '--disable-gpu']
            w3c: false

One thing worth mentioning that when following the docksal docs and installing behat via a separate composer.json file while testing Drupal 8 will throw errors. Behat will install a different version of "symfony/translation" than Drupal 8.7 and will throw fatal errors whenever the Drupal extension attempts to bootstrap Drupal.

Error: Undefined class constant 'INTL_DOMAIN_SUFFIX' in /var/www/tests/behat/vendor/symfony/translation/Translator.php on line 251 #0 /var/www/tests/behat/vendor/behat/behat/src/Behat/Behat/Output/Node/Printer/CounterPrinter.php(72): Symfony\Component\Translation\Translator->transChoice('scenarios_count', 0, Array, 'output')

I worked around this by forcing behat to use the same dependencies as my Drupal 8 site.

{
    "require-dev": {
        "bex/behat-screenshot": "^1.2",
        "drupal/drupal-extension": "~3.4",
        "emuse/behat-html-formatter": "0.2.*",
        "symfony/config": "3.4.26",
        "symfony/console": "3.4.26",
        "symfony/dom-crawler": "3.4.26",
        "symfony/finder": "3.4.26",
        "symfony/filesystem": "3.4.26",
        "symfony/translation": "3.4.26"
    },
    "config": {
        "bin-dir": "bin/"
    }
}

Once this Chrome driver issue stabilizes across dependencies, I'll be happy to make a PR against the docksal doc repo.

lmakarov commented 5 years ago

@aczietlow that for the PR!

I wonder if we should also have the selenium image pinned as mentioned in the article @stevenlafl shared above:

UPDATE

After more investigation it appeared that another issue now presented itself: clicking elements triggers errors like

“ Webdriver http error: 400, payload :{“value”:{“error”:”invalid argument”,”message”:”invalid argument: missing command parameters”,”stacktrace”:”#0 0x5601240ee299 \u003Cunknown>\n”}} (WebDriver\Exception\CurlExec)”

So far, the only way to overcome this is to stick to the selenium/standalone-chrome:3.141.59-oxygen image.

aczietlow commented 5 years ago

I'm seeing the same error when running the selenium/standalone-chrome-debug:3.141.59-oxygen. Investigating further and will update the PR when I find a solution.

wundo commented 5 years ago

hi @aczietlow any update?

aczietlow commented 5 years ago

I'm still not having much luck. I've tested multiple configurations using selenium/standalone-chrome:3.141.59-oxygen selenium/standalone-chrome-debug:3.141.59-oxygen and selenium/standalone-chrome:latest`

I'm currently experimenting with Drupal Extensions 4 as it just got a stable release. A couple notes about that.

There's a new ajax_timeout behat parameter https://github.com/jhedstrom/drupalextension/pull/467/files

I'm still seeing the following error, as well as some other new ones.

@BeforeStep # Drupal\DrupalExtension\Context\MinkContext::beforeJavascriptStep() 

Unable to complete AJAX request. {"name":"step.before","feature":"Getbootstrap smoke testing","step":"I follow \"Get started\"","suite":"default"} (RuntimeException)

I'll update the PR when I find a stable build of behat on the Selenium images.

brooke-heaton commented 4 years ago

ughhh. I'm getting this as well on a Lando machine. Same exact BeforeStep error. Using selenium/standalone-chrome:3.141.59-oxygen and drupal-extension ~4. :(


  Scenario: Create a conference page with all fields                      # features/naswa/release/ContentEditing/ConferenceFields.feature:7
    Given I am logged in as user "bheaton@naswa.org"                      # Drupal\FeatureContext::iAmLoggedInAsUser()
    Given I am on "/node/add/conference"                                  # Drupal\DrupalExtension\Context\MinkContext::visit()
    ┌─ @BeforeStep # Drupal\DrupalExtension\Context\MinkContext::beforeJavascriptStep()
    │
    ╳  RuntimeException: Unable to complete AJAX request. {"name":"step.before","feature":"Conference","step":"I click the \"Primary Info\" tab","suite":"default"} in /app/vendor/drupal/drupal-extension/src/Drupal/DrupalExtension/Context/MinkContext.php:172
    ╳  Stack trace:
brooke-heaton commented 4 years ago

I've stopped experimenting with the Drupal Extension v4. Nevertheless despite the following configuration and using Drupal Extension v3 I'm still getting WebDriver\Exception\NoSuchElement: Element not found with xpath, //html I don't know why.

    Behat\MinkExtension:
      base_url: https://naswa.lndo.site/
      files_path: %paths.base%/files
      browser_name: chrome
      sessions:
        default:
          goutte:
            guzzle_parameters:
              verify: false
        javascript:
          selenium2:
            capabilities:
              browser: "chrome"
              version: "*"
              marionette: true
              extra_capabilities:
                chromeOptions:
                  w3c: false
                  args: ['--headless', '--disable-gpu']
            wd_host: http://chromedriver:4444/wd/hub

Lando chromedriver service:

chromedriver:
    type: compose
    services:
      image: selenium/standalone-chrome:3.141.59-oxygen
      expose:
        - "4444"
      environment:
        CHROMEDRIVER_WHITELISTED_IPS: ""
        CHROMEDRIVER_URL_BASE: "/wd/hub"
      security_opt:
        - seccomp:unconfined
      command: ["/usr/local/bin/supervisord", "-c", "/etc/supervisord.conf"]
stevenlafl commented 4 years ago

@brooke-heaton I've followed your comments across a couple threads relating to this that I had also posted in earlier. It looks like you followed a similar path trying as I did in trying to figure this out.

I also had the problem above and, like you, decided to stop. Sorry we couldn't be of more help. If I get some more time to look at it later, ultimately I would also like to see the solution.

[rant] At what point does this become a gigantic waste of time?

Literally all we want to do is run Behat with Selenium in a Docker container and use it for a Drupal project. Is that use case so absurd that the 5 of us are the only ones trying to do it? If not, surely others would have had this issue. [/rant]

krishnanashok commented 4 years ago

Running into the same issue and this is my setup { "require": { "behat/behat": "~3.0", "behat/mink-goutte-driver": "~1.2.0", "behat/mink-extension": "~2.1", "behat/mink-selenium2-driver": "~1.3", "drupal/drupal-extension": "~3.1", "emuse/behat-html-formatter": "^0.2.0" } }

brooke-heaton commented 4 years ago

@stevenlafl I dunno. I'm on Day 4 now. Just this. Only this. It's such a ginormous time suck. Many threads hint at solutions but I'm stuck for some reason.

brooke-heaton commented 4 years ago

@stevenlafl I guess the only added value of me being here is that it's not just Docksal, this is likely hitting anyone with a combination of behat/mink-extension and a chromedriver and settings that just throw up like this. we all need a beer.

brooke-heaton commented 4 years ago

@stevenlafl @aczietlow some recent edits to behat/selenium2-driver seem to offer clues. For instance: https://github.com/minkphp/MinkSelenium2Driver/commit/3d37a5dd09c044a3d7407d9e85331da7e7b6f8a9

drubage commented 4 years ago

I was also seeing this issue with some behat testing I was doing outside of Docksal. I switched the selenium/selenium-standalone image to selenium/standalone-chrome:3.141.59-oxygen and it worked. Seems some recent updates to that project were causing my issue, not sure if it's the same issue here.

https://medium.com/@alex.designworks/chromedriver-75-enforces-w3c-standard-breaking-behat-tests-460cad435545

brooke-heaton commented 4 years ago

@drubage I'm using the selenium/standalone-chrome:3.141.59-oxygen image and am still getting this issue. I don't know why.

brooke-heaton commented 4 years ago

@drubage would you be able to share your behat.yml config? Also, any specific other settings on the chromedriver container?

drubage commented 4 years ago

My behat.yml looks like this:

default: suites: default: contexts:

Then I am passing in this for the BEHAT_PARAMS environment variable:

{"extensions":{"Behat\\MinkExtension":{"goutte":null,"default_session":"selenium2","javascript_session":"selenium2","base_url":"https://www.yourwebsite.com","browser_name":"chrome","selenium2":{"wd_host":"http://localhost:4444/wd/hub","capabilities":{"browser":"chrome","version":"*"}}},"Drupal\\DrupalExtension":{"blackbox":null}}}

We are using blackbox to test an external site, not the full Drupal Extension capabilities if that makes sense. You need to replace "https://www.yourwebsite.com" with your website's URL of course.

I hope that helps!

brooke-heaton commented 4 years ago

@drubage are you running @javacript tests?

drubage commented 4 years ago

So far we've just been trying to get it to work at all like you were so our tests are for stuff like loading the homepage and logging in, for example:

`Feature: Login Test for Valid and Invalid User In order for the website to function properly As a user with credentials I need to be able to log in to the website

@basic-login--invalid Scenario: Failed Login Attempt Given I am on "/user" Then I pause 2 seconds Then I should see "Log In" When I fill in "name" with "admin" And I fill in "pass" with "admin2" Then I press "op" Then I should see "Unrecognized username or password." Then I take a screenshot named "login-successful-fail"

@basic-login--valid Scenario: Passed Login Attempt Given I am on "/user" Then I pause 2 seconds Then I should see "Log In" When I fill in "name" with "admin" And I fill in "pass" with "admin" Then I press "op" Then I pause 2 seconds Then I should not see "Unrecognized username or password." Then I take a screenshot named "login-successful-pass"`

brooke-heaton commented 4 years ago

@drubage unless you are using js tests, I don't think this issue will be triggered. I have the same setup. All js tests fail.

drubage commented 4 years ago

The issue I was referring to was:

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

Switching to selenium/standalone-chrome:3.141.59-oxygen everything started working. What I saw was that the getHtml() function returned nothing. getContent() worked but Mink uses getHtml() for everything.

brooke-heaton commented 4 years ago

I'm on selenium/standalone-chrome:3.141.59-oxygen and can't get past that error. I don't know why.

brooke-heaton commented 4 years ago

in my .lando.yml

  chromedriver:
    type: compose
    services:
      image: selenium/standalone-chrome:3.141.59-oxygen
      expose:
        - "4444"
      environment:
        CHROMEDRIVER_WHITELISTED_IPS: ""
        CHROMEDRIVER_URL_BASE: "/wd/hub"
      security_opt:
        - seccomp:unconfined
      command: ["/usr/local/bin/supervisord", "-c", "/etc/supervisord.conf"]

my behat.yml

  extensions:
    DMore\ChromeExtension\Behat\ServiceContainer\ChromeExtension: ~
    Behat\MinkExtension:
      # Default configuration has this commented out so it can be overidden.
      base_url: https://naswa.lndo.site/
      files_path: %paths.base%/files
      browser_name: chrome
      javascript_session: javascript
      sessions:
        default:
          goutte:
            guzzle_parameters:
              verify: false
        javascript:
          selenium2:
            wd_host: http://drupal.localhost:4444/wd/hub
            capabilities:
              marionette: true
              browser: chrome
              extra_capabilities:
                chromeOptions:
                  args: ['--headless', '--disable-gpu']
                  w3c: false
brooke-heaton commented 4 years ago

Nothing stands out.

marcelovani commented 4 years ago

This may be due to minkphp/Mink#778 and Behat/MinkExtension#312 and the solution in jhedstrom/drupalextension#535 is to reflect behat.yml:

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

This fixes this error. I suspect it is due to using selenium/standalone-chrome without a version number.

Now I get Unable to complete AJAX request. (RuntimeException) which is a separate error. Still tracking down information.

This is the solution I have been looking for :)

brooke-heaton commented 4 years ago

@marcelovani yep, I assume the Unable to complete AJAX request error is due to iWaitForAjaxToFinish() failing in the Drupal Extension.

marcusanderss commented 4 years ago

I have encountered the same problem now using behat on windows 10; javascripts simply won't work. "Element not found with xpath, //html (WebDriver\Exception\NoSuchElement)". But running in php mode using goutte is fine. However some features are not supported by goutte e.g "add to shopping cart"... Maybe I should switch back to junit4/cucumber?

marcusanderss commented 4 years ago

Another guy tracked down the problem and was able to 'fix' it by inserting the following 3 lines at the start of the webDriverElement function in Behat, vendor/instaclick/php-webdriver/lib/WebDriver/Container.php: protected function webDriverElement($value)

{ if (!array_key_exists('ELEMENT', $value)) { $value['ELEMENT'] = $value['element-6066-11e4-a52e-4f735466cecf']; }

Source: https://tracker.moodle.org/browse/MDL-66378

AntoscencoVladimir commented 4 years ago

Another guy tracked down the problem and was able to 'fix' it by inserting the following 3 lines at the start of the webDriverElement function in Behat, vendor/instaclick/php-webdriver/lib/WebDriver/Container.php:

protected function webDriverElement($value) { if (!array_key_exists('ELEMENT', $value)) { $value['ELEMENT'] = $value['element-6066-11e4-a52e-4f735466cecf']; }

Source: https://tracker.moodle.org/browse/MDL-66378

Thanks, working for me ...

marcusanderss commented 4 years ago

I use chromedriver version 78.0.3904.105 and selenium 3.141.159 plus the above fix on a windows 10 machine.

marlodboro commented 4 years ago

Can anyone help me with my error? I'm trying to incorporate a test verifying a .XML page. Has anyone had experience checking a .XML page instead of .HTML?


    Then I am on "/sitemap.xml"                 # FeatureContext::visit()
    And I should not see "invalid sitemap file" # FeatureContext::assertPageNotContainsText()
      Element not found with xpath, //html

      no such element: Unable to locate element: {"method":"xpath","selector":"//html"}
        (Session info: chrome=73.0.3683.75)
        (Driver info: chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),platform=Linux 4.14.116-boot2docker x86_64) (WebDriver\Exception\NoSuchElement)```
lmakarov commented 3 years ago

I got example tests in this repo passing on my Mac in Docker Desktop after updating Behat and pinning Selenium to selenium/standalone-chrome-debug:3.141.59.

However, tests would fail with the dreaded Element not found with xpath, //html error on Travis CI.

After testing this with VNC on a local Ubuntu VM I noticed that the issue was with Behat hitting Selenium before it was fully initialized. Adding a 5s delay after the docker-compose stack start fixed the issue.

See #16 and https://github.com/docksal/behat/pull/16/commits/388a01ece4bc76113df69cbff6733f8c124bcf26 in particular.

Tests running greed on Travis - https://travis-ci.com/github/docksal/behat/builds/207409190

Hope this solves this issues for good.