Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST module prints complete response ("body" report) #43

Open
manofearth opened this issue Jan 23, 2020 · 1 comment
Open

REST module prints complete response ("body" report) #43

manofearth opened this issue Jan 23, 2020 · 1 comment

Comments

@manofearth
Copy link

Method \Codeception\Module\REST::_failed should take into account shortDebugResponse setting before adding "body" report. Otherwise test output becomes quite unreadable (in case of long responses) even if shortDebugResponse was set to true. Or maybe better create new setting for shortening "body" report (something like shortResponseBody: true). Another solution could be making \Codeception\Test\Metadata::$reports field write-accessible, to allow shortening it in \Codeception\Module::_failed hook

@trenkmann
Copy link

Had the same Problem and found a quick solution so i thought i'd share it:

In the yml config for your suite(e.g. api.suite.yml):

        - \Helper\Api:
            shortResponseBody: 600

In the Helper Class for your suite(e.g. Api.php):

class Api extends \Codeception\Module
{

...

  public function _failed(\Codeception\TestInterface $test, $fail)
  {
    $body = $test->getMetadata()->getReports()['body'];
    $shortResponseBody = $this->_getConfig('shortResponseBody');

    if (isset($body) && isset($shortResponseBody) && strlen($body) > $shortResponseBody) {
      $start = substr($body, 0, $shortResponseBody / 2);
      $end = substr($body, -$shortResponseBody / 2);
      $newBody = $start . '\e ... \e' . $end;
      $test->getMetadata()->addReport('body', $newBody);
    }
  }

...

}

@Naktibalda Naktibalda transferred this issue from Codeception/Codeception Jan 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants