From d5625d439a7a1f9583b25b53a94d5c881e989c05 Mon Sep 17 00:00:00 2001 From: Lukas Mestan Date: Mon, 21 Aug 2017 08:09:16 +0200 Subject: [PATCH] catch exception --- src/HighlightCeption.php | 41 ++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/HighlightCeption.php b/src/HighlightCeption.php index 312d5f9..b86532f 100644 --- a/src/HighlightCeption.php +++ b/src/HighlightCeption.php @@ -2,6 +2,7 @@ namespace Codeception\Module; +use Exception; use Codeception\Module; use Codeception\TestInterface; use Codeception\Exception\ConfigurationException; @@ -149,12 +150,16 @@ public function clickWithRightButton($cssOfXPath = null, $offsetX = null, $offse */ private function highlightText($text) { - $this->loadJQuery(); - $this->debug('[Highlight Text] ' . $text); - $this->webDriverModule->executeJs('jQuery(document).ready(function (){ - jQuery("body").highlight("' . $text . '"); - ' . sprintf('jQuery(".highlight").css(%s);', $this->cssStyle) . ' - });'); + try { + $this->loadJQuery(); + $this->debug('[Highlight Text] ' . $text); + $this->webDriverModule->executeJs('jQuery(document).ready(function (){ + jQuery("body").highlight("' . $text . '"); + ' . sprintf('jQuery(".highlight").css(%s);', $this->cssStyle) . ' + });'); + } catch(Exception $e) { + $this->debug(sprintf("[Highlight Exception] %s \n%s", $e->getMessage(), $e->getTraceAsString())); + } } /** @@ -164,17 +169,21 @@ private function highlightText($text) */ private function highlightElement($selector) { - $locator = $this->getSelector($selector); - if ($locator) { - $this->loadJQuery(); - if (Locator::isXPath($locator)) { - $this->loadJQueryXPath(); - $this->debug('[Highlight XPath] ' . Locator::humanReadableString($locator)); - $this->webDriverModule->executeJs(sprintf('jQuery(document).xpath("%s").css(%s);', addslashes($locator), $this->cssStyle)); - } else { - $this->debug('[Highlight Selector] ' . Locator::humanReadableString($locator)); - $this->webDriverModule->executeJs(sprintf('jQuery("%s").css(%s);', addslashes($locator), $this->cssStyle)); + try { + $locator = $this->getSelector($selector); + if ($locator) { + $this->loadJQuery(); + if (Locator::isXPath($locator)) { + $this->loadJQueryXPath(); + $this->debug('[Highlight XPath] ' . Locator::humanReadableString($locator)); + $this->webDriverModule->executeJs(sprintf('jQuery(document).xpath("%s").css(%s);', addslashes($locator), $this->cssStyle)); + } else { + $this->debug('[Highlight Selector] ' . Locator::humanReadableString($locator)); + $this->webDriverModule->executeJs(sprintf('jQuery("%s").css(%s);', addslashes($locator), $this->cssStyle)); + } } + } catch(Exception $e) { + $this->debug(sprintf("[Highlight Exception] %s \n%s", $e->getMessage(), $e->getTraceAsString())); } }