Skip to content

Commit 7b8d6e1

Browse files
Ashish.Kumar18Ashish.Kumar18
authored andcommitted
Verification test added
2 parents 4feed00 + a417a28 commit 7b8d6e1

File tree

9 files changed

+139
-22
lines changed

9 files changed

+139
-22
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"ext-intl": "*",
1616
"ext-json": "*",
1717
"ext-openssl": "*",
18+
"ext-iconv": "*",
1819
"allure-framework/allure-codeception": "^1.4",
1920
"aws/aws-sdk-php": "^3.132",
2021
"codeception/codeception": "^4.1",

composer.lock

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace tests\unit\Magento\FunctionalTestFramework\Module\Util;
9+
10+
use Magento\FunctionalTestingFramework\Module\Util\ModuleUtils;
11+
use PHPUnit\Framework\TestCase;
12+
13+
class ModuleUtilTest extends TestCase
14+
{
15+
/**
16+
* Test utf8SafeControlCharacterTrim()
17+
*
18+
* @param string $input
19+
* @param string $output
20+
* @param string $removed
21+
*
22+
* @return void
23+
* @dataProvider inDataProvider
24+
*/
25+
public function testUtf8SafeControlCharacterTrim(string $input, string $output, $removed): void
26+
{
27+
$util = new ModuleUtils();
28+
$this->assertStringContainsString($output, $util->utf8SafeControlCharacterTrim($input));
29+
$this->assertStringNotContainsString($removed, $util->utf8SafeControlCharacterTrim($input));
30+
}
31+
32+
/**
33+
* Data input.
34+
*
35+
* @return array
36+
*/
37+
public function inDataProvider(): array
38+
{
39+
$ctr1 = '‹';
40+
$ctr2 = 'Œ';
41+
$ctr3 = 'Œ ‹';
42+
return [
43+
["some text $ctr1", 'some text', $ctr1],
44+
["some text $ctr2", 'some text', $ctr2],
45+
["some text $ctr3", 'some text', $ctr3]
46+
];
47+
}
48+
}

dev/tests/verification/Resources/DataActionsTest.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class DataActionsTestCest
5858
$I->deleteEntity("createdInTest", "test"); // stepKey: deleteInTest
5959
$I->updateEntity("createdInBefore", "test", "entity",[]); // stepKey: updatedDataOutOfScope
6060
$I->deleteEntity("createdInBefore", "test"); // stepKey: deleteDataOutOfScope
61+
$I->rapidClick("#general_locale_timezone", "50"); // stepKey: rapidClickTest
6162
}
6263

6364
public function _passed(AcceptanceTester $I)

dev/tests/verification/TestModule/Test/DataActionsTest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
<deleteData createDataKey="createdInTest" stepKey="deleteInTest"/>
1919
<updateData entity="entity" createDataKey="createdInBefore" stepKey="updatedDataOutOfScope"/>
2020
<deleteData createDataKey="createdInBefore" stepKey="deleteDataOutOfScope"/>
21+
<rapidClick selector="{{LocaleOptionsSection.timezone}}" count="50" stepKey="rapidClickTest"/>
2122
</test>
22-
</tests>
23+
</tests>

src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Magento\FunctionalTestingFramework\DataTransport\Auth\Tfa\OTP;
2222
use Magento\FunctionalTestingFramework\DataTransport\Protocol\CurlInterface;
2323
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\CredentialStore;
24+
use Magento\FunctionalTestingFramework\Module\Util\ModuleUtils;
2425
use Magento\FunctionalTestingFramework\Util\Path\UrlFormatter;
2526
use Magento\FunctionalTestingFramework\Util\ConfigSanitizerUtil;
2627
use Yandex\Allure\Adapter\AllureException;
@@ -390,21 +391,6 @@ public function searchAndMultiSelectOption($select, array $options, $requireActi
390391
}
391392
}
392393

393-
/**
394-
* Simple rapid click as per given count number.
395-
*
396-
* @param string $selector
397-
* @param string $count
398-
* @return void
399-
* @throws \Exception
400-
*/
401-
public function rapidClick($selector, $count)
402-
{
403-
for ($i = 0; $i < $count; $i++) {
404-
$this->click($selector);
405-
}
406-
}
407-
408394
/**
409395
* Select multiple options from a drop down using a filter and text field to narrow results.
410396
*
@@ -599,7 +585,9 @@ public function magentoCLI($command, $timeout = null, $arguments = null)
599585
$response = $executor->read();
600586
$executor->close();
601587

602-
return $response;
588+
$util = new ModuleUtils();
589+
$response = trim($util->utf8SafeControlCharacterTrim($response));
590+
return $response != "" ? $response : "CLI did not return output.";
603591
}
604592

605593
/**
@@ -804,6 +792,21 @@ public function dragAndDrop($source, $target, $xOffset = null, $yOffset = null)
804792
$action->release($tnodes)->perform();
805793
}
806794
}
795+
796+
/**
797+
* Simple rapid click as per given count number.
798+
*
799+
* @param string $selector
800+
* @param string $count
801+
* @return void
802+
* @throws \Exception
803+
*/
804+
public function rapidClick($selector, $count)
805+
{
806+
for ($i = 0; $i < $count; $i++) {
807+
$this->click($selector);
808+
}
809+
}
807810

