From a987fc88e23f74f299d7bf2711b6412da8474ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albrecht=20K=C3=B6hnlein?= Date: Mon, 25 Apr 2022 10:31:59 +0200 Subject: [PATCH 1/3] Escape double quotes to not break JavaScript commands (#71) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Escape double quotes to not break JavaScript commands * Add test for usage with different selectors, including single and double quotes Co-authored-by: Albrecht Köhnlein --- module/VisualCeption.php | 3 +++ test/integration/html/multipleAttributes.html | 18 +++++++++++++++ ...orMultipleSelectors.multipleAttributes.png | Bin 0 -> 2801 bytes .../acceptance/MultipleAttributesCest.php | 21 ++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 test/integration/html/multipleAttributes.html create mode 100644 test/integration/tests/_data/VisualCeption/MultipleAttributesCest.seeSameDivForMultipleSelectors.multipleAttributes.png create mode 100755 test/integration/tests/acceptance/MultipleAttributesCest.php diff --git a/module/VisualCeption.php b/module/VisualCeption.php index 37ab601..56909cd 100755 --- a/module/VisualCeption.php +++ b/module/VisualCeption.php @@ -325,6 +325,9 @@ private function getCoordinates($elementId) { if (is_null($elementId)) { $elementId = 'body'; + } else { + // escape double quotes to not break JavaScript commands + $elementId = str_replace('"', '\\"', $elementId); } $elementExists = (bool)$this->webDriver->executeScript('return document.querySelectorAll( "' . $elementId . '" ).length > 0;'); diff --git a/test/integration/html/multipleAttributes.html b/test/integration/html/multipleAttributes.html new file mode 100644 index 0000000..7a8fd96 --- /dev/null +++ b/test/integration/html/multipleAttributes.html @@ -0,0 +1,18 @@ + + + + + Multiple Attributes + + + +Testing a div with multiple attribute selectors +
My div with multiple attributes
+ + diff --git a/test/integration/tests/_data/VisualCeption/MultipleAttributesCest.seeSameDivForMultipleSelectors.multipleAttributes.png b/test/integration/tests/_data/VisualCeption/MultipleAttributesCest.seeSameDivForMultipleSelectors.multipleAttributes.png new file mode 100644 index 0000000000000000000000000000000000000000..7235f0f45186496cadf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w_!Lq438yK*KGsW0vDNzV6Vu*SYX)Hg+wfXktb`Z-@$R7w)wZ*fGge~G#cbad zDxGx{6T8Km5|TE*p><6UKooCdxI5vQ;6PsV75q*)DcX~+6#&{NWXD})BiSr)e2)DRm5v}#~ zt%lu7H)>P9&EzYI{zjQ67Ict@8O`&idyKpb}a1`7#6h$-uDhq{5$tp-ep;mIr ta5*SkPC-Ie7A`BBq`I{7UqC>Rmk&DTe*^UHLFj)6X`o}G-Ezk*~&b literal 0 HcmV?d00001 diff --git a/test/integration/tests/acceptance/MultipleAttributesCest.php b/test/integration/tests/acceptance/MultipleAttributesCest.php new file mode 100755 index 0000000..0a0a61b --- /dev/null +++ b/test/integration/tests/acceptance/MultipleAttributesCest.php @@ -0,0 +1,21 @@ +amOnPage("/multipleAttributes.html"); + // class selector + $I->dontSeeVisualChanges("multipleAttributes", ".block"); + // attribute selector without value + $I->dontSeeVisualChanges("multipleAttributes", "[data-element]"); + // attribute selector with single quotes + $I->dontSeeVisualChanges("multipleAttributes", "[data-element='myElement']"); + // attribute selector with double quotes + $I->dontSeeVisualChanges("multipleAttributes", '[data-element="myElement"]'); + } +} From e883b6dfc5dea3897742ceea36479ba69dc41687 Mon Sep 17 00:00:00 2001 From: al-zakharov <104079778+al-zakharov@users.noreply.github.com> Date: Thu, 28 Apr 2022 14:36:16 +0300 Subject: [PATCH 2/3] Added support for multi session testing (#73) * Added support for multi session testing * Added MultiSessionCest * Fix MultiSessionCest --- module/VisualCeption.php | 39 +++++++++++++++++- test/integration/html/multiSession.html | 10 +++++ .../integration/html/multiSessionChanged.html | 10 +++++ ...tSeeVisualChangesInMultiSessions.block.png | Bin 0 -> 1658 bytes ...sInMultiSessions.blockInAnotherSession.png | Bin 0 -> 2506 bytes .../tests/acceptance/MultiSessionCest.php | 23 +++++++++++ 6 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 test/integration/html/multiSession.html create mode 100644 test/integration/html/multiSessionChanged.html create mode 100644 test/integration/tests/_data/VisualCeption/MultiSessionCest.dontSeeVisualChangesInMultiSessions.block.png create mode 100644 test/integration/tests/_data/VisualCeption/MultiSessionCest.dontSeeVisualChangesInMultiSessions.blockInAnotherSession.png create mode 100644 test/integration/tests/acceptance/MultiSessionCest.php diff --git a/module/VisualCeption.php b/module/VisualCeption.php index 56909cd..0c7e2f4 100755 --- a/module/VisualCeption.php +++ b/module/VisualCeption.php @@ -1,6 +1,7 @@ 0, @@ -568,4 +569,40 @@ protected function _initVisualReport() } $this->debug( "VisualCeptionReporter: templateFile = " . $this->templateFile ); } + + /** + * Get a new loaded module + */ + public function _initializeSession() + { + $browserModule = $this->getBrowserModule(); + + $this->webDriverModule = $browserModule; + $this->webDriver = $this->webDriverModule->webDriver; + } + + /** + * Loads current RemoteWebDriver instance as a session + * + * @param $session + */ + public function _loadSession($session) + { + $this->webDriver = $session; + } + + /** + * Returns current WebDriver session for saving + * + * @return RemoteWebDriver + */ + public function _backupSession() + { + return $this->webDriver; + } + + public function _closeSession($session = null) + { + // this method will never be needed + } } \ No newline at end of file diff --git a/test/integration/html/multiSession.html b/test/integration/html/multiSession.html new file mode 100644 index 0000000..41109a8 --- /dev/null +++ b/test/integration/html/multiSession.html @@ -0,0 +1,10 @@ + + + + + Multi Session + + +
Text in the first session.
+ + \ No newline at end of file diff --git a/test/integration/html/multiSessionChanged.html b/test/integration/html/multiSessionChanged.html new file mode 100644 index 0000000..0e484ca --- /dev/null +++ b/test/integration/html/multiSessionChanged.html @@ -0,0 +1,10 @@ + + + + + Multi Session + + +
And this is another text from another session.
+ + \ No newline at end of file diff --git a/test/integration/tests/_data/VisualCeption/MultiSessionCest.dontSeeVisualChangesInMultiSessions.block.png b/test/integration/tests/_data/VisualCeption/MultiSessionCest.dontSeeVisualChangesInMultiSessions.block.png new file mode 100644 index 0000000000000000000000000000000000000000..52ed8499e560072559d97d1e0ada0be9e902fe86 GIT binary patch literal 1658 zcmZ`(dpOgJ8~+lUYjs*gS5Amy%QUs@Ooc7C7;>4}GBy*TE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zc$BOOS>96G$HI-g4Lfk z&MtJ2T?PN3C&;{TS-SjO*zz^4uB_Ew`SNX{3cr?*s2UgYx8G)a7-4=pf-<|I1WD{` zXH^XMup@S3&rfP~&XotS{m<*ZzmTVWl-V*&gpVnk%;vA^#5F`*IY#WS@p!nK4qcB9 z+bn+X@I9X~&_#3&dXlMUad<&LNt8<%IV0aHiX4ZXnQ63b&(rd6_7u|tP0l__9-$Mh zZmAq%=-tIXcAp#Y%J2Ae-SUZQ-lZ|veWm!a+(w(ajG%W4i@Ljc+wv6=odZ0k|Wc8!4_$aDxls}3R=`Sn53HXT* literal 0 HcmV?d00001 diff --git a/test/integration/tests/_data/VisualCeption/MultiSessionCest.dontSeeVisualChangesInMultiSessions.blockInAnotherSession.png b/test/integration/tests/_data/VisualCeption/MultiSessionCest.dontSeeVisualChangesInMultiSessions.blockInAnotherSession.png new file mode 100644 index 0000000000000000000000000000000000000000..41f5752e4595c17f39edab021cf5a4e76a8cf261 GIT binary patch literal 2506 zcmZ`*XH=7k68%7>8mg24%F-lDGlU{w08wh_hy)O%28j?_XbIAhDnU?s2k8kIDbi6u zRwO|Y1PMi>OE2yMBAv~i^WKm50>bV0AmL%0C4jE3nrkTNSGnA2Ah~0ur8hzV^tQM zxZd8&ka#@YEJ7KhJZ3t8O+OxF6g3WJHt zaj9Lk%gLO!uefT9?fwA$BGXnU97!Pt@*8g}K0ESMJGO?3y$p;cq#~Gvc!H(ftS91_ zh1hsNEd7$MY%j%wwiY)#YQgy{$I-(P?=|1=Mwe{sENPd=Fmpi4Vwgi&xN8N&JP88W ziMo^WIbYtctlW$6^;@OkmM_I=*{bUZcq?D$^yXNxy)I;c1#%TGfvZ%p3Qc?8>Z6A> zYB=f?kitxl_%|tv9}RAR|44E`a~pVRvKc9z>@zS#Su zE$CN^)p-{OHzQ8RRnqg#Ll9QB$JZG%t^NuvhY<`*G$08dkA5vl06mv46OgOKojD&; zXfcXj;5k9ZY$y_^tDBbYOlLUr7Gpqv{}Jtt47F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(ytrzVWa}sx;Bl^|^znc8_OOhnE(A zw@;ed!J0>Udx&9KJTlVH?fFxYpXp%I@o2Q-iwVev$=0Ff+6E7{y@uF)Q(>V$ybRI0 z*!~G7+IS8&v#(?}8}aMs!h+NP7%={xXfNFVH|&o)e`Oc| N69WtV#v872{{Z(Gqfh_< literal 0 HcmV?d00001 diff --git a/test/integration/tests/acceptance/MultiSessionCest.php b/test/integration/tests/acceptance/MultiSessionCest.php new file mode 100644 index 0000000..ca61b45 --- /dev/null +++ b/test/integration/tests/acceptance/MultiSessionCest.php @@ -0,0 +1,23 @@ +amOnPage("/multiSession.html"); + $I->dontSeeVisualChanges("block", ".block"); + + $friend = $I->haveFriend('friend'); + $friend->does(function (WebGuy $I) { + $I->amOnPage("/multiSessionChanged.html"); + $I->dontSeeVisualChanges("blockInAnotherSession", ".block"); + }); + + $I->amOnPage("/multiSession.html"); + $I->dontSeeVisualChanges("block", ".block"); + } +} From 92ca816010b0a59ecae4904ee1d195fadb117af1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Bure=C5=A1?= Date: Thu, 19 May 2022 07:57:13 +0200 Subject: [PATCH 3/3] New version 1.0.4 --- CHANGELOG.md | 4 ++++ composer.json | 1 + 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3745542..7b05875 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.0.4 +* Added support for multi session testing - #73 +* Fixed double quotes to not break JavaScript commands - #71 + # 1.0.3 * Fix incorrectly cropped full page screenshots * Remove test dependency from www.thewebhatesme.com to local http server diff --git a/composer.json b/composer.json index 12a8a89..c3f7039 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "name": "codeception/visualception", "description": "Visual regression tests for Codeception", + "version": "1.0.4", "homepage": "https://github.com/Codeception/VisualCeption", "license": "Apache-2.0", "require": {