Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeception. Output variable while scenario is running

Is it possible to log or output any user data while the scenario is running? I know that the php code is executed two times at each run, how can I see a variable's value during the second step?

like image 621
MrBinWin Avatar asked Jan 22 '14 14:01

MrBinWin


People also ask

What is Cest Codeception?

Cest is a common test format for Codeception, it is “Test” with the first C letter in it. It is scenario-driven format so all tests written in it are executed step by step. Unless you need direct access to application code inside a test, Cest format is recommended.

How do you skip tests in Codeception?

The codeception library is built on top of phpunit, so to skip test there is a function markTestSkipped . Every code after this function will not be executed.

What is Codeception selenium?

Codeception helps you to organize tests into 3 categories: acceptance, functional, and unit tests. To create all tests and support directories, you will need to run the bootstrap command. vendor/bin/codecept bootstrap. Selenium tests are acceptance tests.


2 Answers

codecept_debug($var);

And run codecept in "debug mode" to see it:

./vendor/bin/codecept run -d

If you want to make sure that your var is shown not only in debug mode:

$t = ob_get_clean(); // get current output buffer and stopping output buffering
var_dump($var); // show what we need
ob_start(); // start output buffering
echo($t); // restore output buffer

You can move this code out to external library.

like image 59
luchaninov Avatar answered Oct 21 '22 13:10

luchaninov


<?php
    use Codeception\Extension\Logger;

    if ($scenario->running()) {
        Logger::log((string)$var);
    }
?>

please, do see docs

and regarding seeing variable value, the preferable way is typecasting to string if it's a scalar data, accessing array index/key if it's an array, etc. but there is undocumented method $var->__value() which you can use for debugging, but should not rely on it in tests

like image 3
tiger.seo Avatar answered Oct 21 '22 12:10

tiger.seo