808811
/**
809812
* Function used to fill sensitive credentials with user data, data is decrypted immediately prior to fill to avoid
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\FunctionalTestingFramework\Module\Util;
8+
9+
class ModuleUtils
10+
{
11+
/**
12+
* Module util function that returns UTF-8 encoding string with control/invisible characters removed,
13+
* and it returns the original string when on error.
14+
*
15+
* @param string $input
16+
* @return string
17+
*/
18+
public function utf8SafeControlCharacterTrim(string $input): string
19+
{
20+
// Convert $input string to UTF-8 encoding
21+
$convInput = iconv("ISO-8859-1", "UTF-8//IGNORE", $input);
22+
if ($convInput !== false) {
23+
// Remove invisible control characters, unused code points and replacement character
24+
// so that they don't break xml test results for Allure
25+
$cleanInput = preg_replace('/[^\PC\s]|\x{FFFD}/u', '', $convInput);
26+
if ($cleanInput !== null) {
27+
return $cleanInput;
28+
} else {
29+
$err = preg_last_error_msg();
30+
print("MagentoCLI response preg_replace() with error $err.\n");
31+
}
32+
}
33+
34+
return $input;
35+
}
36+
}

src/Magento/FunctionalTestingFramework/Util/Manifest/BaseParallelTestManifest.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ abstract class BaseParallelTestManifest extends BaseTestManifest
4141
*/
4242
protected $dirPath;
4343

44+
/**
45+
* An array of test name count in a single group
46+
* @var array
47+
*/
48+
protected $testCountsToGroup = [];
49+
4450
/**
4551
* BaseParallelTestManifest constructor.
4652
*
@@ -87,6 +93,8 @@ public function generate()
8793
foreach ($this->testGroups as $groupNumber => $groupContents) {
8894
$this->generateGroupFile($groupContents, $groupNumber, $suites);
8995
}
96+
97+
$this->generateGroupSummaryFile($this->testCountsToGroup);
9098
}
9199

92100
/**
@@ -114,17 +122,35 @@ protected function generateGroupFile($testGroup, $nodeNumber, $suites)
114122
foreach ($testGroup as $entryName => $testValue) {
115123
$fileResource = fopen($this->dirPath . DIRECTORY_SEPARATOR . "group{$nodeNumber}.txt", 'a');
116124

117-
$line = null;
125+
$this->testCountsToGroup["group{$nodeNumber}"] = $this->testCountsToGroup["group{$nodeNumber}"] ?? 0;
126+
118127
if (!empty($suites[$entryName])) {
119128
$line = "-g {$entryName}";
129+
$this->testCountsToGroup["group{$nodeNumber}"] += count($suites[$entryName]);
120130
} else {
121131
$line = $this->relativeDirPath . DIRECTORY_SEPARATOR . $entryName . '.php';
132+
$this->testCountsToGroup["group{$nodeNumber}"]++;
122133
}
123134
fwrite($fileResource, $line . PHP_EOL);
124135
fclose($fileResource);
125136
}
126137
}
127138

139+
/**
140+
* @param array $groups
141+
* @return void
142+
*/
143+
protected function generateGroupSummaryFile(array $groups)
144+
{
145+
$fileResource = fopen($this->dirPath . DIRECTORY_SEPARATOR . "mftf_group_summary.txt", 'w');
146+
$contents = "Total Number of Groups: " . count($groups) . PHP_EOL;
147+
foreach ($groups as $key => $value) {
148+
$contents .= $key . " - ". $value . " tests" .PHP_EOL;
149+
}
150+
fwrite($fileResource, $contents);
151+
fclose($fileResource);
152+
}
153+
128154
/**
129155
* Function which recusrively parses a given potentially multidimensional array of suites containing their split
130156
* groups. The result is a flattened array of suite names to relevant tests for generation of the manifest.

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
773773
$selector = $this->addUniquenessFunctionCall($customActionAttributes['selector']);
774774
$selector = $this->resolveLocatorFunctionInAttribute($selector);
775775
}
776-
776+
777777
if (isset($customActionAttributes['count'])) {
778778
$countClickValue = $customActionAttributes['count'];
779779
$countValue = $this->addUniquenessFunctionCall($countClickValue);

0 commit comments

Comments
 (0)