Quantcast
Channel: Codeception
Viewing all 762 articles
Browse latest View live

Acceptance test with vhost returns a reponse with status code 406

$
0
0

@Stijn_Blommerde wrote:

problem: I get a status code 406 as response to my acceptance test. I am not able to retrieve html.

The url http://amsterdam.localhost.com:8000/login returns my login page in the browser

I can fetch the html with cUrl from the command line, like so:
curl http://amsterdam.localhost.com:8000/login

amsterdam.localhost.com is a vhost and maps to 127.0.0.1

# acceptance.suite.yml
actor: AcceptanceTester
modules:
    enabled:
        - PhpBrowser:
            url: http://amsterdam.localhost.com:8000/
        - \Helper\Acceptance

# Acceptance/MyFirstCept.php
<?php 
$I = new AcceptanceTester($scenario);
$I->wantTo('open up the root test page and see the login screen');
$I->amOnPage('/login');

Posts: 2

Participants: 2

Read full topic


[Yii 1.1] Mocking CHttpRequest or PHP Server globals in Codeception

$
0
0

@mashiox wrote:

I'm integrating Codeception into an existing Yii 1.1 application. I've gotten Codeception's unit tests running, and I'm working on building up the components necessary for good functional testing, like mocking, stubs, and fixtures.

When the functional testing suite is executed, the app entry point test.php produces an error that CHttpRequest is unable to determine the request URI. The suite isn't being executed with Apache running, so it makes sense these aren't present.

I know the application is heavily reliant on PHP's superglobals, particularly _SERVER, and that Yii 1.1 hydrates itself with these values so I must mock these parameters somehow, but I am confused on how to do this.

So far, I have come across PHPUnit\Framework\TestCase's mock building, as well as AspectMock.
I think one way that I could do this is to use PHPUnit's TestCase to mock the methods from Yii's CHttpRequest, but I think this would leave parameters like _SERVER mal-defined, and the application still uses these supers frequently.

Is there a best practice or recommended method for defining globals like _SERVER? Perhaps creating a mock of _SERVER and including it into the test entry point would be sufficient?

Thanks for any help, and advancement in a sound direction.

Posts: 1

Participants: 1

Read full topic

Does Selenium WebDriver create session cookie with session_start?

$
0
0

@pir1981 wrote:

Hi,

I have index.php where I set the cookie with session_start (), which gets me in "real life" the session cookie "PHPSESSID"

Now I just want to see that the cookie exists with

$I->amOnPage('/index.php');
$I->seeCookie('PHPSESSID');

but I get

Fail Failed asserting that an array contains 'PHPSESSID'.

My assumption is that Selenium, given that it is a server, does create that cookie. So why can't I find it. I am slowly coming to believe that I have to set it manually, but I can't find the right documentation (although I am sure, it must be out there).

My config is as follows:

acceptance.suite.yml

 actor: AcceptanceTester
 modules:
     enabled:
         - WebDriver:
             url: http://nginx-web/     
             browser: chrome
             host: chrome                
             window_size: maximize
         - \Helper\Acceptance

Any help is appreciated!

Posts: 1

Participants: 1

Read full topic

Difference between Acceptance.php and AcceptanceTester.php

$
0
0

@robE127 wrote:

I notice that both files are for defining custom actions. The actions I put in either of these files are available through $I in my acceptance tests. What is the purpose of the differentiation here? What types of things should I put in the module extension Acceptance.php vs the actor extension AcceptanceTester.php?

Posts: 1

Participants: 1

Read full topic

Phalcon module, _request method trouble

$
0
0

@Dmitry_Andreevich wrote:

Hi,

I'm writing tests for my API application on Phalcon. I tested it with REST module (depends: PhpBrowser), and everything worked well. But I need my API to interact with test database so I tried to do similar with help of Phalcon Module.

I make request in this way in helper class:

public function addEventLog($eventName, $logData) {

        $json = $this->getModule('Phalcon')->_request('POST', '/event/add/' . $eventName, [], [], [], json_encode(['four' => 4]));
        $response = json_decode($json);
        return $response;
    }

As a result my application got the POST and handle it but there is no JSON part in the request. I've made everything according to codeception Phalcon documentation. The content part and content type of a request is missing. I don't know why but this _request method doesn't send json body, as a part of the request. Maybe it is my misunderstanding or a bug.
I have already tried every configuration of parameters, it didnt work either.
Also, I didnt find any usefull information in google on this topic.
Please help.

Im working on OS Linux, and using apache with php version 7.1.

Posts: 1

Participants: 1

Read full topic

Run pararell Codeception testsuites using docker and chrome nodes with selenium grid

$
0
0

@Jakub_Gladykowski wrote:

Hi,

I try to run different testsuites (not test cases from same suite) in pararell using selenium grid and chrome nodes. But I get error Can't connect to Webdriver at http://hub:4444/wd/hub when I run more than one test suite at once.

