I run /vendor/bin/behat
and tests without #javascript are running in test database, but tests in chrome, are running in dev enviroment, instead of test enviroment.
Where can I configure and run it in APP_ENV=test ?
I use symfony 5.4
My behat.yml
default:
suites:
default:
contexts:
- App\Tests\Behat\FormContext
extensions:
DMore\ChromeExtension\Behat\ServiceContainer\ChromeExtension: ~
FriendsOfBehat\SymfonyExtension:
bootstrap: tests/bootstrap.php
Behat\MinkExtension:
browser_name: chrome
base_url: http://localhost:8000
default_session: symfony
javascript_session: chrome
sessions:
symfony:
symfony: ~
chrome:
chrome:
api_url: http://127.0.0.1:9222
validate_certificate: false
show_auto: false
I want to create a lot of Behat features with simulating different configurations (from yaml,xml,php files).
Official extension for support Symfony 4 - Symfony2Extension have support for configuring a different environment like:
default:
# ...
extensions:
Behat\Symfony2Extension:
kernel:
class: App\Kernel
bootstrap: config/bootstrap.php
env: custom_env
But, this extension is loaded before any suites or context. I should initial Kernel for each separate context with different config files via env.
Like:
default:
suites:
default:
contexts:
params:
env: custom_env
- FeatureContext:
or
default:
suites:
default:
contexts:
- FeatureContext:
env: custom_env
And I'll load Kernel manually inside Context.
Any idea here?
I guess you could define different profiles for each env:
default:
# ...
extensions:
Behat\Symfony2Extension:
kernel:
class: App\Kernel
bootstrap: config/bootstrap.php
php_profile:
# ...
extensions:
Behat\Symfony2Extension:
kernel:
env: prod
yaml_profile:
# ...
extensions:
Behat\Symfony2Extension:
kernel:
env: dev
Im trying to setup my behat tests in selenium enviroment. For now i got selenium starting with dockers,
Thats my docker-compose.yml config:
hub:
image: selenium/hub
ports:
- "4444:4444"
chrome:
image: selenium/node-chrome
links:
- hub
And i got my behat.yml configurated:
default:
suites:
default:
paths:
features: 'tests/features'
bootstrap: 'tests/features/bootstrap'
contexts:
- FeatureContext: ~
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
base_url: http://localhost
selenium2: ~
And when i launch my tests with #javascript (i suppose this launch selenium env) i get error:
Could not open connection: Curl error thrown for http POST to http://localhost:4444/wd/hub/session with params: {"desiredCapabilities":{"tags":["cli","PHP 7.0.15-1+deb.sury.org~trusty+1"],"browser":"firefox","ignoreZoomSetting":false,"name":"Behat feature suite","browserName":"firefox"}}
Failed to connect to localhost port 4444: Connection refused (Behat\Mink\Exception\DriverException)
When I get on http://localhost:4444/wd/hub/sessions i get:
{"status":13,"value":{"message":"Session [(null externalkey)] not available and is not among the last 1000 terminated sessions.\nActive sessions are[]","class":"org.openqa.grid.common.exception.GridException","stackTrace":[{"fileName":"ActiveTestSessions.java","className":"org.openqa.grid.internal.ActiveTestSessions","methodName":"getExistingSession","lineNumber":110},{"fileName":"Registry.java","className":"org.openqa.grid.internal.Registry","methodName":"getExistingSession","lineNumber":404},{"fileName":"RequestHandler.java","className":"org.openqa.grid.web.servlet.handler.RequestHandler","methodName":"getSession","lineNumber":232},{"fileName":"RequestHandler.java","className":"org.openqa.grid.web.servlet.handler.RequestHandler","methodName":"process","lineNumber":117},{"fileName":"DriverServlet.java","className":"org.openqa.grid.web.servlet.DriverServlet","methodName":"process","lineNumber":83},{"fileName":"DriverServlet.java","className":"org.openqa.grid.web.servlet.DriverServlet","methodName":"doGet","lineNumber":61},{"fileName":"HttpServlet.java","className":"javax.servlet.http.HttpServlet","methodName":"service","lineNumber":687},{"fileName":"HttpServlet.java","className":"javax.servlet.http.HttpServlet","methodName":"service","lineNumber":790},{"fileName":"ServletHolder.java","className":"org.seleniumhq.jetty9.servlet.ServletHolder","methodName":"handle","lineNumber":808},{"fileName":"ServletHandler.java","className":"org.seleniumhq.jetty9.servlet.ServletHandler","methodName":"doHandle","lineNumber":587},{"fileName":"SessionHandler.java","className":"org.seleniumhq.jetty9.server.session.SessionHandler","methodName":"doHandle","lineNumber":221},{"fileName":"ContextHandler.java","className":"org.seleniumhq.jetty9.server.handler.ContextHandler","methodName":"doHandle","lineNumber":1127},{"fileName":"ServletHandler.java","className":"org.seleniumhq.jetty9.servlet.ServletHandler","methodName":"doScope","lineNumber":515},{"fileName":"SessionHandler.java","className":"org.seleniumhq.jetty9.server.session.SessionHandler","methodName":"doScope","lineNumber":185},{"fileName":"ContextHandler.java","className":"org.seleniumhq.jetty9.server.handler.ContextHandler","methodName":"doScope","lineNumber":1061},{"fileName":"ScopedHandler.java","className":"org.seleniumhq.jetty9.server.handler.ScopedHandler","methodName":"handle","lineNumber":141},{"fileName":"HandlerWrapper.java","className":"org.seleniumhq.jetty9.server.handler.HandlerWrapper","methodName":"handle","lineNumber":97},{"fileName":"Server.java","className":"org.seleniumhq.jetty9.server.Server","methodName":"handle","lineNumber":499},{"fileName":"HttpChannel.java","className":"org.seleniumhq.jetty9.server.HttpChannel","methodName":"handle","lineNumber":310},{"fileName":"HttpConnection.java","className":"org.seleniumhq.jetty9.server.HttpConnection","methodName":"onFillable","lineNumber":257},{"fileName":"AbstractConnection.java","className":"org.seleniumhq.jetty9.io.AbstractConnection$2","methodName":"run","lineNumber":540},{"fileName":"QueuedThreadPool.java","className":"org.seleniumhq.jetty9.util.thread.QueuedThreadPool","methodName":"runJob","lineNumber":635},{"fileName":"QueuedThreadPool.java","className":"org.seleniumhq.jetty9.util.thread.QueuedThreadPool$3","methodName":"run","lineNumber":555},{"fileName":"Thread.java","className":"java.lang.Thread","methodName":"run","lineNumber":745}]}}
I suppose its a problem with configuration of behat, but im not sure, since im just started using behat and selenium. If someone got any idea what is wrong i would be very pleased to get some help.
You are missing the wd_host and capabilities options
try something like:
default:
suites:
default:
paths:
features: 'tests/features'
bootstrap: 'tests/features/bootstrap'
contexts:
- FeatureContext: ~
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
selenium2:
browser: "chrome"
wd_host: http://hub:4444/wd/hub
Also your hub, needs to be able to access your localhost.....where the tests are running.
First, try to checkout your apache/nginx etc of your server, to see if you are getting any access/visits from the selenium machine.
something like tail -f /var/log/apache/access.log
or wherever you are saving your files....if you get nothing, then obviously selenium is not accessing your machine
A different approach would be, to deploy your code for example of a test env, then you can do something in your behat.yml like:
Behat\MinkExtension:
base_url: http://my_test_host.com
I am trying to configure Behat3 to use SensionLabs PageObject Extension, but looks like it won't find it. I have the extension added to composer.json file and installed in vendor folder when I look into it.
Here is my behat.yml file
default:
suites:
default:
path:
features: features/site
contexts:
- SiteContext
system:
path:
features: features/system
contexts:
- SystemContext
extensions:
SensioLabs\Behat\PageOBjectExtension:
namespaces:
page: [Page]
MageTest\MagentoExtension\Extensions: ~
Behat\MinkExtension:
base_url: "http://somewebsite.local/"
selenium2:
wd_host: http://127.0.0.1:4444
browser: firefox
I think to have to have figured it out myself, I was using incorrect extension path it should have been
SensioLabs\Behat\PageObjectExtension\ServiceContainer\PageObjectExtension
I'm trying to run some Behat (3.0.15) tests from Jenkins but Behat is raising some failed steps.
For example for this step:
And I should click the header "Cómo Funciona" link
The error:
And I should click the header "C??mo funciona" link # test_behavior/Resources/features/Web/StaticPages/como_funciona.feature:9
[exec] "clickCMoFuncionaLink" method is not available on the Header (BadMethodCallException)
Our build.xml
<target name="behat">
<exec executable="vendor/bin/behat" failonerror="true">
<arg value="--tags=~#skip"/>
<arg value="--profile=jenkins"/>
<arg value="--format=progress"/>
</exec>
</target>
And our behat.yml
default:
suites:
default:
paths: [%paths.base%/test_behavior/Resources/features/Web]
contexts:
- TestBehavior\Context\BaseContext
service:
paths: [%paths.base%/test_behavior/Resources/features/Services]
contexts:
- TestBehavior\Context\BaseContext
- TestBehavior\Context\ServiceContext:
- http://xxxx
command:
paths: [%paths.base%/test_behavior/Resources/features/Commands]
contexts:
- TestBehavior\Context\BaseContext:
- false
- TestBehavior\Context\CommandContext
extensions:
Behat\MinkExtension:
base_url: http://xxxxx:8080
browser_name: chrome
selenium2:
wd_host: 10.0.2.2:4444/wd/hub
show_cmd: open -a Google\ Chrome %s
SensioLabs\Behat\PageObjectExtension:
namespaces:
page: [TestBehavior\Object\Page]
element: [TestBehavior\Object\Element]
jenkins:
suites:
default:
env: integration
service:
env: integration
contexts:
- TestBehavior\Context\BaseContext:
- false
- TestBehavior\Context\ServiceContext:
- http://xxxxxx
command:
env: integration
extensions:
Behat\MinkExtension:
base_url: http://xxxxx
selenium2:
wd_host: 10.52.2.84:4444/wd/hub
Locally everything works fine