phptestingbehatminkselenium-server

How I am able to use Behat 3.1 with Selenium 3.6 and Mink?



I've been trying unsuccessfully to creat some tests with Behat 3.1, Selenium 3.6 and Mink... I have not any idea how I am able to solve this problem: If I fire the command php bin/behat my Firefox starts but my site doesn't load. I just get an error after some minutes:

Scenario: visit login page
Given I am on '/login'
Could not open connection: java.lang.reflect.InvocationTargetException

Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:40.131Z'

System info: host: 'xxx.xxx.xxx.xxx', ip: 'xxx.xxx.xxx.xxx', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13', java.version: '1.8.0_72'

Driver info: driver.version: unknown (Behat\Mink\Exception\DriverException)

When I press 'Startseite'
Then I should see 'einloggen'

My 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' }

My 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);
    }
}

My login.feature

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'

My 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);
        }
    }

I have read lot of forums and honestly I am just confused now...

I am thankful to any kind of help!

best regards Emmanuel

Update 1:

I tried to start my behat with php bin/behat after the command php bin/behat -vvvI got this error msg:

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)

Solution

  • We've been using Behat with Firefox for quite long time and we constantly had issues like you described. Sometimes we even downgraded Firefox version to be able to run Behat features.

    We switched to chromedriver and since then we never had any issues (if you on Mac, install it with brew install chromedriver). Here is our configuration for 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
    

    If you still want to use Firefox to be able to run Behat with Selenium, make sure you have the latest version of Selenium Standalone Server http://docs.seleniumhq.org/download/.

    Also, consider using Docker images with Selenium and browser installed on it https://hub.docker.com/u/selenium/, it is preconfigured and tested to be working.

    UPDATE 1

    Use your GuiContext without constructor and extend RawMinkContext:

    class GuiContext extends RawMinkContext
    {
        /**
         * @When /^wait (\d+) seconds?$/
         */
        public function waitSeconds($seconds)
        {
            $this->getSession()->wait(1000*$seconds);
        }
    }
    

    Once you specify @javascript tag in your feature, Behat will automatically switch to selenium driver.

    UPDATE 2:

    To start selenium execute the command:

    java -jar selenium-server-standalone-3.6.0.jar >& /tmp/selenium.log &
    

    Assuming 3.6.0 is the latest version of selenium downloaded from link. You can also require selenium server using composer:

    composer require se/selenium-server-standalone
    

    And then start it:

    /your-project/vendor/bin/selenium-server-standalone