I start one Codeception, Selenium hub and 3 Chrome nodes. Then I do docker-compose scale chrome=3 to get 3 chrome instances. This is my docker-compose.yml:

version: '3'
  services:
  codecept:
    build: e2e_tests
    volumes:
      - './e2e_tests:/project/tests'
      - './codeception.yml:/project/codeception.yml'

  hub:
    image: "selenium/hub"
    ports:
      - 4444:4444    
      
  chrome:
    image: "selenium/node-chrome-debug"
    links:
      - hub:hub
    volumes:
      - /dev/shm:/dev/shm
    environment:
      - HUB_PORT_4444_TCP_ADDR=hub
      - HUB_PORT_4444_TCP_PORT=4444
      - NODE_MAX_INSTANCES=3
      - NODE_MAX_SESSION=3

This is part of codeception.yml responsible to connect to webdriver.

 WebDriver:
        host: hub
        browser: chrome
        port: 4444

Then on our Jenkins machine I execute 2 testruns at the same time using command docker-compose run --rm codecept run

Any ideas how to make it work ? Is this limitation in Codeception ? What I want to achieve is more than one testrun running at the same time. I thought only limitation will be number of chrome nodes :frowning:

Posts: 1

Participants: 1

Read full topic

Need Help with Windows 10 and Internet Explorer

$
0
0

@Escapio1 wrote:

Hi,

I am currently using Codeception under Windows 10 64bit. The Editor I am using is Visual Studio Code.
I can run the tests under Chrome and Firefox without any problems, but not under Internet Explorer.
I am using Selenium Server 3.8.1 and the latest IEDriverServer. When I start a test like ".\vendor\bin\codecept run --env explorer", the test starts in chrome not internet explorer.

My env for IE looks like:

explorer:
  modules:
     config: 
        WebDriver:
            browser: 'internet explorer'
   extensions: 
      enabled: 
         - Codeception\Extension\RunProcess:
           - java -jar C:\Server\selenium-server-standalone-3.8.1.jar

And another question is, that the first test always fails. For example, if I got 5 tests, die first test always fails.

Hope someone can help me.

Posts: 3

Participants: 2

Read full topic

I want to use _before and _after hooks on the scenario


Stop test with dataProvider

$
0
0

@Cherrish wrote:

Friends,
I've created test with using data provider (further DP). If test with one pool of data from DP fails, all next should stop. at_depends works only with separate methods, and I use the only one. If to split one test to a few, loosing DP advantage, what can be done to stop implementing all N+1 tests after N test fails? To make DP dependable on test failure.

code:
/**
* at_dataprovider pageProvider
*/
public function staticPages(Tester $I, \Codeception\Example $example)
{
$I->doSteps($example['firstStep'],$example['secondStep']);
}

/**
 * at_return array
 */
protected function pageProvider()
{  return
    [
        ['firstStep'=>"Came In", 
	  'secondStep'=>"Came to step 1"] ,
        
        ['firstStep'=>"Came to step 1", 
	  'secondStep'=>"Came out"] 
    ];
}

at_ - means symbol at.

Posts: 1

Participants: 1

Read full topic

How to add Gmagick class to Codeception? I get an error

$
0
0

@Vilius wrote:

Hello, i'm trying to use Gmagick from codeception, and i get:

[Error] Class 'Helper\Gmagick' not found
or
[Error] Class 'Gmagick' not found
if i try calling Gmagick(); directly from the test.

I've set up Gmagick and can use it i.e. if i create a standalone *.php file on my apache server, i can call Gmagick(); without ever declaring anything else.

If I try the same from within Codeception, I get aforementioned error. I suppose there's some simple fix to this but I can't get any useful info from Codeception's documentation, and i can't find any useful info on the internet either :frowning2:

Any help would be appreciated. Thank You :slight_smile:

Posts: 1

Participants: 1

Read full topic

Codeception XPath alternatives for elements

$
0
0

@Escapio1 wrote:

Are there any alternatives in Codeception to work with the elements of a website.
For now I am using XPath but the problem is, that sometimes Codeception runs fine and sometimes it just cant find the XPath.

What would be more efficient and reliable than using the XPath?

Thanking all of you in advance

Posts: 2

Participants: 2

Read full topic

Strange issue with Yii/Codeception/Docker/PhpStorm combination

$
0
0

@borgdrone7 wrote:

My tests run just fine from command line, but from PhpStorm I get very strange issue. For some reason assertNull when called from PhpStorm tries to convert parameter (ActiveObject) to string which in turn causes Codeception code in Step.php to check if the object is mocked, which calls __isset on ActiveRecord (as __mocked is not defined) and that causes ActiveRecord to try and check the attribute in schema which fails as Yii app object is null at that moment. Here is output of both runs as well as code with some comments (I would appreciate concrete answer to why is this happening and how can I solve it instead of some general advice like best practices, code smell, etc. as this code is just temporary and is not meant to be used later on). Thanks in advance:

CODE ***************************************

