Skip to content

Commit e829687

Browse files
authored
MQE-1089: Allow usage of $ JavaScript variables in executeJs
- Added conditional in testGenerator to escape javascript variables only in executeJS functions.
1 parent dd9f789 commit e829687

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
namespace Magento\AcceptanceTest\_default\Backend;
3+
4+
use Magento\FunctionalTestingFramework\AcceptanceTester;
5+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
6+
use Magento\FunctionalTestingFramework\DataGenerator\Persist\DataPersistenceHandler;
7+
use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
8+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\CredentialStore;
9+
use \Codeception\Util\Locator;
10+
use Yandex\Allure\Adapter\Annotation\Features;
11+
use Yandex\Allure\Adapter\Annotation\Stories;
12+
use Yandex\Allure\Adapter\Annotation\Title;
13+
use Yandex\Allure\Adapter\Annotation\Description;
14+
use Yandex\Allure\Adapter\Annotation\Parameter;
15+
use Yandex\Allure\Adapter\Annotation\Severity;
16+
use Yandex\Allure\Adapter\Model\SeverityLevel;
17+
use Yandex\Allure\Adapter\Annotation\TestCaseId;
18+
19+
/**
20+
*/
21+
class ExecuteJsEscapingTestCest
22+
{
23+
/**
24+
* @Features({"TestModule"})
25+
* @Parameter(name = "AcceptanceTester", value="$I")
26+
* @param AcceptanceTester $I
27+
* @return void
28+
* @throws \Exception
29+
*/
30+
public function ExecuteJsEscapingTest(AcceptanceTester $I)
31+
{
32+
$javaVariableEscape = $I->executeJS("return \$javascriptVariable");
33+
$mftfVariableNotEscaped = $I->executeJS("return {$doNotEscape}");
34+
}
35+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="../../../../../src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
11+
<test name="ExecuteJsEscapingTest">
12+
<executeJS function="return $javascriptVariable" stepKey="javaVariableEscape"/>
13+
<executeJS function="return {$doNotEscape}" stepKey="mftfVariableNotEscaped"/>
14+
</test>
15+
</tests>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace tests\verification\Tests;
7+
8+
use tests\util\MftfTestCase;
9+
10+
class ExecuteJsTest extends MftfTestCase
11+
{
12+
/**
13+
* Tests escaping of $javascriptVariable => \$javascriptVariable in the executeJs function
14+
*
15+
* @throws \Exception
16+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
17+
*/
18+
public function testExecuteJsTest()
19+
{
20+
$this->generateAndCompareTest('ExecuteJsEscapingTest');
21+
}
22+
}

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,10 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
618618
// Argument must be a closure function, not a string.
619619
$function = trim($function, '"');
620620
}
621+
// turn $javaVariable => \$javaVariable but not {$mftfVariable}
622+
if ($actionObject->getType() == "executeJS") {
623+
$function = preg_replace('/(?<!{)(\$[\w\d_]+)/', '\\\\$1', $function);
624+
}
621625
}
622626

623627
if (isset($customActionAttributes['html'])) {

0 commit comments

Comments
 (0)