mozilla / geckodriver

WebDriver for Firefox
https://firefox-source-docs.mozilla.org/testing/geckodriver/
Mozilla Public License 2.0
7.19k stars 1.52k forks source link

Behat + Selenium + GeckoDriver - Opens firefox and loads page but cant find content. #1548

Closed Ghostff closed 4 years ago

Ghostff commented 5 years ago

System

Testcase

behat.yml

default:
  autoload:
    '': tests/behat/bootstrap
  suites:
    default:
      paths:
        features: "%paths.base%/tests/behat/"
      contexts:
        - IntegratedExperts\BehatScreenshotExtension\Context\ScreenshotContext
        - BehatContexts\FeatureContext
  extensions:
    Behat\MinkExtension:
      base_url: https://www.wikipedia.org/
      browser_name: chrome
      goutte: ~
      selenium2:
        wd_host: http://127.0.0.1:4444/wd/hub
        browser: chrome
        capabilities:
          marionette: true

firefox:
  extensions:
    Behat\MinkExtension:
      base_url: https://www.wikipedia.org/
      browser_name: firefox
      selenium2:
        wd_host: http://127.0.0.1:4444/wd/hub
        browser: firefox
        capabilities:
          marionette: true

Test feature

@javascript
Scenario: Searching for a page that does exist
  Given I am on "/wiki/Main_Page"
   When I fill in "search" with "Behavior Driven Development"
    And I press "searchButton"
   Then I should see "agile software development"

Stacktrace

starting selenium

java -jar  -Dwebdriver.gecko.driver=tests/behat/drivers/geckodriver -Dwebdriver.chrome.driver=tests/behat/drivers/chromedriver tests/behat/drivers/selenium-server-standalone-3.141.59.jar -log tests/behat/logs/selenium.log > log.txt 2>&1 &

Test attempt output

@javascript
Scenario: Searching for a page that does exist                      # tests/behat/search.feature:8
Given I am on "/wiki/Main_Page"                                 # BehatContexts\FeatureContext::visit()
When I fill in "search" with "Behavior Driven Development"      # BehatContexts\FeatureContext::fillField()

Form field with id|name|label|value|placeholder "search" not found. (Behat\Mink\Exception\ElementNotFoundException)

And the above works for chrome

selenium log

09:08:22.680 INFO [ActiveSessionFactory.apply] - Capabilities are: {
  "browser": "firefox",
  "browserName": "firefox",
  "ignoreZoomSetting": false,
  "marionette": true,
  "name": "Behat feature suite",
  "tags": [
    "localhost.localdomain",
    "PHP 7.2.17"
  ]
}

Trace-level log

whimboo commented 5 years ago

Could you please attach a trace-level log from geckodriver? Read more about reporting actionable bugs in our contribution guidelines.

Ghostff commented 5 years ago

I can really get a trace, i used java -Dwebdriver.gecko.driver=geckodriver >>geckodriver.log 2>>geckodriver.err.log -jar server-standalone-3.141.59.jar

whimboo commented 5 years ago

Not sure how I should parse the last comment. Please read the links I have given in how to create a tracelog which you can attach to this issue then.

maMykola commented 5 years ago

The same problem on OS X Mojave:

geckodriver 0.24.0 firefox 66.0.4 selenium 3.141.59

with chromedriver (74.0.3729.6) works fine chrome 74.0.3729.131

whimboo commented 5 years ago

Sorry, but "me too" comments are pretty much not helpful. Instead, and as requested above please provide trace logs for investigation. Thanks.