public function databaseReady(\FunctionalTester $I)
{
    try {
        $I->assertSame("test", Yii::$app->db->createCommand("SELECT DATABASE()")->queryScalar(), "We are connected to test database");
    } catch (Exception $e) {
        codecept_debug("Error from test:".$e->getMessage());
    }
    $user = User::findActive()->one();
    codecept_debug($user->first_name);
    //this fails from PhpStorm but works from command line, why? What I know so far:
    //Codeception step tries to stringify User ($user) object
    //Then it checks if it has __mocked and since isset is used on non existing prop, __isset is called on ActiveRecord
    //Then active records sees there is no __mocked in attributes
    //Then it tries to load it from schema
    //Then it fails in ActiveRecord.php 135 because Yii::$app is null at that moment
    //If I var_dump Yii::$app after this line it's not null, not sure why it happens but it is real problem
    $I->assertNotEmpty($user, "User is loaded from database");
    $I->assertSame("admin TEST !5!6!9!", $user->first_name, "Test database user is used");
}

CODE ***************************************

COMMAND LINE ***********************************************************************************************

$ docker exec -it sceal_console_1 bash -c "./vendor/bin/codecept run functional --debug"
Codeception PHP Testing Framework v2.4.1
Powered by PHPUnit 6.5.7 by Sebastian Bergmann and contributors.

[Db] Connected to test
[Db] Connected to test
[Db] Executing Populator: mysql -uroot -ptest -hsceal_testdb_1 test < tests/_data/sceal_clean.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[Db] Populator Finished.

Functional Tests (1) -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Modules: Filesystem, Yii2, Asserts, Db
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------AttachmentsCest: Database ready
Signature: tests\AttachmentsCest:databaseReady
Test: tests/functional/AttachmentsCest.php:databaseReady
Scenario --
Destroying application
Starting application
[Fixtures] Loading fixtures
[Fixtures] Done
[yii\db\Connection::open] 'Opening DB connection: mysql:host=sceal_testdb_1;dbname=test'
I assert same "test","test","We are connected to test database"
admin TEST !5!6!9!
I assert not empty "common\models\User","User is loaded from database"
I assert same "admin TEST !5!6!9!","admin TEST !5!6!9!","Test database user is used"
PASSED

Destroying application
Suite done, restoring $_SERVER to original


Time: 5.99 seconds, Memory: 14.00MB

OK (1 test, 3 assertions)

COMMAND LINE ***********************************************************************************************

PHP STORM *********************************************************************

Testing started at 17:10 ...
docker://sceal_console:latest/php /opt/.phpstorm_helpers/codeception.php run --report -o "reporters: report: PhpStorm_Codeception_ReportPrinter" --no-ansi --no-interaction --debug -c /opt/project/codeception.yml functional
Codeception PHP Testing Framework v2.4.1
Powered by PHPUnit 6.5.7 by Sebastian Bergmann and contributors.
mysql: [Warning] Using a password on the command line interface can be insecure.
An Error occurred while handling another error:
Error: Call to a member function has() on null in /opt/project/vendor/yiisoft/yii2/web/ErrorHandler.php:91
Stack trace:

0 /opt/project/vendor/yiisoft/yii2/base/ErrorHandler.php(111): yii\web\ErrorHandler->renderException(Object(Error))

1 [internal function]: yii\base\ErrorHandler->handleException(Object(Error))

2 {main}

Previous exception:
Error: Call to a member function getDb() on null in /opt/project/vendor/yiisoft/yii2/db/ActiveRecord.php:135
Stack trace:

0 /opt/project/vendor/yiisoft/yii2/db/ActiveRecord.php(382): yii\db\ActiveRecord::getDb()

1 /opt/project/vendor/yiisoft/yii2/db/ActiveRecord.php(418): yii\db\ActiveRecord::getTableSchema()

2 /opt/project/vendor/yiisoft/yii2/db/BaseActiveRecord.php(492): yii\db\ActiveRecord->attributes()

3 /opt/project/vendor/yiisoft/yii2/db/BaseActiveRecord.php(289): yii\db\BaseActiveRecord->hasAttribute('__mocked')

4 /opt/project/vendor/yiisoft/yii2/db/BaseActiveRecord.php(335): yii\db\BaseActiveRecord->get('mocked')

5 /opt/project/vendor/codeception/codeception/src/Codeception/Step.php(176): yii\db\BaseActiveRecord->isset('mocked')

6 /opt/project/vendor/codeception/codeception/src/Codeception/Step.php(164): Codeception\Step->getClassName(Object(common\models\User))

7 /opt/project/vendor/codeception/codeception/src/Codeception/Step.php(103): Codeception\Step->stringifyArgument(Object(common\models\User))

8 /opt/project/vendor/codeception/codeception/src/Codeception/Step.php(235): Codeception\Step->getArgumentsAsString(200)

9 /opt/.phpstorm_helpers/codeception_24_56.php(337): Codeception\Step->getHumanizedArguments()

