I'm working to simplify a project's testing suite. There is a suite that uses PhpBrowser and %ABSOLUTE_URL% in the environment is set to "http://127.0.0.1:8888". The config:
class_name: InstallTester
params:
- env
modules:
enabled:
- PhpBrowser:
url: "%ABSOLUTE_URL%"
- \Helper\Install
For some reason, this project also uses an environment file travis_ci.yml:
# `travis_ci` environment config goes here
modules:
enabled:
- PhpBrowser:
url: "http://127.0.0.1:8888"
curl:
CURLOPT_TIMEOUT: 180
config:
Db:
dsn: "mysql:host=127.0.0.1;dbname=testdb"
user: "root"
password: ""
dump: '_data/dump.sql'
populate: true
cleanup: false
reconnect: true
The installation is run by the command:
codecept run install --env travis_ci
The PhpBrowser section in the environment file seems redundant to me. But if I remove the PhpBrowser section in travis_ci.yml, PhpBrowser fails to do the install suite. Am I understand the "params" configuration wrong? What could be the problem?
Dynamic configurations with params is only valid in codeception.yml. Not the suite configuration file.
So the install suite has no need for the params section:
class_name: InstallTester
modules:
enabled:
- PhpBrowser:
url: "%ABSOLUTE_URL%"
- \Helper\Install
Instead, add this section to the root level of codeception.yml:
params:
- env
The dynamic configurations should then work.
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 have a Symfony2 project, but I cannot get WebDriver configured properly.
I have installed facebook webdriver and codeception with composer:
facebook/webdriver:
versions : * 1.1.3
codeception/codeception:
versions : * 2.2.5
I followed these instructions (and when autoload failed, many other sources without success):
http://codeception.com/11-20-2013/webdriver-tests-with-codeception.html
codeception.yml in project root:
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
- WebDriver
config:
WebDriver:
url: 'http://localhost/'
browser: firefox
port: 4444
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql
I have acceptance tests generated, and when I run codeception, following error occurs:
[Codeception\Exception\ConfigurationException]
Class `WebDriver` is not defined. Autoload it or include into '_bootstrap.php' file of 'tests' directory
I've tried adding this into tests/_bootstrap.php:
require_once __DIR__.'/../vendor/codeception/codeception/src/Codeception/Module/WebDriver.php';
The path above is correct, the php file is found, but the problem persist.
Exactly how the autoloading or bootstrap including should be done?
EDIT:
I made the WebDriver enabling and configuration into tests/acceptance.suite.yml instead of root folder codeception.yml, and got over the problem.
Remains unclear why this happens?
WebDriver is not an extension, but a module.
You have to enable it in the modules section of acceptance.suite.yml file.
modules:
enabled:
- WebDriver
- \Helper\Acceptance
https://github.com/Codeception/Codeception/blob/2.2/tests/web.suite.yml
I run Codeception acceptance tests and get results:
As you see coverage is 0%
Then I open coverage results in browser from _output/acceptance.remote.coverage/index.html and see total coverage 81.13%
And the questions is: why coverage result not merged and not printed to console? I have to write unit-tests too for cover all methods?
acceptance.suite.yml
class_name: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: http://127.0.0.1:4444
- \Helper\Acceptance
codeception.yml
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
coverage:
enabled: true
c3_url: http://127.0.0.1:4444
remote: true
whitelist:
include:
- src/*
exclude:
- tests/*
extensions:
enabled:
- Codeception\Extension\RunFailed
Run tests command
codecept run --coverage --coverage-xml --coverage-html --coverage-text --fail-fast
Versions
Codeception PHP Testing Framework v2.2.2
Powered by PHPUnit 5.4.6 by Sebastian Bergmann and contributors.
Codeception won't merge your results, as stated in the documentation:
But if you run tests on different server [...] a single option remote should be added to config. [...]
In this case remote Code Coverage results won’t be merged with local ones, if this option is enabled. Merging is possible only in case a remote and local files have the same path. But in case of running tests on a remote server we are not sure of it.
Maybe you can do it manually by using phpcov.
I'm having a problem with Codeception.
I have a project that involving team, and I want to implement test with codeception and this test should work for everyone in my team.
currently I setup the test for my own-purpose, and here is the example configuration of it:
class_name: FunctionalTester
modules:
enabled:
# add framework module here
- Yii1
- \Helper\Functional
- PhpBrowser
- Db
config:
Yii1:
appPath: '/Volumes/disk0s4/www/new-proj/trunk/test.php'
url: 'https://my.proj.local/test.php'
PhpBrowser:
url: 'https://my.proj.didin/'
Db:
dsn: 'mysql:host=127.0.0.1;dbname=test-proj-new'
user: 'root'
password: 'root'
dump: ''
According to suite-configuration above, under config > Yii1 > appPath: the path is fixed, and it working well only for me, but unfortunately this configuration won't work for other people in my team. So other people should have self-configuration file for this, but keep to run the same test-file.
So, do you have any idea to handle the kind of this situation?
I really appreciate all of your input and thanks a lot for attention.
Thanks for #Rob forrest, so I put it as the answer here.
Currently I found a solution to get this situation,
I see --env option can be used to this, and here is the configuration:
class_name: FunctionalTester
modules:
enabled:
# add framework module here
- Yii1
- \Helper\Functional
- PhpBrowser
- Db
config:
Yii1:
appPath: '/Volumes/disk0s4/www/new-proj/trunk/test.php'
url: 'https://my.proj.local/test.php'
PhpBrowser:
url: 'https://my.proj.didin/'
Db:
dsn: 'mysql:host=127.0.0.1;dbname=test-proj-new'
user: 'root'
password: 'root'
env:
my_env:
modules:
enabled:
- Yii1
- \Helper\Functional
config:
Yii1:
appPath: 'path to index.php of my environment'
url: 'http://my.local/test.php'
production_env:
modules:
enabled:
- Yii1
- \Helper\Functional
config:
Yii1:
appPath: 'path to index.php of production environment'
url: 'http://my.local.com/test.php'
finally, to run the test, just add --env option as follows:
codecept run functional --env my_env or
codecept run functional --env production_env
at least this is the only way that I implemented for now, but I still open any input from all of you.
Thank you