Codeception autoload: 'WebDriver' is not defined - php

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

Related

Unable to load dynamic configurations in codeception suite configuration

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.

Codeception remote coverage not merged

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.

Codeception code coverage low

I have constructed a pretty complex code suite for a project with Codeception
approx 300 tests, with about 3000 assertions. Now I would like to see my codecoverage.
I ran the following line as per the instruction:
./vendor/bin/codecept run --coverage --coverage-html
I got a very low score (1%). Which is next to impossible considering that all the assertions that I have created does go to the designated spot in the code when the codecoverage states otherwise.
my codeception.yml file looks like this:
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
modules:
config:
\Helper\DbWithMigration:
dsn: 'mysql:host=localhost;dbname=travis_test'
user: 'travis'
password: ''
dump: tests/_data/dump.sql
coverage:
enabled: true
include:
- src/*
- console/*
I have tests for the following: unit, acceptance, console, and api.
They all turn green. I'm unsure where I went wrong
UPDATE
Here is my api.suite.yml:
class_name: ApiTester
modules:
enabled:
- \Helper\Api
- REST:
depends: Silex
- Silex:
app: 'tests/_app/bootstrap.php'
- \Helper\DbWithMigration:
cleanup: true
- Asserts
and acceptance.suit.yml:
class_name: AcceptanceTester
modules:
enabled:
- \Helper\Acceptance
- REST:
depends: Silex
- Silex:
app: 'tests/_app/bootstrap.php'
- \Helper\DbWithMigration:
cleanup: true
- Asserts
and as mentioned i'm running off a VM that has ubuntu 14.04 LTS and PHP 5.6.20 with xdebug.

Codeception is not rolling back DB changes in Laravel 5?

I am new to codeception and I am using it to test a web service I am creating in laravel 5. So my main config file looks like so:
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
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
config:
Db:
dsn: 'mysql:host=localhost;dbname=carparts'
user: 'root'
password: 'SomePassword'
dump: tests/_data/dump.sql
And the suite file called api.suite.yml looks like so:
class_name: ApiTester
modules:
enabled:
- Laravel5
- REST:
url: http://localhost:8000/api/
depends: PhpBrowser
config:
Laravel5:
cleanup: true
environment_file: .env.testing
I also copy pasted the whole dump of my database carparts into the dump.sql file but still when I run the tests, I still see new users created which are being created in the tests. What am I missing? Where am I going wrong?
So I did not know that in order to rollback the DB I need to enable the Db module:
class_name: ApiTester
modules:
enabled:
- Laravel5
- Db
- REST:
url: http://localhost:8000/api/
depends: PhpBrowser
config:
Laravel5:
cleanup: true
environment_file: .env.testing
And that did it.

Codeception, configure suite test path

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

Categories