Skip to content

Commit be79cdb

Browse files
Try to use any module which inherits from WebDriver if WebDriver isn't found (#61)
1 parent 5ff7ad8 commit be79cdb

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

module/VisualCeption.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,37 @@ public function _failed(TestInterface $test, $fail)
129129
*/
130130
public function _before(TestInterface $test)
131131
{
132-
if (!$this->hasModule($this->config['module'])) {
132+
$browserModule = $this->getBrowserModule();
133+
134+
if ($browserModule === null) {
133135
throw new \Codeception\Exception\ConfigurationException("VisualCeption uses the WebDriver. Please ensure that this module is activated.");
134136
}
135137
if (!class_exists('Imagick')) {
136138
throw new \Codeception\Exception\ConfigurationException("VisualCeption requires ImageMagick PHP Extension but it was not installed");
137139
}
138140

139-
$this->webDriverModule = $this->getModule($this->config['module']);
141+
$this->webDriverModule = $browserModule;
140142
$this->webDriver = $this->webDriverModule->webDriver;
141143

142144
$this->test = $test;
143145
}
146+
147+
protected function getBrowserModule() {
148+
if ($this->hasModule($this->config['module'])) {
149+
return $this->getModule($this->config['module']);
150+
}
151+
152+
foreach($this->getModules() as $module) {
153+
if($module === $this) {
154+
continue;
155+
}
156+
if($module instanceof WebDriver) {
157+
return $module;
158+
}
159+
}
160+
161+
return null;
162+
}
144163

145164
/**
146165
* Get value of the private property $referenceImageDir

0 commit comments

Comments
 (0)