Skip to content

Commit 5ee0e59

Browse files
author
Neubert, Sebastian
committed
Merge branch 'master' of github.com:DigitalProducts/codeception-module-visualception
2 parents f709930 + afab048 commit 5ee0e59

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

module/VisualCeption.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,14 @@ public function __construct ($config)
4141
* Event hook before a test starts
4242
*
4343
* @param \Codeception\TestCase $test
44+
* @throws \Exception
4445
*/
4546
public function _before (\Codeception\TestCase $test)
4647
{
48+
if ( !$this->hasModule("WebDriver")) {
49+
throw new \Exception("VisualCeption uses the WebDriver. Please be sure that this module is activated.");
50+
}
51+
4752
$this->webDriverModule = $this->getModule("WebDriver");
4853
$this->webDriver = $this->webDriverModule->webDriver;
4954

@@ -215,6 +220,13 @@ private function getCoordinates ($elementId)
215220
$this->webDriver->executeScript('jQuery.noConflict();');
216221

217222
$imageCoords = array ();
223+
224+
$elementExists = (bool) $this->webDriver->executeScript('return jQuery( "' . $elementId . '" ).length > 0;');
225+
226+
if( !$elementExists) {
227+
throw new \Exception("The element you want to examine ('".$elementId."') was not found.");
228+
}
229+
218230
$imageCoords['offset_x'] = (string) $this->webDriver->executeScript('return jQuery( "' . $elementId . '" ).offset().left;');
219231
$imageCoords['offset_y'] = (string) $this->webDriver->executeScript('return jQuery( "' . $elementId . '" ).offset().top;');
220232
$imageCoords['width'] = (string) $this->webDriver->executeScript('return jQuery( "' . $elementId . '" ).width();');

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ VisualCeption is really easy to use. There are only two method that will be adde
6363
```php
6464
$I->seeVisualChanges( "uniqueIdentifier1", "elementId1" );
6565
$I->dontSeeVisualChanges( "uniqueIdentifier2", "elementId2" );
66+
6667
$I->dontSeeVisualChanges( "uniqueIdentifier3", "elementId3" [, array("excludeElement1", "excludeElement2")] );
6768
```
6869

0 commit comments

Comments
 (0)