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
Related
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.
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 want to use Codeception to write some acceptance tests in symfony 2 project. I don't want to use PhpBrowser but symfony envoriment.
Original acceptance.suite.yml
class_name: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: http://localhost/myapp
- \Helper\Acceptance
I change it to:
class_name: AcceptanceTester
modules:
enabled: Symfony2
config:
Symfony2:
app_path: 'app'
environment: 'test'
But now i can't use \Helper\Acceptance to write my tests using codeception
$I = new AcceptanceTester($scenario);
$I->wantTo('choose my store');
$I->amOnPage('/');
$I->amGoingTo('/welcome');
How to set up config to run tests on app, instead via PhpBrowser?
It looks like you used pre-2.1 style of configuration.
http://codeception.com/06-30-2015/codeception-2.1-is-here.html
Module config simplified: Modules can be configured in enabled section of suite config. Take a look of this sample declaration of Api suite, there is no config section inside modules.
Correct way is:
class_name: AcceptanceTester
modules:
enabled:
- Symfony2:
app_path: 'app'
environment: 'test'
http://codeception.com/docs/modules/Symfony2#Example-functionalsuiteyml---Symfony-2x-Directory-Structure
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.
I have a PHP project with Codeception on which several developers are working. Everyone have their own environment and different URL to their copy of the project. But in Codeception Functional/Acceptance yml config file we have to set up URL for acceptance and functional tests.
How could we have different URL to project and have main part of configs in repository?
Thank you in advance.
One way to solve this is to look at the $_SERVER['HOSTNAME'] value and select the appropriate url from that. I've currently got this in my tests/acceptance/_bootstrap.php
switch($_SERVER['HOSTNAME'])
{
case 'dev1':
$base_url = 'http://www.example.com.dev1';
break;
default:
$base_url = 'http://www.example.com';
break;
}
define("BASE_URL",$base_url);
You can then make use of this constant in a test
$I = new AcceptanceTester($scenario);
$I->wantTo('ensure that the a user can log in');
$I->amOnUrl(BASE_URL . "/home");
I have same problem. I asked same question here. I used --environment option to get this working.
here is the example 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'
I know that config contains duplicated-lines and should be able to be simplified, I've tried to simplify by removing duplicate line at global modules, but seems doesn't work to me.
So I let the config as you see above and I have created Issue for it, but still wondering if someone get this overriding working.
I hope this helps to anyone.