我一直在尝试使用Behat 3.1,Selenium 3.6和Mink创建一些测试,但均未成功。我不知道如何解决此问题:如果我启动命令php bin/behat
,我的Firefox将启动,但我的站点却无法启动不加载。几分钟后我才得到一个错误:
方案:访问登录页面
鉴于我正在'/ login'
无法打开连接:java.lang.reflect.InvocationTargetException
内部版本信息:版本:'3.6.0',版本:'6fbf3ec767',时间:'2017-09-27T16:15:40.131Z'
系统信息:主机:'xxx.xxx.xxx.xxx',ip:'xxx.xxx.xxx.xxx',操作系统名称:'Mac OS X',os.arch:'x86_64',os.version:' 10.13'',java.version:'1.8.0_72'
驱动程序信息:driver.version:未知(Behat \ Mink \ Exception \ DriverException)
当我按“开始”
然后我应该看到“ einloggen”
我的behat.yml
# behat.yml
default:
autoload: %paths.base%/features/bootstrap
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
base_url: http://myWebsite
default_session: selenium2
selenium2:
browser: firefox
wd_host: http://127.0.0.1:4444/wd/hub
capabilities: { "platform": 'MAC', "browser": 'firefox', "version": '56' }
我的FeatureContext.php
use Behat\Behat\Context\Context;
use Behat\MinkExtension\Context\MinkContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
class FeatureContext extends MinkContext implements Context
{
public function __construct()
{
}
/**
* @Given I am on :arg1
*/
public function iAmOn($arg1)
{
$this->visit($arg1);
}
/**
* @When I press :arg1
*/
public function iPress($arg1)
{
$this->getSession()
->getPage()
->findButton($arg1)
->press();
}
/**
* @Then I should see :arg1
*/
public function iShouldSee($arg1)
{
$this->assertPageContainsText($arg1);
}
}
我的登录功能
Feature: login page
In order to see login contens
As a user
I am able to visit login page
@javascript @login
Scenario: visit login page
Given I am on '/login'
When I press 'Startseite'
Then I should see 'einloggen'
我的GuiContext
use Behat\Behat\Context\BehatContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Mink\Mink,
Behat\Mink\Session,
Behat\Mink\Driver\Selenium2Driver,
Behat\MinkExtension\Context\MinkContext;
use Nearsoft\SeleniumClient as SeleniumClient;
require_once 'PHPUnit/Autoload.php';
require_once 'PHPUnit/Framework/Assert/Functions.php';
class GuiContext extends MinkContext
{
public function __construct(array $parameters)
{
$mink = new Mink(array(
'selenium2' => new Session(new Selenium2Driver($parameters['wd_capabilities']['browser'], $parameters['wd_capabilities'], $parameters['wd_host'])),
));
$this->gui = $mink->getSession('selenium2');
}
/**
* @When /^wait (\d+) seconds?$/
*/
public function waitSeconds($seconds)
{
$this->getSession()->wait(1000*$seconds);
}
}
我读过很多论坛,说实话,我现在很困惑...
我感谢任何帮助!
最好的祝福
伊曼纽尔
更新1:
我尝试以
php bin/behat
开始在命令
php bin/behat -vvv
之后,我收到此错误消息:Emmanuel@Emmanuel-macOS:/Applications/MAMP/htdocs/symfony$ php bin/behat -vvv
Feature: login page
In order to see login contents
As a user
I am able to visit login page
@javascript @login
Scenario: dashboard # features/login.feature:7
Given I am on '/' # FeatureContext::iAmOn()
WebDriver\Exception\SessionNotCreated: Unable to create a new session because of no configuration.
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:40.131Z'
System info: host: 'Emmanuel-macOS.local', ip: '192.168.178.31', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13', java.version: '1.8.0_72'
Driver info: driver.version: unknown in vendor/instaclick/php-webdriver/lib/WebDriver/Exception.php:155
Stack trace:
#0 vendor/instaclick/php-webdriver/lib/WebDriver/AbstractWebDriver.php(157): WebDriver\Exception::factory(33, 'Unable to creat...')
#1 vendor/instaclick/php-webdriver/lib/WebDriver/WebDriver.php(70): WebDriver\AbstractWebDriver->curl('POST', '/session', Array, Array)
#2 vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php(307): WebDriver\WebDriver->session(Array, Array)
#3 vendor/behat/mink/src/Session.php(70): Behat\Mink\Driver\Selenium2Driver->start()
#4 vendor/behat/mink/src/Session.php(145): Behat\Mink\Session->start()
#5 vendor/behat/mink-extension/src/Behat/MinkExtension/Context/RawMinkContext.php(131): Behat\Mink\Session->visit('http://l3ams3/')
#6 vendor/behat/mink-extension/src/Behat/MinkExtension/Context/MinkContext.php(49): Behat\MinkExtension\Context\RawMinkContext->visitPath('/')
#7 features/bootstrap/FeatureContext.php(21): Behat\MinkExtension\Context\MinkContext->visit('/')
#8 [internal function]: FeatureContext->iAmOn('/')
#9 vendor/behat/behat/src/Behat/Testwork/Call/Handler/RuntimeCallHandler.php(104): call_user_func_array(Array, Array)
#10 vendor/behat/behat/src/Behat/Testwork/Call/Handler/RuntimeCallHandler.php(60): Behat\Testwork\Call\Handler\RuntimeCallHandler->executeCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
#11 vendor/behat/behat/src/Behat/Testwork/Call/CallCenter.php(129): Behat\Testwork\Call\Handler\RuntimeCallHandler->handleCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
#12 vendor/behat/behat/src/Behat/Testwork/Call/CallCenter.php(82): Behat\Testwork\Call\CallCenter->handleCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
#13 vendor/behat/behat/src/Behat/Behat/Tester/Runtime/RuntimeStepTester.php(125): Behat\Testwork\Call\CallCenter->makeCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
#14 vendor/behat/behat/src/Behat/Behat/Tester/Runtime/RuntimeStepTester.php(73): Behat\Behat\Tester\Runtime\RuntimeStepTester->testDefinition(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\StepNode), Object(Behat\Behat\Definition\SearchResult), false)
#15 vendor/behat/behat/src/Behat/Behat/Hook/Tester/HookableStepTester.php(74): Behat\Behat\Tester\Runtime\RuntimeStepTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\StepNode), false)
#16 vendor/behat/behat/src/Behat/Behat/EventDispatcher/Tester/EventDispatchingStepTester.php(73): Behat\Behat\Hook\Tester\HookableStepTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\StepNode), false)
#17 vendor/behat/behat/src/Behat/Behat/Tester/StepContainerTester.php(59): Behat\Behat\EventDispatcher\Tester\EventDispatchingStepTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\StepNode), false)
#18 vendor/behat/behat/src/Behat/Behat/Tester/Runtime/RuntimeScenarioTester.php(76): Behat\Behat\Tester\StepContainerTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\ScenarioNode), false)
#19 vendor/behat/behat/src/Behat/Behat/Hook/Tester/HookableScenarioTester.php(74): Behat\Behat\Tester\Runtime\RuntimeScenarioTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\ScenarioNode), false)
#20 vendor/behat/behat/src/Behat/Behat/EventDispatcher/Tester/EventDispatchingScenarioTester.php(103): Behat\Behat\Hook\Tester\HookableScenarioTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\ScenarioNode), false)
#21 vendor/behat/behat/src/Behat/Behat/Tester/Runtime/RuntimeFeatureTester.php(83): Behat\Behat\EventDispatcher\Tester\EventDispatchingScenarioTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\ScenarioNode), false)
#22 vendor/behat/behat/src/Behat/Behat/Hook/Tester/HookableFeatureTester.php(72): Behat\Behat\Tester\Runtime\RuntimeFeatureTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), false)
#23 vendor/behat/behat/src/Behat/Behat/EventDispatcher/Tester/EventDispatchingFeatureTester.php(71): Behat\Behat\Hook\Tester\HookableFeatureTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), false)
#24 vendor/behat/behat/src/Behat/Testwork/Tester/Runtime/RuntimeSuiteTester.php(63): Behat\Behat\EventDispatcher\Tester\EventDispatchingFeatureTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), false)
#25 vendor/behat/behat/src/Behat/Testwork/Hook/Tester/HookableSuiteTester.php(73): Behat\Testwork\Tester\Runtime\RuntimeSuiteTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Testwork\Specification\GroupedSpecificationIterator), false)
#26 vendor/behat/behat/src/Behat/Testwork/EventDispatcher/Tester/EventDispatchingSuiteTester.php(72): Behat\Testwork\Hook\Tester\HookableSuiteTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Testwork\Specification\GroupedSpecificationIterator), false)
#27 vendor/behat/behat/src/Behat/Testwork/Tester/Runtime/RuntimeExercise.php(71): Behat\Testwork\EventDispatcher\Tester\EventDispatchingSuiteTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Testwork\Specification\GroupedSpecificationIterator), false)
#28 vendor/behat/behat/src/Behat/Testwork/EventDispatcher/Tester/EventDispatchingExercise.php(70): Behat\Testwork\Tester\Runtime\RuntimeExercise->test(Array, false)
#29 vendor/behat/behat/src/Behat/Testwork/Ordering/OrderedExercise.php(80): Behat\Testwork\EventDispatcher\Tester\EventDispatchingExercise->test(Array, false)
#30 vendor/behat/behat/src/Behat/Testwork/Tester/Cli/ExerciseController.php(146): Behat\Testwork\Ordering\OrderedExercise->test(Array, false)
#31 vendor/behat/behat/src/Behat/Testwork/Tester/Cli/ExerciseController.php(108): Behat\Testwork\Tester\Cli\ExerciseController->testSpecifications(Object(Symfony\Component\Console\Input\ArgvInput), Array)
#32 vendor/behat/behat/src/Behat/Testwork/Cli/Command.php(63): Behat\Testwork\Tester\Cli\ExerciseController->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#33 vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php(262): Behat\Testwork\Cli\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#34 vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(888): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#35 vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(224): Symfony\Component\Console\Application->doRunCommand(Object(Behat\Testwork\Cli\Command), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#36 vendor/behat/behat/src/Behat/Testwork/Cli/Application.php(121): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#37 vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(125): Behat\Testwork\Cli\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#38 vendor/behat/behat/bin/behat(32): Symfony\Component\Console\Application->run()
#39 {main}
Next Behat\Mink\Exception\DriverException: Could not open connection: Unable to create a new session because of no configuration.
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:40.131Z'
System info: host: 'Emmanuel-macOS.local', ip: '192.168.178.31', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13', java.version: '1.8.0_72'
Driver info: driver.version: unknown in vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php:310
Stack trace:
#0 vendor/behat/mink/src/Session.php(70): Behat\Mink\Driver\Selenium2Driver->start()
#1 vendor/behat/mink/src/Session.php(145): Behat\Mink\Session->start()
#2 vendor/behat/mink-extension/src/Behat/MinkExtension/Context/RawMinkContext.php(131): Behat\Mink\Session->visit('http://l3ams3/')
#3 vendor/behat/mink-extension/src/Behat/MinkExtension/Context/MinkContext.php(49): Behat\MinkExtension\Context\RawMinkContext->visitPath('/')
#4 features/bootstrap/FeatureContext.php(21): Behat\MinkExtension\Context\MinkContext->visit('/')
#5 [internal function]: FeatureContext->iAmOn('/')
#6 vendor/behat/behat/src/Behat/Testwork/Call/Handler/RuntimeCallHandler.php(104): call_user_func_array(Array, Array)
#7 vendor/behat/behat/src/Behat/Testwork/Call/Handler/RuntimeCallHandler.php(60): Behat\Testwork\Call\Handler\RuntimeCallHandler->executeCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
#8 vendor/behat/behat/src/Behat/Testwork/Call/CallCenter.php(129): Behat\Testwork\Call\Handler\RuntimeCallHandler->handleCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
#9 vendor/behat/behat/src/Behat/Testwork/Call/CallCenter.php(82): Behat\Testwork\Call\CallCenter->handleCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
#10 vendor/behat/behat/src/Behat/Behat/Tester/Runtime/RuntimeStepTester.php(125): Behat\Testwork\Call\CallCenter->makeCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
#11 vendor/behat/behat/src/Behat/Behat/Tester/Runtime/RuntimeStepTester.php(73): Behat\Behat\Tester\Runtime\RuntimeStepTester->testDefinition(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\StepNode), Object(Behat\Behat\Definition\SearchResult), false)
#12 vendor/behat/behat/src/Behat/Behat/Hook/Tester/HookableStepTester.php(74): Behat\Behat\Tester\Runtime\RuntimeStepTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\StepNode), false)
#13 vendor/behat/behat/src/Behat/Behat/EventDispatcher/Tester/EventDispatchingStepTester.php(73): Behat\Behat\Hook\Tester\HookableStepTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\StepNode), false)
#14 vendor/behat/behat/src/Behat/Behat/Tester/StepContainerTester.php(59): Behat\Behat\EventDispatcher\Tester\EventDispatchingStepTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\StepNode), false)
#15 vendor/behat/behat/src/Behat/Behat/Tester/Runtime/RuntimeScenarioTester.php(76): Behat\Behat\Tester\StepContainerTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\ScenarioNode), false)
#16 vendor/behat/behat/src/Behat/Behat/Hook/Tester/HookableScenarioTester.php(74): Behat\Behat\Tester\Runtime\RuntimeScenarioTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\ScenarioNode), false)
#17 vendor/behat/behat/src/Behat/Behat/EventDispatcher/Tester/EventDispatchingScenarioTester.php(103): Behat\Behat\Hook\Tester\HookableScenarioTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\ScenarioNode), false)
#18 vendor/behat/behat/src/Behat/Behat/Tester/Runtime/RuntimeFeatureTester.php(83): Behat\Behat\EventDispatcher\Tester\EventDispatchingScenarioTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\ScenarioNode), false)
#19 vendor/behat/behat/src/Behat/Behat/Hook/Tester/HookableFeatureTester.php(72): Behat\Behat\Tester\Runtime\RuntimeFeatureTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), false)
#20 vendor/behat/behat/src/Behat/Behat/EventDispatcher/Tester/EventDispatchingFeatureTester.php(71): Behat\Behat\Hook\Tester\HookableFeatureTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), false)
#21 vendor/behat/behat/src/Behat/Testwork/Tester/Runtime/RuntimeSuiteTester.php(63): Behat\Behat\EventDispatcher\Tester\EventDispatchingFeatureTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), false)
#22 vendor/behat/behat/src/Behat/Testwork/Hook/Tester/HookableSuiteTester.php(73): Behat\Testwork\Tester\Runtime\RuntimeSuiteTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Testwork\Specification\GroupedSpecificationIterator), false)
#23 vendor/behat/behat/src/Behat/Testwork/EventDispatcher/Tester/EventDispatchingSuiteTester.php(72): Behat\Testwork\Hook\Tester\HookableSuiteTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Testwork\Specification\GroupedSpecificationIterator), false)
#24 vendor/behat/behat/src/Behat/Testwork/Tester/Runtime/RuntimeExercise.php(71): Behat\Testwork\EventDispatcher\Tester\EventDispatchingSuiteTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Testwork\Specification\GroupedSpecificationIterator), false)
#25 vendor/behat/behat/src/Behat/Testwork/EventDispatcher/Tester/EventDispatchingExercise.php(70): Behat\Testwork\Tester\Runtime\RuntimeExercise->test(Array, false)
#26 vendor/behat/behat/src/Behat/Testwork/Ordering/OrderedExercise.php(80): Behat\Testwork\EventDispatcher\Tester\EventDispatchingExercise->test(Array, false)
#27 vendor/behat/behat/src/Behat/Testwork/Tester/Cli/ExerciseController.php(146): Behat\Testwork\Ordering\OrderedExercise->test(Array, false)
#28 vendor/behat/behat/src/Behat/Testwork/Tester/Cli/ExerciseController.php(108): Behat\Testwork\Tester\Cli\ExerciseController->testSpecifications(Object(Symfony\Component\Console\Input\ArgvInput), Array)
#29 vendor/behat/behat/src/Behat/Testwork/Cli/Command.php(63): Behat\Testwork\Tester\Cli\ExerciseController->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#30 vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php(262): Behat\Testwork\Cli\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#31 vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(888): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#32 vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(224): Symfony\Component\Console\Application->doRunCommand(Object(Behat\Testwork\Cli\Command), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#33 vendor/behat/behat/src/Behat/Testwork/Cli/Application.php(121): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#34 vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(125): Behat\Testwork\Cli\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#35 vendor/behat/behat/bin/behat(32): Symfony\Component\Console\Application->run()
#36 {main}
When I press 'einloggen' # FeatureContext::iPress()
Then I should see 'Login' # FeatureContext::iShouldSee()
--- Failed scenarios:
features/login.feature:7
1 scenario (1 failed)
3 steps (1 failed, 2 skipped)
0m0.10s (10.17Mb)
最佳答案
我们在Firefox上使用Behat已有很长时间了,我们经常遇到您所描述的问题。有时,我们甚至将Firefox版本降级以能够运行Behat功能。
我们切换到chromedriver,从那以后我们再也没有任何问题(如果在Mac上,请使用brew install chromedriver
安装它)。
这是我们对Behat的配置:
default:
gherkin:
filters:
tags: @mytag
autoload:
'': %paths.base%/bootstrap
extensions:
Behat\MinkExtension:
base_url: https://site.local
goutte:
guzzle_parameters:
verify: false
browser_name: 'chrome'
selenium2:
capabilities: { "browserName": "chrome", "browser": "chrome", 'chrome': {'switches':['--no-sandbox']}}
suites:
mysuite:
paths: [ %paths.base%/features ]
contexts:
- FeatureContext
- GuiContext
如果仍要使用Firefox来与Beele一起运行Behat,请确保您具有最新版本的Selenium Standalone Server http://docs.seleniumhq.org/download/。
另外,考虑将Docker映像与Selenium和安装在其上的浏览器https://hub.docker.com/u/selenium/一起使用,它已预先配置并经过测试可以正常工作。
更新1
使用不带构造函数的GuiContext并扩展RawMinkContext:
class GuiContext extends RawMinkContext
{
/**
* @When /^wait (\d+) seconds?$/
*/
public function waitSeconds($seconds)
{
$this->getSession()->wait(1000*$seconds);
}
}
在功能中指定
@javascript
标记后,Behat将自动切换到硒驱动程序。更新2:
要启动硒,请执行以下命令:
java -jar selenium-server-standalone-3.6.0.jar >& /tmp/selenium.log &
假设3.6.0是从link下载的最新硒版本。
您还可以使用composer要求使用硒服务器:
composer require se/selenium-server-standalone
然后启动它:
/your-project/vendor/bin/selenium-server-standalone
关于php - 如何将Behat 3.1与Selenium 3.6和Mink结合使用?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46788079/