Ghostff commented 5 years ago
2019-06-12 08:40:18.926:INFO::main: Logging initialized @270ms to org.seleniumhq.jetty9.util.log.StdErrLog
1560347088072   mozrunner::runner   INFO    Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile.IYfKrAi1FcJ4"
1560347088407   addons.webextension.screenshots@mozilla.org WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1560347088407   addons.webextension.screenshots@mozilla.org WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1560347088408   addons.webextension.screenshots@mozilla.org WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader*
IPDL protocol Error: Received an invalid file descriptor
IPDL protocol Error: Received an invalid file descriptor
1560347089385   Marionette  INFO    Listening on port 45837
IPDL protocol Error: Received an invalid file descriptor
1560347090454   Marionette  INFO    Stopped listening on port 45837
[Parent 3053, Gecko_IOThread] WARNING: pipe error (71): Connection reset by peer: file /builddir/build/BUILD/firefox-66.0.5/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 357
[Parent 3053, Gecko_IOThread] WARNING: pipe error (77): Connection reset by peer: file /builddir/build/BUILD/firefox-66.0.5/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 357
whimboo commented 5 years ago

There are two IPC errors which might cause Firefox to unexpectedly close. Would you mind checking if there are crash reports written to disk? See https://firefox-source-docs.mozilla.org/testing/geckodriver/CrashReports.html for how to do that. Thanks.

Ghostff commented 5 years ago

Am working with Behat PHP I tried asking around if anyone know how i can get the crash report, but none.

andreastt commented 5 years ago

IPC warnings written to the console are not necessarily indicative of a Firefox crash, as the IPC subsystem gets interrupted when Marionette calls Services.startup.quit(eForceQuit) and spews out errors like this.

@Ghostff I would quite like to see a trace-level log in addition to what you posted in https://github.com/mozilla/geckodriver/issues/1548#issuecomment-501280771. Please see https://firefox-source-docs.mozilla.org/testing/geckodriver/geckodriver/TraceLogs.html how to set a capability on moz:firefoxOptions to increase the log level. Alternatively you can start the geckodriver binary with the -vv flag as explained in the documentation.

gregatp commented 5 years ago

The similar problem on macOS Mojave:

Behat output:

  @javascript
  Scenario: Open contact form in selenium                                    # test/behat/features/ffexample.feature:50
    Given I am on the homepage                                               # Drupal\DrupalExtension\Context\MinkContext::iAmOnHomepage()
    And I should see "Contact"                                               # Drupal\DrupalExtension\Context\MinkContext::assertPageContainsText()
      WebDriver\Exception\NoSuchElement: Element not found with xpath, //html
       in vendor/instaclick/php-webdriver/lib/WebDriver/Exception.php:155
      Stack trace:
      #0 vendor/instaclick/php-webdriver/lib/WebDriver/Container.php(89): WebDriver\Exception::factory(7, 'Element not fou...')
      #1 vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php(1012): WebDriver\Container->element('xpath', '//html')
      #2 vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php(524): Behat\Mink\Driver\Selenium2Driver->findElement('//html')
      #3 vendor/behat/mink/src/Element/Element.php(176): Behat\Mink\Driver\Selenium2Driver->getText('//html')
      #4 vendor/behat/mink/src/WebAssert.php(257): Behat\Mink\Element\Element->getText()
      #5 vendor/behat/mink-extension/src/Behat/MinkExtension/Context/MinkContext.php(292): Behat\Mink\WebAssert->pageTextContains('Contact')
      #6 [internal function]: Behat\MinkExtension\Context\MinkContext->assertPageContainsText('Contact')
      #7 vendor/behat/behat/src/Behat/Testwork/Call/Handler/RuntimeCallHandler.php(109): call_user_func_array(Array, Array)
      #8 vendor/behat/behat/src/Behat/Testwork/Call/Handler/RuntimeCallHandler.php(64): Behat\Testwork\Call\Handler\RuntimeCallHandler->executeCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
      #9 vendor/behat/behat/src/Behat/Testwork/Call/CallCenter.php(140): Behat\Testwork\Call\Handler\RuntimeCallHandler->handleCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
      #10 vendor/behat/behat/src/Behat/Testwork/Call/CallCenter.php(96): Behat\Testwork\Call\CallCenter->handleCall(Object(Behat\Behat\Definition\Call\DefinitionCall))