10 /opt/project/vendor/phpunit/phpunit/src/Framework/TestResult.php(408): PhpStorm_Codeception_ReportPrinter->endTest(Object(Codeception\Test\Cest), 0.089478015899658)

11 /opt/project/vendor/codeception/codeception/src/Codeception/Test/Test.php(111): PHPUnit\Framework\TestResult->endTest(Object(Codeception\Test\Cest), 0.089478015899658)

12 /opt/project/vendor/phpunit/phpunit/src/Framework/TestSuite.php(755): Codeception\Test\Test->run(Object(PHPUnit\Framework\TestResult))

13 /opt/project/vendor/codeception/phpunit-wrapper/src/Runner.php(106): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))

14 /opt/project/vendor/codeception/codeception/src/Codeception/SuiteManager.php(157): Codeception\PHPUnit\Runner->doEnhancedRun(Object(Codeception\Suite), Object(PHPUnit\Framework\TestResult), Array)

15 /opt/project/vendor/codeception/codeception/src/Codeception/Codecept.php(189): Codeception\SuiteManager->run(Object(Codeception\PHPUnit\Runner), Object(PHPUnit\Framework\TestResult), Array)

16 /opt/project/vendor/codeception/codeception/src/Codeception/Codecept.php(158): Codeception\Codecept->runSuite(Array, 'functional', NULL)

17 /opt/project/vendor/codeception/codeception/src/Codeception/Command/Run.php(466): Codeception\Codecept->run('functional')

18 /opt/project/vendor/codeception/codeception/src/Codeception/Command/Run.php(361): Codeception\Command\Run->runSuites(Array, Array)

19 /opt/project/vendor/symfony/console/Command/Command.php(252): Codeception\Command\Run->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

20 /opt/project/vendor/symfony/console/Application.php(946): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

21 /opt/project/vendor/symfony/console/Application.php(248): Symfony\Component\Console\Application->doRunCommand(Object(Codeception\Command\Run), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

22 /opt/project/vendor/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

23 /opt/project/vendor/codeception/codeception/src/Codeception/Application.php(108): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

24 /opt/.phpstorm_helpers/codeception.php(40): Codeception\Application->run()

25 {main}

An Error occurred while handling another error:
Error: Call to a member function has() on null in /opt/project/vendor/yiisoft/yii2/web/ErrorHandler.php:91
Stack trace:

0 /opt/project/vendor/yiisoft/yii2/base/ErrorHandler.php(111): yii\web\ErrorHandler->renderException(Object(Error))

1 [internal function]: yii\base\ErrorHandler->handleException(Object(Error))

2 {main}

Previous exception:
Error: Call to a member function getDb() on null in /opt/project/vendor/yiisoft/yii2/db/ActiveRecord.php:135
Stack trace:

0 /opt/project/vendor/yiisoft/yii2/db/ActiveRecord.php(382): yii\db\ActiveRecord::getDb()

1 /opt/project/vendor/yiisoft/yii2/db/ActiveRecord.php(418): yii\db\ActiveRecord::getTableSchema()

2 /opt/project/vendor/yiisoft/yii2/db/BaseActiveRecord.php(492): yii\db\ActiveRecord->attributes()

3 /opt/project/vendor/yiisoft/yii2/db/BaseActiveRecord.php(289): yii\db\BaseActiveRecord->hasAttribute('__mocked')

4 /opt/project/vendor/yiisoft/yii2/db/BaseActiveRecord.php(335): yii\db\BaseActiveRecord->get('mocked')

5 /opt/project/vendor/codeception/codeception/src/Codeception/Step.php(176): yii\db\BaseActiveRecord->isset('mocked')

6 /opt/project/vendor/codeception/codeception/src/Codeception/Step.php(164): Codeception\Step->getClassName(Object(common\models\User))

7 /opt/project/vendor/codeception/codeception/src/Codeception/Step.php(103): Codeception\Step->stringifyArgument(Object(common\models\User))

8 /opt/project/vendor/codeception/codeception/src/Codeception/Step.php(235): Codeception\Step->getArgumentsAsString(200)

9 /opt/.phpstorm_helpers/codeception_24_56.php(337): Codeception\Step->getHumanizedArguments()

10 /opt/project/vendor/phpunit/phpunit/src/Framework/TestResult.php(408): PhpStorm_Codeception_ReportPrinter->endTest(Object(Codeception\Test\Cest), 0.089478015899658)

11 /opt/project/vendor/codeception/codeception/src/Codeception/Test/Test.php(111): PHPUnit\Framework\TestResult->endTest(Object(Codeception\Test\Cest), 0.089478015899658)

12 /opt/project/vendor/phpunit/phpunit/src/Framework/TestSuite.php(755): Codeception\Test\Test->run(Object(PHPUnit\Framework\TestResult))

13 /opt/project/vendor/codeception/phpunit-wrapper/src/Runner.php(106): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))

