4

Edit: thanks to mykbas's answer, I got my system up and running! I've written a pretty thorough how-to for any Mac users that would like a step-by-step, including options for using Docker containers :)


I've looked and looked, and I'm not finding this precise question anywhere, so I'm going to go ahead and ask... I'm pretty new to programming, so I'm not sure what info is obvious/redundant and what info is crucial. I'll try to err on the side of too much.

My ultimate goal is to be able to write and run Behat tests on my Mac for websites that use javascript. If I'm completely on the wrong track, please feel free to send me in another direction.

I'm trying to follow a BDD, Behat, Mink and other Wonderful Things tutorial. It was going well until we got to the part involving Selenium.

I'm running Mac OS 10.12.6

I used composer to install Behat and some extensions,

composer require behat/mink-extension behat/mink-goutte-driver
behat/mink-selenium2-driver facebook/webdriver

(As I type this, I'm realizing that part of my problem might be that I'm trying to use a Selenium 2 driver to drive Selenium 3... minkphp/MinkSelenium2Driver: Selenium 3 support #254 Ugh. Should I go download the most recent version of Selenium 2? Except I read something about Selenium 2 not supporting recent versions of browsers, which would be a bummer since they all auto update to the most recent version on my computer...)

I downloaded Selenium Standalone Server 3.8.1 and stuck it in ~/Applications. It's not in my $PATH, but since I'm calling it directly I figured it doesn't need to be.

I also downloaded chromedriver and geckodriver and put them in /usr/local/bin/, which is in my $PATH.

$ ./behat --version
behat version 3.4.3

$ chromedriver --version
ChromeDriver 2.34.522932 (4140ab217e1ca1bec0c4b4d1b148f3361eb3a03e)

$ geckodriver --version
geckodriver 0.19.1

(At this point I'm just googling and downloading anything that sounds applicable and hoping that something works... :sigh: )

As far as browser versions go, I have:

  • Chrome Version 63.0.3239.84 (Official Build) (64-bit)
  • Firefox Quantum Version 63.0.3239.84 (Official Build) (64-bit)
  • Safari Version 11.0.2 (12604.4.7.1.4)

I would be delighted if Behat could successfully talk to any of the above.

My behat.yml contains:

default:
  extensions:
    Behat\MinkExtension:
      base_url: http://127.0.0.1:8000/
      goutte: ~
      selenium2:
        wd_host: 127.0.0.1:4444/wd/hub

My FeatureContext.php contains:

<?php

use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkContext;

/**
 * Defines application features from the specific context.
 */
class FeatureContext extends MinkContext implements Context, SnippetAcceptingContext
{
    /**
     * Initializes context.
     *
     * Every scenario gets its own context instance.
     * You can also pass arbitrary arguments to the
     * context constructor through behat.yml.
     */
    public function __construct()
    {
    }
}

My /features/search.feature contains:

Feature: Search
  In order to find products dinosaurs love
  As a web user
  I need to be able to search for products

  @javascript
  Scenario: Searching for a product that exists
    Given I am on "/"
    When I fill in "searchTerm" with "Samsung"
    And I press "search_submit"
    Then I should see "Samsung Galaxy"

In a separate tab of my browser, I launched Selenium Standalone Server:

$ java -jar /Users/noxlady/Applications/selenium-server-standalone-3.8.1.jar
19:04:54.801 INFO - Selenium build info: version: '3.8.1', revision: '6e95a6684b'
19:04:54.801 INFO - Launching a standalone Selenium Server
2017-12-15 19:04:55.246:INFO::main: Logging initialized @1087ms to org.seleniumhq.jetty9.util.log.StdErrLog
19:04:55.386 INFO - Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`
19:04:55.443 INFO - Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
19:04:55.458 INFO - Using `new EdgeOptions()` is preferred to `DesiredCapabilities.edge()`
19:04:55.463 INFO - Driver class not found: com.opera.core.systems.OperaDriver
19:04:55.463 INFO - Using `new OperaOptions()` is preferred to `DesiredCapabilities.operaBlink()`
19:04:55.467 INFO - Using `new SafariOptions()` is preferred to `DesiredCapabilities.safari()`
19:04:55.469 INFO - Driver class not found: org.openqa.selenium.phantomjs.PhantomJSDriver
19:04:55.570 INFO - Driver provider class org.openqa.selenium.ie.InternetExplorerDriver registration is skipped:
 registration capabilities Capabilities {browserName: internet explorer, ensureCleanSession: true, platform: WINDOWS, version: } does not match the current platform MAC
19:04:55.570 INFO - Driver provider class org.openqa.selenium.edge.EdgeDriver registration is skipped:
 registration capabilities Capabilities {browserName: MicrosoftEdge, platform: WINDOWS, version: } does not match the current platform MAC
19:04:55.703 INFO - Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
19:04:55.703 INFO - Using `new EdgeOptions()` is preferred to `DesiredCapabilities.edge()`
19:04:55.703 INFO - Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`
19:04:55.704 INFO - Using `new OperaOptions()` is preferred to `DesiredCapabilities.operaBlink()`
19:04:55.704 INFO - Using `new SafariOptions()` is preferred to `DesiredCapabilities.safari()`
19:04:55.731 INFO - Using the passthrough mode handler
2017-12-15 19:04:55.805:INFO:osjs.Server:main: jetty-9.4.7.v20170914
2017-12-15 19:04:55.870:WARN:osjs.SecurityHandler:main: ServletContext@o.s.j.s.ServletContextHandler@1a75e76a{/,null,STARTING} has uncovered http methods for path: /
2017-12-15 19:04:55.879:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler@1a75e76a{/,null,AVAILABLE}
2017-12-15 19:04:55.964:INFO:osjs.AbstractConnector:main: Started ServerConnector@79207381{HTTP/1.1,[http/1.1]}{0.0.0.0:4444}
2017-12-15 19:04:55.965:INFO:osjs.Server:main: Started @1806ms
19:04:55.965 INFO - Selenium Server is up and running

The "Selenium Server is up and running" bit certainly sounds promising! Visiting both http://127.0.0.1:4444/ and http://0.0.0.0:4444/ in my browser takes me to a nice Selenium Standalone v.3.8.1 page (which is only available when Selenium is running in my terminal), so the Selenium jar file seems to be doing something...

When I remove the @javascript and run my test (using Goutte) I get:

$  ./behat
Feature: Search
  In order to find products dinosaurs love
  As a web user
  I need to be able to search for products

  Scenario: Searching for a product that exists # features/search.feature:7
    Given I am on "/"                           # FeatureContext::visit()
    When I fill in "searchTerm" with "Samsung"  # FeatureContext::fillField()
    And I press "search_submit"                 # FeatureContext::pressButton()
    Then I should see "Samsung Galaxy"          # FeatureContext::assertPageContainsText()

1 scenario (1 passed)
4 steps (4 passed)
0m3.15s (14.27Mb)

However, when I put the @javascript back in (so it's using Selenium) Firefox launches and then just kind of sits there. After about 45 seconds my terminal gets bored and spits out the following:

./behat --verbose
Feature: Search
  In order to find products dinosaurs love
  As a web user
  I need to be able to search for products

  @javascript
  Scenario: Searching for a product that exists # features/search.feature:7
    Given I am on "/"                           # FeatureContext::visit()
      WebDriver\Exception\UnknownError: Timed out waiting 45 seconds for Firefox to start.
      Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'
      System info: host: 'Megs-MacBook.local', ip: 'fe80:0:0:0:1057:7410:918d:cd36%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '9.0.1'
      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(13, 'Timed out waiti...')
      #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(287): WebDriver\WebDriver->session(Array, Array)
      #3 vendor/behat/mink/src/Session.php(70): Behat\Mink\Driver\Selenium2Driver->start()
      #4 vendor/behat/mink/src/Mink.php(117): Behat\Mink\Session->start()
      #5 vendor/behat/mink-extension/src/Behat/MinkExtension/Context/RawMinkContext.php(108): Behat\Mink\Mink->getSession(NULL)
      #6 vendor/behat/mink-extension/src/Behat/MinkExtension/Context/RawMinkContext.php(131): Behat\MinkExtension\Context\RawMinkContext->getSession(NULL)
      #7 vendor/behat/mink-extension/src/Behat/MinkExtension/Context/MinkContext.php(49): Behat\MinkExtension\Context\RawMinkContext->visitPath('/')
      #8 [internal function]: Behat\MinkExtension\Context\MinkContext->visit('/')
      #9 vendor/behat/behat/src/Behat/Testwork/Call/Handler/RuntimeCallHandler.php(109): call_user_func_array(Array, Array)
      #10 vendor/behat/behat/src/Behat/Testwork/Call/Handler/RuntimeCallHandler.php(64): Behat\Testwork\Call\Handler\RuntimeCallHandler->executeCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
      #11 vendor/behat/behat/src/Behat/Testwork/Call/CallCenter.php(140): Behat\Testwork\Call\Handler\RuntimeCallHandler->handleCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
      #12 vendor/behat/behat/src/Behat/Testwork/Call/CallCenter.php(96): 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/TickingStepTester.php(59): 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/EventDispatcher/Tester/EventDispatchingStepTester.php(73): Behat\Behat\EventDispatcher\Tester\TickingStepTester->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/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)
      #19 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)
      #20 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)
      #21 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)
      #22 vendor/behat/behat/src/Behat/Behat/Tester/Runtime/IsolatingScenarioTester.php(69): Behat\Behat\EventDispatcher\Tester\EventDispatchingScenarioTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\ScenarioNode), false)
      #23 vendor/behat/behat/src/Behat/Behat/Tester/Runtime/RuntimeFeatureTester.php(84): Behat\Behat\Tester\Runtime\IsolatingScenarioTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\ScenarioNode), false)
      #24 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)
      #25 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)
      #26 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)
      #27 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)
      #28 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)
      #29 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)
      #30 vendor/behat/behat/src/Behat/Testwork/EventDispatcher/Tester/EventDispatchingExercise.php(70): Behat\Testwork\Tester\Runtime\RuntimeExercise->test(Array, false)
      #31 vendor/behat/behat/src/Behat/Testwork/Ordering/OrderedExercise.php(80): Behat\Testwork\EventDispatcher\Tester\EventDispatchingExercise->test(Array, false)
      #32 vendor/behat/behat/src/Behat/Testwork/Tester/Cli/ExerciseController.php(149): Behat\Testwork\Ordering\OrderedExercise->test(Array, false)
      #33 vendor/behat/behat/src/Behat/Testwork/Tester/Cli/ExerciseController.php(108): Behat\Testwork\Tester\Cli\ExerciseController->testSpecifications(Object(Symfony\Component\Console\Input\ArgvInput), Array)
      #34 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))
      #35 vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php(242): Behat\Testwork\Cli\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      #36 vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(842): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      #37 vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(193): Symfony\Component\Console\Application->doRunCommand(Object(Behat\Testwork\Cli\Command), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      #38 vendor/behat/behat/src/Behat/Testwork/Cli/Application.php(124): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      #39 vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(117): Behat\Testwork\Cli\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      #40 vendor/behat/behat/bin/behat(34): Symfony\Component\Console\Application->run()
      #41 {main}

      Next Behat\Mink\Exception\DriverException: Could not open connection: Timed out waiting 45 seconds for Firefox to start.
      Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'
      System info: host: 'Megs-MacBook.local', ip: 'fe80:0:0:0:1057:7410:918d:cd36%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '9.0.1'
      Driver info: driver.version: unknown in vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php:290
      Stack trace:
      #0 vendor/behat/mink/src/Session.php(70): Behat\Mink\Driver\Selenium2Driver->start()
      #1 vendor/behat/mink/src/Mink.php(117): Behat\Mink\Session->start()
      #2 vendor/behat/mink-extension/src/Behat/MinkExtension/Context/RawMinkContext.php(108): Behat\Mink\Mink->getSession(NULL)
      #3 vendor/behat/mink-extension/src/Behat/MinkExtension/Context/RawMinkContext.php(131): Behat\MinkExtension\Context\RawMinkContext->getSession(NULL)
      #4 vendor/behat/mink-extension/src/Behat/MinkExtension/Context/MinkContext.php(49): Behat\MinkExtension\Context\RawMinkContext->visitPath('/')
      #5 [internal function]: Behat\MinkExtension\Context\MinkContext->visit('/')
      #6 vendor/behat/behat/src/Behat/Testwork/Call/Handler/RuntimeCallHandler.php(109): call_user_func_array(Array, Array)
      #7 vendor/behat/behat/src/Behat/Testwork/Call/Handler/RuntimeCallHandler.php(64): Behat\Testwork\Call\Handler\RuntimeCallHandler->executeCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
      #8 vendor/behat/behat/src/Behat/Testwork/Call/CallCenter.php(140): Behat\Testwork\Call\Handler\RuntimeCallHandler->handleCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
      #9 vendor/behat/behat/src/Behat/Testwork/Call/CallCenter.php(96): 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/TickingStepTester.php(59): 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/EventDispatcher/Tester/EventDispatchingStepTester.php(73): Behat\Behat\EventDispatcher\Tester\TickingStepTester->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/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)
      #16 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)
      #17 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)
      #18 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)
      #19 vendor/behat/behat/src/Behat/Behat/Tester/Runtime/IsolatingScenarioTester.php(69): Behat\Behat\EventDispatcher\Tester\EventDispatchingScenarioTester->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/Tester/Runtime/RuntimeFeatureTester.php(84): Behat\Behat\Tester\Runtime\IsolatingScenarioTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\ScenarioNode), false)
      #21 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)
      #22 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)
      #23 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)
      #24 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)
      #25 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)
      #26 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)
      #27 vendor/behat/behat/src/Behat/Testwork/EventDispatcher/Tester/EventDispatchingExercise.php(70): Behat\Testwork\Tester\Runtime\RuntimeExercise->test(Array, false)
      #28 vendor/behat/behat/src/Behat/Testwork/Ordering/OrderedExercise.php(80): Behat\Testwork\EventDispatcher\Tester\EventDispatchingExercise->test(Array, false)
      #29 vendor/behat/behat/src/Behat/Testwork/Tester/Cli/ExerciseController.php(149): Behat\Testwork\Ordering\OrderedExercise->test(Array, false)
      #30 vendor/behat/behat/src/Behat/Testwork/Tester/Cli/ExerciseController.php(108): Behat\Testwork\Tester\Cli\ExerciseController->testSpecifications(Object(Symfony\Component\Console\Input\ArgvInput), Array)
      #31 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))
      #32 vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php(242): Behat\Testwork\Cli\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      #33 vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(842): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      #34 vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(193): Symfony\Component\Console\Application->doRunCommand(Object(Behat\Testwork\Cli\Command), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      #35 vendor/behat/behat/src/Behat/Testwork/Cli/Application.php(124): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      #36 vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(117): Behat\Testwork\Cli\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      #37 vendor/behat/behat/bin/behat(34): Symfony\Component\Console\Application->run()
      #38 {main}
    When I fill in "searchTerm" with "Samsung"  # FeatureContext::fillField()
    And I press "search_submit"                 # FeatureContext::pressButton()
    Then I should see "Samsung Galaxy"          # FeatureContext::assertPageContainsText()

--- Failed scenarios:

    features/search.feature:7

1 scenario (1 failed)
4 steps (1 failed, 3 skipped)
0m46.70s (13.28Mb)

Meanwhile, the following is added to the terminal tab running Selenium Server:

2017-12-15 19:14:05.837:INFO:osjshC.ROOT:qtp1021436681-16: org.openqa.selenium.remote.server.WebDriverServlet-49049a04: Initialising WebDriverServlet
19:14:05.975 INFO - Found handler: org.openqa.selenium.remote.server.commandhandler.BeginSession@a667021
19:14:05.990 INFO - /session: Executing POST on /session (handler: BeginSession)
19:14:06.197 INFO - Capabilities are: Capabilities {browser: firefox, browserName: firefox, ignoreZoomSetting: false, marionette: false, name: Behat feature suite, tags: [Megs-MacBook.local, PHP 7.0.24]}
19:14:06.202 INFO - Capabilities {browser: firefox, browserName: firefox, ignoreZoomSetting: false, marionette: false, name: Behat feature suite, tags: [Megs-MacBook.local, PHP 7.0.24]} matched class org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.firefox.XpiDriverService)

If any of you have some experience getting Behat to talk to browsers on a Mac, I would really, really appreciate your help. If you need more info (like logs or something) I'll totally provide it, but you might need to give me "Idiot's Guide" instructions on how to find it...

Anyhow, thanks for slogging through all this and thanks in advance for any help you can offer :)

Meg Claypool
  • 65
  • 1
  • 8

3 Answers3

3

Got stuck with the same problem, there is a known issue with new mink-extension 2.3 all you need is just to set marionette: null

extensions:
    Behat\MinkExtension:
        base_url: http://127.0.0.1:8000
        javascript_session: selenium2

        browser_name: chrome
        selenium2:
            capabilities:
                # required by mink-extension 2.3
                marionette: null
                browserName: chrome
                browser: chrome
                version: 63
mykbas
  • 180
  • 2
  • 9
  • Oh. My. Gosh. It worked! Finally, FINALLY, it WORKED!!! Thank you sooooo much! I was seriously starting to think I'd carelessly installed something that had borked my system and was getting ready to nuke and pave this weekend, so you've saved me hours and hours of futile work. Thanks! – Meg Claypool Jan 11 '18 at 06:54
2

You need to set the driver when you are starting the selenium server.

java -Dwebdriver.chrome.driver=path_to_chrome_driver -jar path_to_selenium_server.jar

I recommend having them both(selenium server and browser driver) in the same directory and use a bash script to start the server.
You don't have to specify the wd_host if you have the server on local machine with the default port 4444.

I did't tried with firefox, chrome works well. When are you using a browser you should let @javascript tag at feature level an you can use also @insulated so your browser starts clean with no cookies and cache.

@insulated @javascript
Feature: Feature name


  @my_tag
  Scenario: Feature name - scenario summary

Try a behat.yml like:

default:
  suites:
    default:
      contexts:
        - FeatureContext
  formatters:
    pretty:
    junit:
    html:
      output_path: %paths.base%/report

  extensions:
    Behat\MinkExtension:
      goutte: ~
      selenium2:
        browser: chrome
        capabilities:
          chrome:
            switches:
              - "start-maximized"
      base_url: 'base_url'


dev:
  extensions:
    Behat\MinkExtension:
      base_url: 'base_url_dev'

When you are using another browser you should also start the selenium server with that driver and also change the name in behat.yml, for firefox you need geckdriver and to use gecko.driver instead of chrome.

lauda
  • 4,153
  • 2
  • 14
  • 28
  • Hey lauda, thanks for the advice. Unfortuately, it's not working for me, but maybe you've got some more thoughts. I moved my selenium jar file into /usr/local/bin so it could hang out with chromedriver and geckodriver. I changed my behat.yml as per your recommendations and then started selenium in another tab using "java -Dwebdriver.chrome.driver=/usr/local/bin/chromedriver -jar /usr/local/bin/selenium-server-standalone-3.8.1.jar". When I tried running behat, the same thing happened as before. That is to say, **Firefox** opened and then hung there... No Chrome. Thoughts??? – Meg Claypool Dec 16 '17 at 17:48
  • Side question: how the heck do people have followup discussions re: suggested solutions on SO? I can't really paste code in here; do I edit my original post?? – Meg Claypool Dec 16 '17 at 17:50
  • If you have drivers and files in the same directory you don't have to specify the full path. For other questions related to this and updates you need to edit your question. You also need to careful with the versions of libraries you are installing. – lauda Dec 16 '17 at 20:09
  • Finally got this working, and I just wanted to thank you again for the time you spent helping me out. Although Mykhailo's solution contained the gold nugget that made it work on my system, I really appreciate your thorough and thoughtful assistance :) – Meg Claypool Jan 11 '18 at 06:56
1

Another solution could be to skip selenium and use the chrome driver directly via the ChromeExtension of D.More. Using the Chrome driver works both in a window and headless. Using the headless version of chrome and this driver is also a lot faster than using selenium. For reference my behat.yml:

default:
translation:
    locale: nl
extensions:
    DMore\ChromeExtension\Behat\ServiceContainer\ChromeExtension: ~
    Behat\MinkExtension:
        browser_name: chrome
        base_url: https://www.yoursite.com
        sessions:
            default:
                chrome:
                    api_url: "http://127.0.0.1:9222"
                    download_behavior: allow
                    download_path: ~/Downloads
                    validate_certificate: false

And my composer.json:

{
"require-dev": {
    "behat/behat": "^3.4",
    "behat/mink-extension": "^2.3",
    "behat/mink-selenium2-driver": "^1.3"
},
"require": {
    "behat/mink-goutte-driver": "^1.2",
    "dmore/chrome-mink-driver": "^2.5",
    "dmore/behat-chrome-extension": "^1.1"
}

}

Note that you need to start chrome (headless or not) before running behat. For this I created three aliases in my .bash_profile (in my home-dir:

alias chrome='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'
alias chromedriver='chrome --disable-gpu --remote-debugging-address=127.0.0.1 --remote-debugging-port=9222'
alias chromedriverheadless='chrome --disable-gpu --headless --remote-debugging-address=127.0.0.1 --remote-debugging-port=9222'

The chromedriver (check you have in a location that is in your $PATH somewhere) should match the version of Chrome installed. If it stops working, often Chrome has updated itself, but not chromedriver. I have this solution working on my mac.

Bjinse
  • 1,339
  • 12
  • 25
  • Hi Bjinse, thanks so much for your time :) If you have a little more time, I'm running into some problems. When I set up my files to match yours and then run behat, I get the following error: ``` Scenario: Search for a word that exists # features/search.feature:6 Given I am on "/" # FeatureContext::visit() Warning: First parameter must either be an object or the name of an existing class in vendor/dmore/chrome-mink-driver/src/ChromeBrowser.php line 43 ``` Do you have any suggestions? (My google-fu is failing me here :( ) – Meg Claypool Jan 04 '18 at 05:49
  • Are you running chrome and is it listening on port 9222 (check with ps or browse to 127.0.0.1:9222)? When I google it, I see somebody running selenium server and using chrome in the tests. You do not need selenium server to be running. – Bjinse Jan 05 '18 at 08:58
  • Hello @Bjinse, thanks for the notes above. I'm currently getting a cert error when I run a simple test. I used the headless alias you gave above, it starts correctly. `$ chromedriverheadless`: `DevTools listening on ws://127.0.0.1:9222/devtools/browser/188... etc \\ [0512/175434.603916:ERROR:trust_store_mac.cc(844)] Error parsing certificate: ERROR: Failed parsing extensions` I've tried running this with `--ignore-certificate-error` as well, same result. Any ideas? Cheers! jz – J.Z. May 13 '23 at 00:57
  • Not sure. Above answer is 5 years old. I haven't used Behat in the last years. I moved on to Cypress. Different language, but much more stable environment. – Bjinse May 17 '23 at 20:42