behat.log Marionette-tracelog.log Selenium.log

On Chrome and PhantomJS drivers everything is fine and the scenario passes.

whimboo commented 5 years ago

@gregatpega as the Marionette log shows this is not a problem with geckodriver:

1572470914113   Marionette  DEBUG   0 -> [0,3,"WebDriver:FindElement",{"using":"xpath","value":"//html"}]
1572470914120   Marionette  DEBUG   0 <- [1,3,null,{"value":{"element-6066-11e4-a52e-4f735466cecf":"ecc4f3cf-152d-064f-81be-241696ca2edd"}}]
1572470914121   webdriver::server   DEBUG   <- 200 OK {"value":{"element-6066-11e4-a52e-4f735466cecf":"ecc4f3cf-152d-064f-81be-241696ca2edd"}}

There is clearly an element returned. As such it is a problem with Behat in not interpreting it correctly.

whimboo commented 4 years ago

No further reply from the reporter. Closing the issue.

jonketo commented 4 years ago

I am using webdriver-manager for Chrome and Firefox and noticed differences in behavior between Chrome and Firefox.

webdriver-manager: using global installed version 12.1.7
[16:51:06] I/start - java -Djava.security.egd=file:///dev/./urandom -Dwebdriver.chrome.driver=/usr/lib/node_modules/webdriver-manager/selenium/chromed
river_78.0.3904.105 -Dwebdriver.gecko.driver=/usr/lib/node_modules/webdriver-manager/selenium/geckodriver-v0.26.0 -jar /usr/lib/node_modules/webdriver
-manager/selenium/selenium-server-standalone-3.141.59.jar -port 4444
[16:51:06] I/start - seleniumProcess.pid: 6318
16:51:06.869 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
16:51:07.068 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone Selenium Server on port 4444
2020-01-23 16:51:07.183:INFO::main: Logging initialized @947ms to org.seleniumhq.jetty9.util.log.StdErrLog
16:51:07.683 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
16:51:07.875 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
[16:51:08] I/start - Everything started
[16:51:08] I/start - Detached pid: 6312

While Chrome passed a simple test of finding text with Behat, Firefox did not. The test is:

Feature: Firefox testing
  PoC firefox gecko driver

  @javascript
  Scenario: Pages
    Given I am on "/"
    Then I should see the text "What we do"

I began followed the calls and realized in vendor/instaclick/php-webdriver/lib/WebDriver/Container.php the element() method the call to webDriverElement was returning null

$element = $this->webDriverElement($result['value']);

The json returned from the previous curl call were the following:

Firefox, https://www.unserialize.com/s/2300f6a7-f84b-0148-2249-00003dc30e42 Chrome, https://www.unserialize.com/s/18fd65c4-a4cf-bd08-eaea-000045a218d3

The info array in contains the 'ELEMENT' key in Chrome, but for Firefox a unique id appended. Unsure why, but I guess geckodriver has a reason.

I modified the code in the webDriverElement as follows and now the tests pass.

foreach(array_keys($value) as $key) {
    if (strncasecmp($key, 'element', 7) === 0) {
        return new Element(
            $this->getElementPath($value[$key]), // url
            $value[$key] // id
        ); 
    }
}
return null;

Going to continue further testing. Unsure whether this should be fixed in geckodriver or php-webdriver.

jonketo commented 4 years ago

This was also resolved by making sure instaclick/php-webdriver was set to v1.4.7. https://github.com/instaclick/php-webdriver/blob/b5f330e900e9b3edfc18024a5ec8c07136075712/lib/WebDriver/Container.php#L207

gregatp commented 4 years ago

@jonketo I've updated php-webdriver v1.4.7 and this solved my issue with Firefox. Thank you for your help.

lock[bot] commented 4 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have run into an issue you think is related, please open a new issue.