Hey there,
I am not sure if this is the right place to ask questions about problems but my current problem is:
I was creating some helper files to reuse code and I am not sure how but the codecept run acceptance command throws this error:
[Symfony\Component\Debug\Exception\FatalErrorException] Cannot redeclare _generated\AcceptanceTesterActions::switchToIFrame()
I am using the Laravel5 module and the Webdriver module with chrome as a browser.
I am using Codeception 2.1.3 and PHPUnit 4.8.10
Does anyone know how can I solve this problem?
It could be a bug.
Are you using Laravel5 and WebDriver in the same suite?
WebDriver has switchToIFrame method,
Laravel5 inherits a new switchToIFrame method from InnerBrowser class.
See if downgrading to 2.1.2 helps.
Yeah I use them both in the same suite (acceptance),
is the order of the modules included in my acceptance file. I am using Laravel5 mostly for some Model references and dummy data generation.
Oh and now that you mentioned the downgrade, I think that this error started showing up when I upgraded codeception to 2.1.3
I downgraded it to 2.1.2 (PHPUnit was updated to 4.8.11) and now the tests work again!
Thanks for your help :)
Also, while I am still here, I have a quick question: When I run codecept build, I see the list of module names and helpers but the number of methods added is 0 every time I run the command (compared to some older codeception videos where the numbers change)
WebDriver
How is this possible? They should throw conflict exceptions. These modules share same interface and should not be working together.
Also, while I am still here, I have a quick question: When I run codecept build, I see the list of module names and helpers but the number of methods added is 0 every time I run the command (compared to some older codeception videos where the numbers change)
Error generating Actor class happened.
I had an impression that Laravel5 module integrates with WebDriver, but I can't find a source where did it come from.
I have no idea how it works but I don't get any exceptions. How am I suppose to do acceptance testing? Should I use one of the modules? (I see they use the (almost) same methods.
Also, I don't get any error generating Actor Class (maybe it happened the first time but it doesn't show anymore). How can I fix this?
@Rufflesaurus acceptance testing should be done without Laravel module - it is for funcitonal testing only.
The difference is how module connects to application. Laravel5 expects application to be connected internally via PHP inclusion, while WebDriver connects to application through webserver. Mixing those modules together may provide you unexpected results - as you are connecting to two different aplications! Depending on position of module in config list you are switching them - so you can not be sure how you are testing: with WebDriver or Laravel in each case.
Just don't use Laravel module for acceptance testing. The only fix here is to throw exceptions when you try to load Laravel + WebDriver
P.S. Not sure why error appeared only now but @Naktibalda added a method to Laravel5 which has the same signature as a method of WebDriver
Ok cool, thanks! I was using the Laravel5 module for rerunning the seeds to cleanup + repopulate some of the tables. Now I gotta figure out a better way to reset the database when each test is run, for scenarios like deleting, or a need of already existing data for a scenario etc.
I hate to comment on a closed issue, but I cannot figure out how to get acceptance testing working without the Laravel5 module.
this is my 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
- Codeception\Extension\Recorder
modules:
enabled:
- Db:
dsn: 'pgsql:host=localhost;port=5432;dbname=test;user=test_user;password='
user: 'test_user'
password: ''
dump: tests/_data/dump.sql
cleanup: true
And my acceptance.suite.yml:
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://eagle.app/
browser: firefox
- \Helper\Acceptance
And my database config:
'default' => env('DB_CONNECTION', 'pgsql'),
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => database_path('database.sqlite'),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'screaming_eagle'),
'username' => env('DB_USERNAME', 'freedom'),
'password' => env('DB_PASSWORD', 'Rock!Eagle!Flag!'),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
'test' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => 'test',
'username' => 'test_user',
'password' => '',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
],
],
But when I delete the local DB/roles and run the test, I can see from the screenshots that the acceptance test is using my local db setup.

The only way I can get laravel to work with the testing database is to set variables using a seperate .env.testing file. But that's only possible by using the Laravel5 module, which according to this board I shouldn't do. Then how do I get my acceptance suite to use the correct DB?
Codeception has no control over application configuration or environment when WebDriver or PhpBrowser is being used. You have to configure your application to use test database. You can use a different deployment of site for it.
I hate to comment on a closed issue too, but skipping all the theory and semantic dispute, acceptance tests are just like functional tests, they just happen to run on a real browser because javascript needs to be tested. If I can use Laravel 5 with InnerBrowser, I should be able to use Laravel 5 with WebDriver as well.
I just wanted to let you know that using both modules was really useful in scenarios like the ones Rufflesaurus cited.
WebDriver and PhpBrowser tests are blackbox tests - they can't see what's inside app and they can't affect it.
Codeception would have to act as a webserver to make a combination of framework module and WebDriver work.
I've just run into this same issue. Its understandable that the Laravel5 module would not actually be driving the tests but it would be real nice to use WebDriver and Laravel5 together. WebDriver would drive the tests and Laravel5 would manage the database, ie have access to the models to set up the tests.
You can use Db module for that.
Not really, or at least I cant see a way to do that. The DB module has a grabFromDatabase method but that only retries a single column. I want the entire model.
Related ticket: #2470
@devinfd You can use the seeInDatabase method of the Db module, that's similar to the seeRecord method in the Laravel module.
And what do you need to do with an actual model object in your acceptance tests?
I'm looking for a way to set up the conditions of the test. Using Laravel, I can manipulate the models or even Laravel factories to create the needed conditions.
Ok. Maybe you can try to load only the ORM part of the Laravel 5 module. I haven't tried that myself, but it just occurred to me that that just might work. You can find some explanation in the following post: http://codeception.com/06-30-2015/codeception-2.1-is-here.html. Search for the text "Modules can be partially loaded" somewhere in the middle of the post.
Yes! adding
modules:
enabled:
- Laravel5:
part: ORM
to the acceptance.suite.yml file worked perfectly. Thanks so much!
Ok great.
@devinfd I have been thinking some more about this solution, and it will work for now, but it will probably stop working for upcoming releases of Codeception, my guess is the 2.2 release. This is because there is already functionality implemented for conflicting modules, for example WebDriver and Laravel 5, but due to a bug this functionality currently does not work. But this will be fixed in 2.2 and in that case this solution will not work anymore.
But there is a better solution. You can simply add the following lines of code to the _bootstrap.php file of your test suite to load all Laravel functionality:
require 'bootstrap/autoload.php';
$app = require 'bootstrap/app.php';
$app->loadEnvironmentFrom('.env.testing');
$app->instance('request', new \Illuminate\Http\Request);
$app->make('Illuminate\Contracts\Http\Kernel')->bootstrap();
With this solution you can remove the Laravel module from your suite configuration and you will not run into problems when we release the fix for the module conflicts functionality.
@janhenkgerritsen sorry for this super late response.
Yes I had considered this solution but was hoping there was a more "config friendly" way to get what I wanted. Even still its good to know this solution will work when the update is released. Thanks!
Wow this is awful. I have been working on trying to get Codeception to work literally all day. I am getting this exact error, except I am not using Larvel5 Is there something else that causes this to generate wrongly?
UPDATE: I did a search and replace on switchToIframe case sensitive and replaced it with switchToIFrame and not it worked.
@bjcullinan The solution provided by @janhenkgerritsen seems to work for me. You just need to add this to acceptance/_bootstrap.php. What error are you seeing? This is only needed for acceptance using WebDriver module, functional tests don't need any workaround if you use only Laravel5 module:
class_name: FunctionalTester
modules:
enabled:
- Laravel5
- FunctionalHelper
config:
Laravel5:
environment_file: .env.testing
I was getting Cannot redeclare switchToIframe because there is a switchToIframe function in InnerBrowser and a switchToIFrame function in WebDriver.
@bjcullinan Could you please open a new issue and provide some more details, for example the version of Codeception you are using, your suite configuration file and the exact error message you get?
Most helpful comment
Yes! adding
to the acceptance.suite.yml file worked perfectly. Thanks so much!