Using Behat version 3 in conjunction with the Google Chrome browser

Struggling to set up behat 3 with chrome and encountering issues while trying to initialize the behat.yml file.

default:
  extensions:
    Behat\MinkExtension\Extension:
      base_url: 'http://someurl.com'
      javascript_session: selenium2
      selenium2:
        browser: chrome
      goutte: ~

The contents of my composer.json file are as follows:

{
    "require-dev": {
    "behat/behat": "3.*@stable",
    "behat/mink": "1.6.*@stable",
    "behat/mink-extension": "@stable",
    "behat/mink-goutte-driver": "@stable",
    "behat/mink-selenium2-driver": "*",
    "peridot-php/webdriver-manager": "dev-master",
    "bossa/phpspec2-expect": "*"
  },
  "config": {
    "bin-dir": "bin"
  }
}

Facing the error message:

[Behat\Testwork\ServiceContainer\Exception\ExtensionInitializationException]
Behat\MinkExtension\Extension extension file or class could not be located.

Answer №1

It appears that there is an issue

The Behat\MinkExtension\Extension extension file or class cannot be found.

To resolve this, you must remove the word "Extension" from behat.yml and replace Behat\MinkExtension\Extension: with Behat\MinkExtension:

Once this adjustment is made, everything should function properly.

Answer №2

For a solution, consider updating the extensions block in your yml configurations file to something similar to this example:

extensions:
    Behat\MinkExtension:
        base_url: "http://www.your-web.com/"
        sessions:
            chrome_mac:
                selenium2:
                    browser: "chrome"
                    wd_host: http://xxx.xxx.xxx.xxx:4444/wd/hub
                    capabilities:
                        platform: WINDOWS
                        browser: chrome
                        version: ""
                        extra_capabilities:
                            chromeOptions:
                                args:
                                    - "--start-maximized"

The "extra_capabilities section is not mandatory but can be included if needed. This should resolve the issue at hand!

Answer №3

Thank you everyone for your help, I have resolved the issues by making the following changes: Behat.yml

default:
  extensions:
    Behat\MinkExtension:
      base_url: myURL.com
      selenium2: ~
      browser_name: 'chrome'
  suites:
      defaults:
          contexts:
              - FeatureContext
              - Behat\MinkExtension\Context\MinkContext

composer.json

{
    "require": {
        "behat/mink-extension": "^2.2",
        "behat/mink-goutte-driver": "^1.2",
        "behat/mink-selenium2-driver": "^1.3"
    }
}

Java in Command Line Interface (CLI)

java -jar -Dwebdriver.gecko.driver=geckodriver.exe seleneiumversionhere

Answer №4

In my testing projects, I exclusively use the default Chrome browser. This has proven to be effective for me and may also work well for you.

default:
  autoload:
    '': %paths.base%/features/bootstrap
  extensions:
    Behat\MinkExtension:
      base_url: https://www.example.com
      default_session: selenium2
      files_path: features/Resources
      show_cmd: 'open %s'
      selenium2:
        browser: chrome
        wd_host: http://localhost:4444/wd/hub

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the process for generating an alert box with protractor?

While conducting tests, I am attempting to trigger an alert pop-up box when transitioning my environment from testing to production while running scripts in Protractor. Can someone assist me with this? ...