Skip to content

Commit a987fc8

Browse files
Escape double quotes to not break JavaScript commands (#71)
* 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 <albrecht.koehnlein@verdure.de>
1 parent b342e9f commit a987fc8

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

module/VisualCeption.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ private function getCoordinates($elementId)
325325
{
326326
if (is_null($elementId)) {
327327
$elementId = 'body';
328+
} else {
329+
// escape double quotes to not break JavaScript commands
330+
$elementId = str_replace('"', '\\"', $elementId);
328331
}
329332

330333
$elementExists = (bool)$this->webDriver->executeScript('return document.querySelectorAll( "' . $elementId . '" ).length > 0;');
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Multiple Attributes</title>
6+
<style>
7+
.block {
8+
height: 400px;
9+
width: 400px;
10+
background-color: aquamarine;
11+
}
12+
</style>
13+
</head>
14+
<body>
15+
Testing a div with multiple attribute selectors
16+
<div class="block" data-element="myElement">My div with multiple attributes</div>
17+
</body>
18+
</html>
2.74 KB
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
class MultipleAttributesCest
4+
{
5+
6+
/**
7+
* Comparing the same div with different attribute selectors
8+
*/
9+
public function seeSameDivForMultipleSelectors(WebGuy $I, $scenario)
10+
{
11+
$I->amOnPage("/multipleAttributes.html");
12+
// class selector
13+
$I->dontSeeVisualChanges("multipleAttributes", ".block");
14+
// attribute selector without value
15+
$I->dontSeeVisualChanges("multipleAttributes", "[data-element]");
16+
// attribute selector with single quotes
17+
$I->dontSeeVisualChanges("multipleAttributes", "[data-element='myElement']");
18+
// attribute selector with double quotes
19+
$I->dontSeeVisualChanges("multipleAttributes", '[data-element="myElement"]');
20+
}
21+
}

0 commit comments

Comments
 (0)