Mink / behat javascript错误未找到简单场景的元素

问题描述 投票:0回答:1

您能帮我吗?

我对简单的场景Gerkins找不到问题的字段有问题

找不到具有id | name | label | value |占位符“ searchform-search”的表单字段。 (Behat \ Mink \ Exception \ ElementNotFoundException)

但是硒会正确发射铬。我使用水貂/ behat symfony,selecium和chrome-driver。

例如,我的场景我使用https://hotexamples.com/

behat.yml

default:
autoload:
    - "%paths.base%/tests/api/bootstrap"

extensions:
    Behat\Symfony2Extension:
        kernel:
            bootstrap: tests/api/bootstrap/bootstrap.php
            class: App\Kernel
    Behat\MinkExtension:
        base_url: https://hotexamples.com
        goutte: ~
        selenium2: ~
        browser_name: chrome

suites:
    default:
        contexts:
            - Context\FeatureContext:
                kernel: '@kernel'
        paths: [ "%paths.base%/tests/api", "%paths.base%/tests/behat"]

FeatureContext:

  <?php

declare(strict_types=1);

namespace Context;

use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\MinkExtension\Context\MinkContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\KernelInterface;

/**
 * This context class contains the definitions of the steps used by the demo
 * feature file. Learn how to get started with Behat and BDD on Behat's website.
 *
 * @see http://behat.org/en/latest/quick_start.html
 */
class FeatureContext extends MinkContext implements Context, SnippetAcceptingContext
{
    /**
     * @var KernelInterface
     */
    private $kernel;

    /**
     * @var Response|null
     */
    private $response;

    public function __construct(KernelInterface $kernel)
    {
        $this->kernel = $kernel;
    }

     /**
     * @Given I wait for the page to be loaded
     */
    public function iWaitForThePageToBeLoaded()
    {
        $this->getSession()->wait(5000, "document.readyState === 'complete'");
    }


    /**
     * @Given I wait :time seconds
     */
    public function iWaitSeconds(int $time)
    {
        sleep($time);
    }

}

场景:

  Feature: TestBehat

  @javascript @api
  Scenario: Search
    Given I am on the homepage
    When I fill in "searchform-search" with "behat"

composer.json

"require-dev": {
    "behat/behat": "^3.5",
    "behat/mink": "~1.7@dev",
    "behat/mink-browserkit-driver": "^1.3",
    "behat/mink-extension": "^2.3",
    "behat/mink-goutte-driver": "^1.2",
    "behat/mink-selenium2-driver": "^1.3",
    "behat/symfony2-extension": "^2.1",
    "behatch/contexts": "^3.2",
    "doctrine/instantiator": "^1.3",
    "hautelook/alice-bundle": "^2.5",
    "nikic/php-parser": "^4.3",
    "phpstan/phpstan": "^0.12.3",
    "phpunit/phpunit": "^8.5",
    "symfony/maker-bundle": "^1.11",
    "symfony/var-dumper": "4.2.*"
}

和控制台的输出

   vendor/bin/behat 
Feature: TestBehat

  @javascript @api
  Scenario: Search                                  # tests/behat/authentication.feature:4
12:09:24.452 INFO [ActiveSessionFactory.apply] - Capabilities are: {
  "browser": "firefox",
  "browserName": "chrome",
  "ignoreZoomSetting": false,
  "name": "Behat feature suite",
  "tags": [
    "debian",
    "PHP 7.3.12-1+0~20191128.49+debian9~1.gbp24559b"
  ]
}
12:09:24.453 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
Starting ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@{#614}) on port 31246
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
12:09:24.796 INFO [ProtocolHandshake.createSession] - Detected dialect: W3C
12:09:24.797 INFO [RemoteSession$Factory.lambda$performHandshake$0] - Started new session db80a68bb2beb001693480d14ffa7b1f (org.openqa.selenium.chrome.ChromeDriverService)
    Given I am on the homepage                      # Context\FeatureContext::iAmOnHomepage()
    When I fill in "searchform-search" with "behat" # Context\FeatureContext::fillField()
      Form field with id|name|label|value|placeholder "searchform-search" not found. (Behat\Mink\Exception\ElementNotFoundException)

--- Scénarios échoués:

    tests/behat/authentication.feature:4

1 scénario (1 échecs)
2 étapes (1 succès, 1 échecs)
0m2.11s (19.49Mb)
12:09:26.573 INFO [ActiveSessions$1.onStop] - Removing session db80a68bb2beb001693480d14ffa7b1f (org.openqa.selenium.chrome.ChromeDriverService)

谢谢

symfony google-chrome behat mink
1个回答
0
投票

通过使用貂皮更改chrome选项的配置文件解决的问题

默认:

autoload:
    - "%paths.base%/tests/api/bootstrap"

calls:
    error_reporting: 16383 # E_ALL & ~E_USER_DREPRECATED

extensions:
    Behat\Symfony2Extension:
        kernel:
            bootstrap: tests/api/bootstrap/bootstrap.php
            class: App\Kernel
    Behat\MinkExtension:
        browser_name: chrome
        base_url: 'http://127.0.0.1:8080/'
        goutte: ~
        selenium2: ~
        sessions:
            default:
              selenium2:
                capabilities:
                  extra_capabilities:
                    chromeOptions:
                      args:
                        - "--disable-gpu"
                        - "--window-size=1920,1080"
                      w3c: false

suites:
    default:
        contexts:
            - Context\FeatureContext:
                kernel: '@kernel'
        paths: [ "%paths.base%/tests/api", "%paths.base%/tests/behat"]
© www.soinside.com 2019 - 2024. All rights reserved.