behat 3 with chrome - selenium

I want to run behat 3 with chrome but unable to run the --init
my behat.yml
default:
extensions:
Behat\MinkExtension\Extension:
base_url: 'http://someurl.com'
javascript_session: selenium2
selenium2:
browser: chrome
goutte: ~
my composer.json file is as following:
{
"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"
}
}
getting the following error
[Behat\Testwork\ServiceContainer\Exception\ExtensionInitializationException]
Behat\MinkExtension\Extension extension file or class could not be located.

As it seems
Behat\MinkExtension\Extension extension file or class could not be located.
You need to remove Extension from behat.yml
Replace Behat\MinkExtension\Extension: with Behat\MinkExtension:
After this it should work.

Try changing your extensions block in the yml configurations file to something like this:
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 optional.
This should do the trick!

thanks all i have fixed with the followings:
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 CLI
java -jar -Dwebdriver.gecko.driver=geckodriver.exe seleneiumversionhere

I use default chrome browser only, I think may work to you, cause I do this every in my project test.
default:
autoload:
'': %paths.base%/features/bootstrap
extensions:
Behat\MinkExtension:
base_url: https://www.test your url.com
default_session: selenium2
files_path: features/Resources
show_cmd: 'open %s'
selenium2:
browser: chrome
wd_host: http://localhost:4444/wd/hub

Related

selenium with chromedriver not working

I use selenium 3 and chrome browser to test but selenium doesn't launch chrome browser. I set chromedriver path: usr/local/bin
this is code behat.yml:
default:
suites:
default:
bundle: MedBundle
contexts:
- test\MedBundle\Behat\Context\FeatureContext
- test\MedBundle\Behat\Context\AjouterContext
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
base_url: http://localhost/test/web/app_dev.php
goutte: ~
browser_name: 'chrome'
javascript_session: selenium2
selenium2:
wd_host: http://localhost:4444/wd/hub
sessions:
default:
symfony2: ~
I have this problem:
help me for resolve this problem , I am blocked

Behat 3 and Mink Extension on Ubuntu error in FeatureContext

