Mink / behat JavaScript 错误找不到简单场景的元素



你能帮我吗?

我对找不到错误字段的简单场景 gerkins 有问题

未找到带有 id|名称|标签|值|占位符"搜索表单搜索"的表单字段。(Behat\Mink\Exception\ElementNotFoundException(

但是Selecium正确地启动了Chrome。 我使用mink/behat symfony,selecium,chrome-driver。

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

贝哈特·

default:
autoload:
- "%paths.base%/tests/api/bootstrap"
extensions:
BehatSymfony2Extension:
kernel:
bootstrap: tests/api/bootstrap/bootstrap.php
class: AppKernel
BehatMinkExtension:
base_url: https://hotexamples.com
goutte: ~
selenium2: ~
browser_name: chrome
suites:
default:
contexts:
- ContextFeatureContext:
kernel: '@kernel'
paths: [ "%paths.base%/tests/api", "%paths.base%/tests/behat"]

功能上下文:

<?php
declare(strict_types=1);
namespace Context;
use BehatBehatContextContext;
use BehatBehatContextSnippetAcceptingContext;
use BehatMinkExtensionContextMinkContext;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentHttpKernelKernelInterface;
/**
* 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"

作曲家.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                      # ContextFeatureContext::iAmOnHomepage()
When I fill in "searchform-search" with "behat" # ContextFeatureContext::fillField()
Form field with id|name|label|value|placeholder "searchform-search" not found. (BehatMinkExceptionElementNotFoundException)
--- 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)

谢谢

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

违约:

autoload:
- "%paths.base%/tests/api/bootstrap"
calls:
error_reporting: 16383 # E_ALL & ~E_USER_DREPRECATED
extensions:
BehatSymfony2Extension:
kernel:
bootstrap: tests/api/bootstrap/bootstrap.php
class: AppKernel
BehatMinkExtension:
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:
- ContextFeatureContext:
kernel: '@kernel'
paths: [ "%paths.base%/tests/api", "%paths.base%/tests/behat"]

相关内容

最新更新