14 /opt/project/vendor/codeception/codeception/src/Codeception/SuiteManager.php(157): Codeception\PHPUnit\Runner->doEnhancedRun(Object(Codeception\Suite), Object(PHPUnit\Framework\TestResult), Array)

15 /opt/project/vendor/codeception/codeception/src/Codeception/Codecept.php(189): Codeception\SuiteManager->run(Object(Codeception\PHPUnit\Runner), Object(PHPUnit\Framework\TestResult), Array)

16 /opt/project/vendor/codeception/codeception/src/Codeception/Codecept.php(158): Codeception\Codecept->runSuite(Array, 'functional', NULL)

17 /opt/project/vendor/codeception/codeception/src/Codeception/Command/Run.php(466): Codeception\Codecept->run('functional')

18 /opt/project/vendor/codeception/codeception/src/Codeception/Command/Run.php(361): Codeception\Command\Run->runSuites(Array, Array)

19 /opt/project/vendor/symfony/console/Command/Command.php(252): Codeception\Command\Run->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

20 /opt/project/vendor/symfony/console/Application.php(946): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

21 /opt/project/vendor/symfony/console/Application.php(248): Symfony\Component\Console\Application->doRunCommand(Object(Codeception\Command\Run), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

22 /opt/project/vendor/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

23 /opt/project/vendor/codeception/codeception/src/Codeception/Application.php(108): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

24 /opt/.phpstorm_helpers/codeception.php(40): Codeception\Application->run()

25 {main}

$_SERVER = [
'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
'HOSTNAME' => '98cc7ec2f196',
'JETBRAINS_REMOTE_RUN' => '1',
'IDE_SCRIPT_PREFIX' => '',
'IDE_CODECEPTION_EXE' => '/opt/project/vendor/codeception/codeception/codecept',
'DEBIAN_FRONTEND' => 'teletype',
'LANG' => 'en_US.UTF-8',
'LANGUAGE' => 'en_US.UTF-8',
'LC_ALL' => 'en_US.UTF-8',
'LC_CTYPE' => 'UTF-8',
'TERM' => 'xterm',
'HOME' => '/root',
'PHP_SELF' => '/opt/.phpstorm_helpers/codeception.php',
'SCRIPT_NAME' => 'api/web/index-test.php',
'SCRIPT_FILENAME' => 'index-test.php',
'PATH_TRANSLATED' => '/opt/.phpstorm_helpers/codeception.php',
'DOCUMENT_ROOT' => '',
'REQUEST_TIME_FLOAT' => 1523283055.505418,
'REQUEST_TIME' => 1523283055,
'argv' => [
'/opt/.phpstorm_helpers/codeception.php',
'run',
'--report',
'-o',
'reporters: report: PhpStorm_Codeception_ReportPrinter',
'--no-ansi',
'--no-interaction',
'--debug',
'-c',
'/opt/project/codeception.yml',
'functional',
],
'argc' => 11,
'SHELL_VERBOSITY' => 0,
'SERVER_NAME' => null,
'SERVER_PORT' => '80',
'HTTPS' => false,
]
PHP Fatal error: Uncaught RuntimeException: Command Did Not Finish Properly in /opt/project/vendor/codeception/codeception/src/Codeception/Subscriber/ErrorHandler.php:101
Stack trace:

0 [internal function]: Codeception\Subscriber\ErrorHandler->shutdownHandler()

1 {main}

thrown in /opt/project/vendor/codeception/codeception/src/Codeception/Subscriber/ErrorHandler.php on line 101
PHP Stack trace:
PHP 1. yii\web\ErrorHandler->handleException() /opt/project/vendor/yiisoft/yii2/base/ErrorHandler.php:0
PHP 2. yii\web\ErrorHandler->handleFallbackExceptionMessage() /opt/project/vendor/yiisoft/yii2/base/ErrorHandler.php:124

Process finished with exit code 1

PHP STORM *********************************************************************

Posts: 1

Participants: 1

Read full topic

A weird error when testing rest api with symfony

$
0
0

@tuancode wrote:

Hi, I got a weird error. The Codeception PUT request wasn't prevented by the validation of email unique which was work fine in dev or prod environment.

Testing api
PutUserCest: Put user by invalid email
Signature: PutUserCest:putUserByInvalidEmail
Test: tests/api/User/PutUserCest.php:putUserByInvalidEmail
Scenario --
  [Database] Transaction started
 I login
   I am bearer authenticated "eyJhbGciOiJSUzI1NiJ9.eyJ1c2VybmFtZSI6ImFkbWluQGV4YW1wbGUubmV0IiwiZXhwIjoxNTIzMzMyNzY1LCJpYXQiOjE1MjMzMjkxNjV9.TlDhC5QmN5Y3iATi0kOk0prqzQkqTxWQETtPq1e1e6kHFdH0EHwyLl_JdmBlBVImCVCRJhzPrs3MRd2GJjFwJ8X6MwPajf..." I grab entity from repository "AppBundle\Entity\User",{"email":"admin@example.net"}
  SELECT s FROM AppBundle\Entity\User s WHERE s.email = :s_email
 ---Duplicate Email---
 I send put "/user/1.json",{"email":"admin@example.net","phone":"+8412000001","status":"A","enabled":true}
  [Request] PUT /api/v1/user/1.json {"email":"admin@example.net","phone":"+8412000001","status":"A","enabled":true}
  [Request Headers] {"Authorization":"Bearer eyJhbGciOiJSUzI1NiJ9.eyJ1c2VybmFtZSI6ImFkbWluQGV4YW1wbGUubmV0IiwiZXhwIjoxNTIzMzMyNzY1LCJpYXQiOjE1MjMzMjkxNjV9.TlDhC5QmN5Y3iATi0kOk0prqzQkqTxWQETtPq1e1e6kHFdH0EHwyLl_JdmBlBVImCVCRJhzPrs3MRd2GJjF
wJ8X6MwPajfJTEjgQtRTgdT92r3MP0N1FU_4tL6ZGBWPiL5yEVzXYr3fg9C_Q0Bhew711PLF-YPOODrAz8eOzTv8CzLQBfT-iUD-rdh9BCNOxTgPpgQEt8oZcPoM-PrDCTpmTjzYLr86A3A0TTpJ3ID2fa4lk3q9jA1NzSxUFYBnUrtAFPFeBskjBzsosLavW28ssyoJgcvtdlV04huZG-jvjI9lb_dg9A_oFuxokq9rmp
FhEGWbBXBOTYA1Y1JhVz56Jt-pLFfbk6-bZ-10ibli3rAiMkUE1vRQ4Goe6TvBzbnG3bU6KODGeejjE-wKhzHlyVQ_Z1ho5TFq3jvHF69dn10B6bjEKW7Lc53a9zLnJXnDqfVizbCFYvW-saNYev51oU92SpQ_h29-7l1pDCF6ft_m0zzExU12vMbPFK5AKCxmchrgtwxeR2NdmO1gN_JcPVcUoRKV5tybnhmvimLiAbQZ
RzJSIvH5LJLevHf7QiYZuXurv4mt0drIWU-uithG3bV5jTaybWyp5fZcRNmFFGaPxkMnYnhO4y8_bSxhFF_Rkqx7uUWYpEoQv8Lyr_sAJa_l61QNjjm6yu0Z6Sp4"}
PutUserCest.php on line 100:
AppBundle\Entity\User {#732
  #id: 1
  -status: "A"
  -phone: "+841208667413"
  -createdDate: DateTime @1523256430 {#805
    date: 2018-04-09 13:47:10.0 Asia/Ho_Chi_Minh (+07:00)
  }
  -updatedDate: DateTime @1523256430 {#742
    date: 2018-04-09 13:47:10.0 Asia/Ho_Chi_Minh (+07:00)
  }
  #username: "admin@example.net"
  #usernameCanonical: "admin@example.net"
  #email: "admin@example.net"
  #emailCanonical: "admin@example.net"
  #enabled: true
  #salt: null
  #password: "$2y$13$BMC94Hz0JgiGV7I9MtwlLuHlt5qNVZvH5vk.bsnr1iPsgNgCsgTEy"
  #plainPassword: null
  #lastLogin: null
  #confirmationToken: null
  #passwordRequestedAt: null
  #groups: null
  #roles: array:1 [
    0 => "ROLE_ADMIN"
  ]
}
  [Page] /api/v1/user/1.json
  [Response] 200
  [Request Cookies] []
  [Response Headers] {"cache-control":["no-cache, private"],"date":["Tue, 10 Apr 2018 02:59:25 GMT"],"content-type":["application/json"],"x-debug-token":["198a5c"],"set-cookie":["MOCKSESSID=deleted; expires=Mon, 10-Apr-2017 02:59:24 GMT; 
max-age=-31536001; path=/"]}
  [User] admin@example.net [ROLE_ADMIN,ROLE_USER]
  [Response] {"id":1,"email":"admin@example.net","phone":"+8412000001","status":"A","enabled":true,"created_date":"2018-04-09T13:47:10+07:00","updated_date":"2018-04-10T09:59:25+07:00"}
 I see response code is 400
 FAIL 

  [Database] Transaction cancelled; all changes reverted.

Posts: 1

Participants: 1

Read full topic

Error initialising WpBrowser

$
0
0

@csaborio wrote:

Thanks for reading this, I am stumped and the error I am receiving is not hinting me very well what I am doing wrong. I am trying to set Wordpress with Conception using these instructions: https://codeception.com/for/wordpress#Install

Running in a local environment, the first few questions seem to be ok:

Bootstrapping Codeception for WordPress 

File codeception.yml created       <- global configuration
? How would you like the acceptance suite to be called? (acceptance) 
? How would you like the functional suite to be called? (functional) 
? How would you like the WordPress unit and integration suite to be called? (wpunit) 
---

WPLoader and WordPress modules need to access the WordPress files to work
? Where is WordPress installed? (/var/www/wp) /Users/csaborio/Library/Mobile Documents/com~apple~CloudDocs/ScorpioTek/Sites/test.spark.vinnies.org.au
? What is the path, relative to WordPress root folder, of the admin area? (/wp-admin) 
The WPDb module needs the database details to access the database used by WordPress
? What's the name of the database used by the WordPress installation? (wp) test.spark.vinnies.org.au
? What's the host of the database used by the WordPress installation? (localhost) 
? What's the user of the database used by the WordPress installation? (root) 
? What's the password of the database used by the WordPress installation? root
? What's the table prefix of the database used by the WordPress installation? (wp_) 
WPLoader will reinstall a fresh WordPress installation before the tests; as such it needs the details you would typically provide when installing WordPress from scratch

It then goes on to the configuration of WPLoader and this is where it fails:

> WPLoader should be configured to run on a dedicated database!

? What's the name of the database WPLoader should use? (wpTests) 
? What's the host of the database WPLoader should use? (localhost) 
? What's the user of the database WPLoader should use? (root) 
? What's the password of the database WPLoader should use? root
? What's the table prefix of the database WPLoader should use? (wp_) 
? What's the URL the WordPress installation? (http://wp.localhost) http://localhost:8888/
? What's the email of the WordPress site administrator? (admin@localhost) [hidden]
? What's the title of the WordPress site? (Test) 
? What is the login of the administrator user? (admin) 
? What is the password of the administrator user? (password) 
? Are you testing a plugin or a theme? (plugin) 
? What is the folder/plugin.php name of the plugin? (my-plugin/my-plugin.php) spark-gf-to-volunteer/spark-gf-to-volunteer.php
? Does your plugin or theme needs additional plugins to be activated to work? (no) 
> Unit helper has been created in tests/_support/Helper
> UnitTester actor has been created in tests/_support
> Actions have been loaded
tests/unit created                 <- unit tests
tests/unit.suite.yml written       <- unit tests suite configuration
> Wpunit helper has been created in tests/_support/Helper
> WpunitTester actor has been created in tests/_support
> Actions have been loaded
tests/wpunit created               <- WordPress unit and integration tests
tests/wpunit.suite.yml written     <- WordPress unit and integration tests suite configuration
> Functional helper has been created in tests/_support/Helper

The error given us then:

Something is not ok in the modules configurations: check your answers and try the initialization again.
> All files and folders created by the initialization attempt have been removed.

The database I specified does exists, and the username/password for the database are correct.

I am clear on all questions, but am baffled a bit about this one:

What's the URL the WordPress installation?

It wants the URL of the test Wordpress Installation that I created to test the plugin or it wants the address of where the test Wordpress install that it is creating will live?

mySQL is running on port 8889, I have tried specifying database server as localhost, 127.0.0.1, localhost:8889, 127.0.0.1:8889 and I still face issues.

Is there a way of knowing what failed?

Any feedback is greatly appreciated, I'm completely stumped and this is the setup process...oh lordy! xD

Posts: 2

Participants: 1

Read full topic

Beginner Codeception Unit Test Help

$
0
0

@rjcoleman wrote:

I'm running through the documentation for setting up and using codeception for the first time on a preexisting application. The app I've inherited has a user class located at /Classes/User.php. My test just wants to test that the $user->username is set correctly but I can't figure out how to use my class in the test scripts. Is this possible? How do I set up codeception's unit testing to use this applications classes?

Or if this question screams: they haven't rtfm, which i suspect it might, please, direct me to the manual on how to use codeception with an existing application that isn't using a framework. I'm very very happy to have documentation or tutorials or videos, I just can't find any that cover this situation!

Thank you very much in advance!

Posts: 3

Participants: 2

Read full topic


Symfony4 separate testing database

$
0
0

@tuancode wrote:

Hi, I use Codeception with Symfony4 to write api testing and I cannot separate testing database by overriding the value of the DATABASE_URL env var in the phpunit.xml.dist (follow symfony document) to use a different database for my test as bellow:

<?xml version="1.0" charset="utf-8" ?>
<phpunit>
    <php>
        <!-- the value is the Doctrine connection string in DSN format -->
        <env name="DATABASE_URL" value="mysql://USERNAME:PASSWORD@127.0.0.1/DB_NAME" />
    </php>
    <!-- ... -->
</phpunit>

This is my api.suite.yml

actor: ApiTester
modules:
    enabled:
        - Symfony:
            app_path: 'src'
            environment: 'test'
        - REST:
            url: /
            depends: Symfony
        - Doctrine2:
            depends: Symfony
        - \Helper\Api

Does anyone have a solution?

Posts: 2

Participants: 2

Read full topic

grabFromDatabase() not printing result in console

$
0
0

@Swarndeep_singh wrote:

Hi I am trying to print my result using : grabFromDatabase('tableNames','column1Name', array('column2Value' => '2')); My result passes but does not show the actual result value in console. Ane help much appreciated. Thanks

class_name: AcceptanceTester
modules:
enabled:
- Asserts

    - Db:
        dsn: "sqlsrv:Server=localhost,1433;Database=Drugs"
        user: 'sa'
        password: 'Creative'
        dump: 'tests/_data/dump.sql'
        populate: true # run populator before all tests
        cleanup: true # run populator before each test
        populator: 'mssql -u $user -h $host $dbname < $dump'
    - \Helper\Acceptance

Posts: 1

Participants: 1

Read full topic

Using CLI or filesystem module

$
0
0

@Alexandru_Mainea wrote:

Hello!

I got one question and i couldn't find any answer yet.
I want to use CLI or filesystem module from Codeception, but the automated tests are in a different repo, running from a different machine, meaning that running a command like runShellCommand will not do anything.
In the documentation it doesn't write anything about opening a ssh connection in a CEST. So, I am asking you how did you created the ssh connection. Is there an embedded module for this?
I found edno/codeception-secureshell but i cannot use it due to php.net/ssh2 dependency.
I found http://phpseclib.sourceforge.net/ from FTP/SFTP documentation and https://robo.li/tasks/Remote/ which has SSH.
I want to know which method did you use, and how should i approach the problem.

The necessity is: I got a system where i want to write tests for it, but the system contains a lot of crons that do all the work. My need is to run this crons (which are PHP commands) manually and control them when to start and stop, in order to see the effect on the DB.

Any advice ?

Thanks for help,
Alex

Posts: 1

Participants: 1

Read full topic

How to generate the URL for tests

$
0
0

@Escapio1 wrote:

Hi,

I have one question. I am using Codeception to test different Branches. Its quit anoying to change the URL in the acceptance suite every time I change the Branch. Is there any function or script that generates the URL automatically, so that I only have to type in the Branch number?

For example:
www.001-Test.de
www.023-Test.de

Thanking all of you in advance

Posts: 2

Participants: 2

Read full topic

Running PhpBrowser and WebDriver together

$
0
0

@davert wrote:

Usually, you wouldn't do it but what if there are some actions that you would like to run in a faster PhpBrowser environment without a real browser? For instance, create a user via admin area (with PhpBrowser) and then login this user via WebDriver.

You can't configure Codeception to run both modules but you can create your own helper that wraps PhpBrowser.

codecept g:helper PhpBrowserAPI

then edit a file:

class PhpBrowserAPI extends \Codeception\Module
{
    protected $requiredFields = ['url', 'user', 'password'];

    /**
     * @var Client
     */
    protected $client;

    /**
     * @var PhpBrowser
     */
    private $phpBrowser;

    public function _initialize()
    {
        // we initialize PhpBrowser here
        $this->phpBrowser = new PhpBrowser($this->moduleContainer, [
           'url' => $this->config['url'],
           'auth' => [$this->config['user'], $this->config['password']]
        ]);
        $this->phpBrowser->_initialize();
    }

Then we implement a method to perform actions using PhpBrowser:

    public function registerUserInAdmin($name, $password)
    {
        $this->phpBrowser->amOnPage('/admin/users/new');
        $this->phpBrowser->submitForm([
            'name' => $name,
            'password' => $password
        ]);
    }

Then you can use this user in a test:

// inside PhpBrowser
$I->registerUserInAdmin('davert', '123456');

// inside WebDriver
$->amOnPage('/login');
$I->fillField('username', 'davert');
$I->fillFIeld('password', '123456');
$I->click('Login');
$I->see('Welcome');

To make this work enable WebDriver and PhpBrowserApi enable them in acceptance.suite.yml config:

modules:
    enabled:
        - WebDriver:
            url: "https://site.com"
            browser: chrome
        - \Helper\PhpBrowserAPI
            url: "https://site.com"

Sharing the Same Session

What if you need to have PhpBrowserAPI and WebDriver to share the same session? You just need to share their cookied.

Let PhpBrowser access a page before WebDriver, get cookies, and store them to WebDriver. Just add to PhpBrowserAPI class:

    public function _before(\Codeception\TestInterface $test)
    {
        // open page in PhpBrowser
        $this->phpBrowser->amOnPage('/');
        /** @var $webdriver WebDriver  **/
        $webdriver = $this->getModule('WebDriver');
        // open page in WebDriver
        $webdriver->amOnPage('/');
        /** @var $cookieJar CookieJar  **/
        $cookieJar = $this->phpBrowser->client->getCookieJar();
        /** @var $cookie SetCookie  **/
        foreach ($cookieJar->all() as $cookie) {
        // copy cookies from PhpBrowser to WebDriver
            $webdriver->setCookie($cookie->getName(), $cookie->getValue());
        }
    }

Posts: 1

Participants: 1

Read full topic

Viewing all 762 articles
Browse latest View live