Depending on if my FeatureContext class extends RawMinkContext or MinkContext I'm having issues running Behat tests.
Here's my FeatureContext.php
<?php
use Behat\Behat\Context\ClosuredContextInterface;
use Behat\Behat\Context\TranslatedContextInterface;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\BehatContext;
use Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkContext;
use Behat\MinkExtension\Context\RawMinkContext;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Mink\Driver\Selenium2Driver;
use Behat\Behat\Hook\Scope\AfterStepScope;
use Goutte\Client;
class FeatureContext extends MinkContext implements Context, SnippetAcceptingContext {
/**
* Initializes context.
* Every scenario gets its own context object.
*
* #since 1.0.0
*
* #param array $parameters context parameters (set them up through behat.yml)
* #return null
*/
public function __construct() {
}/* __construct() */
}
?>
and my behat.yml
default:
suites:
default:
path: %paths.base%/features
contexts:
- FeatureContext
- Behat\MinkExtension\Context\MinkContext
- Behat\MinkExtension\Context\RawMinkContext
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
base_url: 'http://somesite.com'
goutte: ~
javascript_session: selenium2
files_path: 'vendor'
selenium2: ~
sessions:
default:
goutte: ~
goutte:
goutte: ~
selenium2:
selenium2: ~
symfony2:
symfony2: ~
formatters:
html:
output_path: %paths.base%/reports
PHP Fatal error: Call to a member function getSession() on a non-object in /home/behat/composer/vendor/behat/mink-extension/src/Behat/MinkExtension/Context/RawMinkContext.php on line 101
If I extend RawMinkContext instead of MinkContext then the tests run, but it adds (blank) versions of the default steps that are defined in MinkContext (i.e. If I am on [url] or When I go to [url] etc. ).
If I run behat -c ./config/behat.yml (or, just ./behat.yml - I have an identical behat.yml file in both locations as I wasn't sure it was being used properly) I get the same results as above. I'm almost certainly doing something dumb...
My composer.json for reference:
{
"name": "behat mink skeleton",
"require": {
"behat/behat": "*",
"behat/mink-extension": "*",
"behat/mink-browserkit-driver": "*",
"behat/mink-goutte-driver": "*",
"behat/mink-selenium2-driver": "*",
"bossa/phpspec2-expect": "*",
"teaandcode/behat-guzzle-extension": "*",
"sauce/sausage": ">=0.5",
"sauce/connect": ">=3.0",
"emuse/behat-html-formatter": "dev-master"
},
"minimum-stability": "dev",
"config": {
"bin-dir": "bin/",
"github-oauth": {
"github.com": "ac1dd3678488663ccc1ba02a5d1d474e1a78bb93"
}
}
}
If you extend MinkContext in FeatureContext then remove MinkContext from behat.yml.
behat.yml file should contain only the local context under contexts section, in your case you don't need MinkContext or RawAwareContext, only FeatureContext.

What is the cause of this exception .?

I am trying to run Behat\mink using this code "bin\behat --format html --out report.html --profile firefox" . But i am getting this error .
[RuntimeException]
MinkExtension 1.3 only supports Goutte 1.x for MinkGoutteDriver, not Goutte 2.x.
composer.json looks like this
{
"require": {
"behat/behat": "2.5.*#stable",
"behat/mink": "1.6.*#stable",
"behat/mink-extension": "*",
"behat/mink":"~1.5#dev",
"behat/mink":"~1.6#dev",
"behat/mink-goutte-driver": "*",
"behat/mink-selenium2-driver": "*"
},
"minimum-stability": "dev",
"config": {
"bin-dir": "bin/"
}
}
behat.yml
firefox:
context:
parameters:
Browser_Name: firefox
extensions:
Behat\MinkExtension\Extension:
base_url: https://google.com
javascript_session: selenium2
browser_name: firefox
selenium2:
wd_host: http://127.0.0.1:4444/wd/hub
It would be so helpful if you could tell me where i have gone wrong .
I would say that your first problem lies within your composer.json file. It would appear as though you are attempting to load both developmental and stable versions of the same library.
Unless you are attempting to test / load some dev code you can simplify your require section to:
"require": {
"behat/mink-selenium2-driver" : "~1.2",
"behat/mink-goutte-driver" : "~1.1",
"behat/mink-extension" : "~2.0"
}
Your behat/behat, and behat/mink libraries will automatically be pulled in by composer to fulfil the requirements for those libraries.
Information on the tilde operator, within your composer.json file can be found within composers documentation
Again, unless you are using dev based releases you might want to look at omitting:
"minimum-stability": "dev",

Unrecognized options "suites" under "behat"

I am using behat 2.4(stable), and I am trying to pass parameters into class's, that extends BehatContext class, constructor.
However I get 'Unrecognized options "suites" under "behat"', with the following set up.
I am using the following behat.yml file:
default:
suites:
default:
contexts:
exampleContext:
browser: http://localhost:8080
browser_version: /var/tmp
paths:
features: %behat.paths.base%/../../
bootstrap: %behat.paths.base%/../../
extensions:
Behat\MinkExtension\Extension:
# base_url is the URL to your dev site. Make sure you include
# the port at the end. e.g.
base_url: http://example.web01.com
default_session: selenium2
browser_name: 'chrome'
selenium2:
capabilities: { "browser": "firefox", "version": "14"}
sites/all/libraries/extensions/DrupalBehatExtension.php: ~
filters:
# The default profile does not rebuild from nothing so do not run tests
# that require a rebuild from nothing.
tags: ~#require-rebuild
context:
class: DrupalContext
parameters:
# If you'd like to test on a clone of the actual site data set to true.
use_test_database: false
# If an existing test database exists then it will be used unless reset_database is set to true.
reset_database: false
# If you would like to clear the db and run site install on every feature
# set to the name of an install profile, otherwise set to false.
# If you do set this you should also set use_test_database to true.
rebuild_on_feature: false
# If you would like to enable a module after running site install
rebuild_module: false
# Set the name of the site folder to use for settings.php.
site: dev.example.com
My class implementation is
class exampleContext extends BehatContext {
public function __construct($browser = 'ie', $browser_version = '8') {
...
}
How can I achieve this? The only answer I've found is the one that demands to take out the DrupalContext which is rather important.
How can i get the Parameters from Behat.yml to a php file?
suites option was added in behat3. You should update version.
Try this. This is for Behat 2 not 3 though!
mySymfonyProject/composer.json:
"require": {
"behat/behat": "2.5.*#stable",
"behat/behat-bundle": "1.0.0",
"behat/symfony2-extension": "1.1.2",
"behat/mink": "1.5.0",
"behat/mink-extension": "~1.3",
"behat/mink-selenium2-driver": "1.1.1",
"behat/mink-goutte-driver": "1.0.9"
},
"config": {
"bin-dir": "bin"
},
"minimum-stability": "dev",
behat.yml
default:
context:
class: FeatureContext
parameters:
browser: 'ie'
browser_version: '8'
extensions:
Behat\Symfony2Extension\Extension:
mink_driver: true
kernel:
env: test
debug: true
Behat\MinkExtension\Extension:
base_url: 'http://mysymfonyproject.local/app_test.php/'
javascript_session: selenium2
browser_name: firefox
goutte: ~
selenium2: ~
paths:
features: %behat.paths.base%/src
bootstrap: %behat.paths.features%/Context
CONTEXT FEATURE
mySymfonyProject/src/Site/CommonBundle/Features/Context/FeatureContext.php
<?php
namespace Site\CommonBundle\Features\Context;
use Behat\MinkExtension\Context\MinkContext;
class FeatureContext extends MinkContext
{
public function __construct($browser, $browser_version)
{
// Do whatever you wish with params
}
//And your own methods
}
TESTS
When you have feature files you can run them like this (this runs all in one go. for more info read behat doc):
bin/behat #SiteCommonBundle

Struggling to get Mink working with Behat

I've been following this guide (and installed everything through composer): http://docs.behat.org/cookbook/behat_and_mink.html and am attempting to get Behat + Mink working but everytime I try and run bin/behat I get the following error:
PHP Fatal error: Call to a member function getSession() on a non-object in vendor/behat/mink-extension/src/Behat/MinkExtension/Context/RawMinkContext.php on line 80
That line of code is:
return $this->getMink()->getSession($name);
So for some reason the mink attribute is empty but I've no idea why.
My .feature file is exactly the same as the one in the guide, the FeatureContext class is also from the guide:
use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\TranslatedContextInterface,
Behat\Behat\Context\BehatContext,
Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkContext;
/**
* Features context.
*/
class FeatureContext extends MinkContext
{
}
and my vendor/behat/mink/behat.yml file contains:
context:
extensions:
Behat\MinkExtension\Extension:
base_url: 'http://en.wikipedia.org/'
goutte: ~
selenium2: ~
I've also tried making my class extend BehatContext and then call useContext but that gives me the same error. Behat itself seems to work it's just anything with Mink produces that fatal error and I've no idea how to fix it.
This is because you should copy vendor/behat/behat/behat.yml.dist file to your/project/root/behat.yml, rather than editing the file in the vendor dir and add extesions to the default section.
And here's what it looks like:
default:
extensions:
Behat\MinkExtension\Extension:
base_url: http://lunch-time/app_dev.php
goutte: ~
selenium2: ~
paths:
features: features
bootstrap: features/bootstrap
annotations:
paths:
features: features/annotations
closures:
paths:
features: features/closures
I was facing a similar issue. We need to tell Symfony to initialize the object.
Mine got fixed after adding under the default > suites > my_suite.
contexts: [Behat\MinkExtension\Context\MinkContext]
Here is how my new behat.yml looks like.
default:
suites:
my_suite:
type: symfony_bundle
bundle: AcmeProjectManagerBundle
contexts: [Behat\MinkExtension\Context\MinkContext]
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
base_url: http://en.wikipedia.org
goutte: ~
selenium2: ~
sessions:
default:
symfony2: ~