9 use Codeception\Event\StepEvent;
10 use Codeception\Event\TestEvent;
12 use Facebook\WebDriver\Exception\UnexpectedAlertOpenException;
14 use Facebook\WebDriver\Exception\TimeOutException;
30 private $ignoredActions = [
53 private $readinessMetrics;
72 parent::_initialize();
84 parent::beforeTest($e);
85 if (isset($this->config[
'resetFailureThreshold'])) {
86 $failThreshold = intval($this->config[
'resetFailureThreshold']);
91 $this->testName = $e->getTest()->getMetadata()->getName();
93 $this->
getDriver()->_setConfig([
'skipReadiness' =>
false]);
96 foreach ($this->config[
'readinessMetrics'] as $metricClass) {
97 $metrics[] =
new $metricClass($this, $failThreshold);
100 $this->readinessMetrics = $metrics;
114 $step = $e->getStep();
115 $manualSkip = $this->
getDriver()->_getConfig()[
'skipReadiness'];
116 if ($this->shouldSkipCheck($step, $manualSkip)) {
123 'Page URI changed; resetting readiness metric failure tracking',
125 'step' => $step->__toString(),
126 'newUri' => $this->
getUri()
130 foreach ($this->readinessMetrics as $metric) {
131 $metric->resetTracker();
136 if (isset($this->config[
'timeout'])) {
137 $timeout = intval($this->config[
'timeout']);
139 $timeout = $this->
getDriver()->_getConfig()[
'pageload_timeout'];
142 $metrics = $this->readinessMetrics;
145 $this->
getDriver()->webDriver->wait($timeout)->until(
146 function () use ($metrics) {
150 foreach ($metrics as $metric) {
152 if (!$metric->runCheck()) {
155 }
catch (UnexpectedAlertOpenException $exception) {
161 }
catch (TimeoutException $exception) {
165 foreach ($metrics as $metric) {
166 $metric->finalizeForStep($step);
177 return $this->testName;
188 private function shouldSkipCheck($step, $manualSkip)
190 if ($step instanceof Step\Comment || in_array($step->getAction(), $this->ignoredActions) || $manualSkip) {
204 private function logDebug(
$message, $context = [])
206 if ($this->verbose) {
208 'test' => $this->testName,
211 foreach ($this->readinessMetrics as $metric) {
212 $logContext[$metric->getName()] = $metric->getStoredValue();
213 $logContext[$metric->getName() .
'.failCount'] = $metric->getFailureCount();
215 $context = array_merge($logContext, $context);
beforeStep(\Codeception\Event\StepEvent $e)