I'm new using codeception and i try to do a simple test: Log in and check links inside.
I'm using $I = new AcceptanceTester($scenario); in my acceptance test but i see people using WebGuy($scenario) and i don't know the difference between WebGuy and AcceptanceTester.
SigninCept.php code:
<?php
//webLOG IN
$I = new AcceptanceTester($scenario);
$I->wantTo('Log in my app mobile');
//$I->amOnUrl('192.168.X.X/app/mobile/');
$I->amOnPage('/');
$I->fillField('user','test');
$I->fillField('password','test1234');
$I->fillField('zone','01');
//$I->uncheckOption('input[type=checkbox]');
$I->seeCheckboxIsChecked('#rememberme');
$I->seeElement('input[name=submit]');
$I->click('input[type=submit]');
//succes
$I->wantTo('Check main page');
$I->amOnPage('/principal.php');
$I->seeLink('salir','salir.php');
[...]
?>
Result(cmd):
C:\xampp\htdocs\public_html\codeception>php codecept.phar run acceptance --steps
Codeception PHP Testing Framework v2.0.9
Powered by PHPUnit 4.4.0 by Sebastian Bergmann.
Acceptance Tests (1) -----------------------------------------------------------
---------------------------------------
Trying to Log in App Mobile (SigninCept)
Scenario:
* I am on page "/"
* I fill field "user","test"
* I fill field "password","test1234"
* I fill field "zone","01"
* I see checkbox is checked "#rememberme"
* I see element "input[name=submit]"
* I click "input[type=submit]"
* I am on page "/principal.php"
* I see link "salir","salir.php"
[...]
PASSED
When i use $I = new WebGuy($scenario); i get this:
C:\xampp\htdocs\public_html\codeception>php codecept.phar run acceptance --steps
Codeception PHP Testing Framework v2.0.9
Powered by PHPUnit 4.4.0 by Sebastian Bergmann.
Acceptance Tests (1) -----------------------------------------------------------
---------------------------------------
Trying to Log in App mobile(SigninCept)
Scenario:
Fatal error: Class 'WebGuy' not found in C:\xampp\htdocs\public_html\codeception\tests\acceptance\SigninCept.php on line 3
FATAL ERROR. TESTS NOT FINISHED.
Class 'WebGuy' not found
in C:\xampp\htdocs\public_html\codeception\tests\acceptance\SigninCept.php:3
I have **WebGuy.php in my acceptance dir.**
If i do build i get this:
C:\xampp\htdocs\public_html\codeception>php codecept.phar build acceptance --steps
[RuntimeException]
Too many arguments.
build [-c|--config[="..."]]
Codeception 2.x use only AcceptanceTester.
As it was said, Guys were renamed to Testers. Actor classes and
helpers are named by suite. For instance, acceptance test will start
with this line:
<?php
$I = new AcceptanceTester($scenario);
// and uses AcceptanceHelper
?>
See here : http://codeception.com/06-06-2014/codeception-2.0-final.html
The name of the "guy" depends on what you have in codeception configuration of your suite (in your case the acceptance suite):
# acceptance.suite.yml
class_name: AcceptanceTester
modules:
enabled:
- WebDriver
...
When running codecept build the guy class will be created integrating all the methods of the modules you have defined, and it will then used by CodeCeption when running the tests. Any other classes will be ignored.
Also see the help for the build command (codecept help build) to see what options you can pass to it (i.e. normally you don't need any option).
the WebGuy class is only a custom class that extends from the AcceptanceTester Class. You can implement your own and call it from the acceptance.suite.yml
class_name: AcceptanceTester ==> or ==> WebGuy // here is the call of the class
modules:
enabled:
- WebDriver:
url: 'http://local.symmetryk.com/'
browser: firefox
window_size: maximize
wait: 10
capabilities:
unexpectedAlertBehaviour: 'accept'
env:
chrome:
modules:
config:
WebDriver:
browser: 'chrome'
- Db:
hope this will help you understand :)
Related
I have an application with different modules. For each module, there are separate tests written which are divided in different suites.
For example in tests/Custom/codeception.yml
namespace: Test\Custom
paths:
tests: .
data: _data
support: _support
log: _output
coverage:
enabled: true
remote: false
whitelist: { include: ['../../../../src/*'] }
suites:
Business:
path: Business
...
View:
path: View
....
So every module has its own codeception.yml.
To have one "master config" there is a codeception.yml in the first level of the test folder which is including all the subfolder module yml with
namespace: Test
actor: Tester
include:
- tests/*
...
When running a build caused by a branch update in the repository we usually don't want to run other tests than business because they are slow and fragile.
For this i try to run codecept run Business and expect, that just the Business suites from the included files will be executed.
But this will not work, instead i get the error message
Suite 'Business' could not be found
But when i run one module explicit with Business suite
codecept run -c tests/Custom Business
it works.
My first assumption was, that the files get not proper included to the master yml so i tried the general call
codecept run
and it works! But this unfortunately runs all suites.
So, why the suites cant be seen by the master codeception.yml? How can i run all tests Business suites without pointing explicit to the module path?
Thanks
everyone!
I have been trying to configure Codeception 2.3.6 with Laravel 5.3.30 running on PHP 7.0.23 powered by WAMP 3.1.0. My functional test cases are running fine, but when I try to run my acceptance test cases, a new chrome window opens and then closes without doing anything.
The output in the HTML Report is Codeception Results OK(0s), while the output on the command line is:
WelcomeCept: Perform actions and see result (0.00s)
Time: 3.24 seconds, Memory: 22.75MB
OK (1 test, 0 assertions)
HTML report generated in file://D:\wamp\www\myApp\tests/_output\report.html
First I start ChromeDriver with the command
chromedriver --url-base=/wd/hub
Then I start Selenium Standalone Server 3.13.0 with the command:
java -Dwebdriver.chrome.driver="chromedriver" -jar selenium-server-standalone-3.13.0.jar -port 4445
Then I run my acceptance test suite which contains a single test file, with the command:
call vendor/bin/codecept run acceptance --html
My acceptance.suite.yml is:
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://lcms.com/
window_size: false # disabled in ChromeDriver
port: 9515
browser: 'chrome'
restart: true
wait: 200
capabilities:
unexpectedAlertBehaviour: 'accept'
webStorageEnabled: true
javascriptEnabled: true
- Laravel5:
part: ORM
cleanup: false # can't wrap into transaction
environment_file: .env
- \Helper\Acceptance
My WelcomeCept.php file, just for testing the configuration, is:
<?php
class WelcomeCept
{
public function welcomeTest(AcceptanceTester $I)
{
$I->wantTo('perform actions and see result');
}
}
Please review my workflow and let me know if I'm doing things incorrectly or am missing something.
Thanks!
Update: Same thing is happening using GeckoDriver or PhantomJS in WebDriver mode. The tests are passing with OK but not performing any actions.
Solved! I tried WelcomeCest instead of WelcomeCept and things have fallen into place.
In order to record my tests I run codeception with this command
codecept --ext Recorder
However I can't manage to record anything. Does one see what I'm doing wrong?
Codeception Recorder is disabled, no available modules:
gravityflow/codeception.dist.yml
gravityflow/plugin/tests/acceptance-tests/acceptance.suite.yml:
You're using the WordPress module, WPWebDriver. You need to tell recorder it's active. Put this in your main codeception.yml file:
extensions:
enabled:
- Codeception\Extension\RunFailed
- Codeception\Extension\Recorder
config:
Codeception\Extension\Recorder:
delete_successful: false
module: WPWebDriver
I have set up a functional test following the tutorials at:
http://codeception.com/docs/04-FunctionalTests
http://codeception.com/docs/modules/Symfony
http://codeception.com/09-04-2015/using-codeception-for-symfony-projects.html
The main difference is that I've set up Codeception the traditional way because I don't want to mix test code with project code.
This is my functional test (I know it's not actually testing anything):
<?php
class MyFirstCest {
public function _before(FunctionalTester $I) {
}
public function _after(FunctionalTester $I) {
}
// tests
public function tryToTest(FunctionalTester $I) {
$I->amOnPage('/app/login/');
}
}
When I run the functional test I get:
[RuntimeException] Call to undefined method FunctionalTester::amOnPage
When I rebuild Codeception, I get:
Building Actor classes for suites: acceptance, functional, unit
-> AcceptanceTesterActions.php generated successfully. 0 methods added
\AcceptanceTester includes modules: PhpBrowser, \Helper\Acceptance
-> FunctionalTesterActions.php generated successfully. 0 methods added
\FunctionalTester includes modules:
-> UnitTesterActions.php generated successfully. 0 methods added
\UnitTester includes modules: Asserts, \Helper\Unit
The critical part seems to be \FunctionalTester includes modules: which is empty.
My functional.suite.yml file looks like this:
actor: FunctionalTester
modules:
- Symfony:
app_path: 'app'
environment: 'local_test'
class_name: FunctionalTester
modules:
enabled:
- Symfony2:
app_path: 'path/to/app'
var_path: 'path/to/app'
- Doctrine2:
depends: Symfony2
- \Helper\Functional
- PhpBrowser:
url: dev.hmr-app
- \AcmeBundle\Helper\Functional
where the Symfony app lives in path/to/app. I know there's a lot of junk in there, but that's because I've been experimenting, trying to get it to work.
What am I doing wrong?
I think that your problem is that you have
modules:
- Symfony:
app_path: 'app'
environment: 'local_test'
in the config.
That section is completely misplaced and it probably is causing you issues.
Please remove it and rename Symfony2 with Symfony in enabled section.
Also make sure that you are using the latest version of Codeception.
I'm trying to get into using codeception for my acceptance testing.
I have the following for one of my tests:
<?php
use Codeception\Util\Stub;
class SomeTest extends \Codeception\TestCase\Test
{
protected $webGuy;
/**
* #test
*/
public function incorrect_login_should_redirect_back()
{
$I = $this->webGuy;
$I->wantTo('fail at logging in');
$I->amOnPage('/'); // <-- This is the line that is failing
$I->fillField('email','info#tntstudio.hr');
$I->fillField('password','pass');
$I->click('Login');
$I->see('email', 'input');
$I->seeCurrentUrlEquals('/login');
}
}
Initially the tests ran OK, however after adding Laravel4 to the acceptance.suite.yml file and running build, the test now fails with the following:
1) SomeTest::incorrect_login_should_redirect_back
Symfony\Component\HttpKernel\Exception\NotFoundHttpException:
#1 /Applications/MAMP/htdocs/hired/vendor/laravel/framework/src/Illuminate/Routing/Router.php:1021
#2 /Applications/MAMP/htdocs/hired/vendor/laravel/framework/src/Illuminate/Routing/Router.php:989
#3 /Applications/MAMP/htdocs/hired/vendor/laravel/framework/src/Illuminate/Routing/Router.php:968
#4 /Applications/MAMP/htdocs/hired/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:738
#5 /Applications/MAMP/htdocs/hired/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:708
#6 /Applications/MAMP/htdocs/hired/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Client.php:81
#7 /Applications/MAMP/htdocs/hired/vendor/symfony/browser-kit/Symfony/Component/BrowserKit/Client.php:325
#8 /Applications/MAMP/htdocs/hired/app/tests/acceptance/WebGuy.php:476
#9 /Applications/MAMP/htdocs/hired/app/tests/acceptance/SomeTest.php:16
I'm running my app in a virtual environment using vagrant, at http://localhost:3030/
I have set this to the url for the PhpBrowser config in acceptance.suite.yml as below:
class_name: WebGuy
modules:
enabled:
- PhpBrowser
- WebHelper
- Laravel4
config:
PhpBrowser:
url: 'http://localhost:3030/'
I'm wondering if anybody else has come across this, or has any ideas on how to get around this, I've been tearing my hair out for hours on this.
Laravel4 module will cause Codeception to use the "testing" environment in Laravel.
Laravel will disable all route filters in "testing" environment - so your filters are not working correctly and its probably calling the wrong route, causing your app to die and your test to fail.
I dont think using the Laravel4 module with "acceptance" tests is correct - it should only be for functional tests? Edit: I just found that the Codeception Laravel4 module docs actually say "This module allows you to run functional tests for Laravel 4" - so I guess it was not actually designed for Acceptance tests?
But with all the changes in Codeception 2.x - you are better off using PhpBrowser module for your acceptance tests, and Laravel4 module for your functional tests.
If you are using Homestead, I do this in my start.php file to detect if Codeception is running, and specifically put it into a 'codeception' environment, otherwise I let it run my environment detection normally
if ((gethostname() === 'homestead') && (isset($_SERVER['REMOTE_ADDR'])) && ($_SERVER['REMOTE_ADDR'] === '127.0.0.1'))
{
$env = $app->detectEnvironment(['codeception' => ['homestead']]);
}
else
{
$env = $app->detectEnvironment(['dev' => ['homestead']]);
}
Then in my 'codeception' environment, I setup a SQLite file database, and run acceptance tests against that (which is faster than mySQL testing).
You don't even have to change your start.php. You can set the environment for codecption in the laravel4 Module config. So in your acceptance.suite.yml it will look like this:
modules:
enabled: [PhpBrowser, WebHelper, Laravel4]
config:
Laravel4:
environment : 'codeception'
filters : true
Now, when you execute php codecept run acceptance in your terminal, the Laravel4 Module will use the configuration files from app/config/codeception.
Was not able to find a solution to this, so for now am going to just go without the Laravel4 module, sadly.