Skip to content

Instantly share code, notes, and snippets.

@lucatume
Created January 23, 2019 09:46
Show Gist options
  • Save lucatume/6e1cf9ff7c43677874501b0219fdb22b to your computer and use it in GitHub Desktop.
Save lucatume/6e1cf9ff7c43677874501b0219fdb22b to your computer and use it in GitHub Desktop.
Codeception Acceptance Helper modified to add a saveHtmlSnapshot method
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Acceptance extends \Codeception\Module {
public function saveHtmlSnapshot( string $snapshot = null ) {
$responseContent = $this->getModule( 'WPBrowser' )->_getResponseContent();
$snapshots = codecept_output_dir( 'snapshots' );
if ( ! is_dir( $snapshots ) && ! mkdir( $snapshots ) && ! is_dir( $snapshots ) ) {
throw new \RuntimeException( 'Could not create snapshots dir.' );
}
$snapshot = $snapshot ?? date( 'Y-m-d-H-i-s' );
file_put_contents( $snapshots . '/' . $snapshot . '.html', $responseContent );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment