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?
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.
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.
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.
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.
<?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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With