Skip to content

Commit 5d6d254

Browse files
authored
MQE-1157: Add readiness bypass to test actions (magento#207)
* MQE-1157: Add readiness bypass to test actions - Adding skip readiness getter - Adding skip readiness attribute * MQE-1157: Add readiness bypass to test actions - Adding setp generation to TestGeneration * MQE-1157: Add readiness bypass to test actions - Added skip command to web driver - Added check to page readiness extension * MQE-1157: Add readiness bypass to test actions - Updated Tests - Added Restriction for action groups * MQE-1157: Add readiness bypass to test actions - Removed testing statements and unused code * MQE-1157: Add readiness bypass to test actions - Removed print statements, created action steps instead * MQE-1157: Add readiness bypass to test actions - Adding action to readiness skip list - Adjusting conditional to check string match
1 parent 487a9c0 commit 5d6d254

File tree

12 files changed

+132
-4
lines changed

12 files changed

+132
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 ActionGroupSkipReadinessCest
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 ActionGroupSkipReadiness(AcceptanceTester $I)
31+
{
32+
$I->skipReadinessCheck(true);
33+
$I->comment("ActionGroupSkipReadiness");
34+
$I->skipReadinessCheck(false);
35+
}
36+
}

dev/tests/verification/Resources/BasicFunctionalTest.txt

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class BasicFunctionalTestCest
6262
{
6363
$I->comment("");
6464
$I->comment("");
65+
$I->skipReadinessCheck(true);
66+
$I->comment("skipReadiness");
67+
$I->skipReadinessCheck(false);
6568
$someVarDefinition = $I->grabValueFrom();
6669
$I->acceptPopup();
6770
$I->amOnPage("/test/url");

dev/tests/verification/TestModule/ActionGroup/BasicActionGroup.xml

+4
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,8 @@
114114
</arguments>
115115
<see selector=".selector" userInput="{{sameStepKeyAsArg}}" stepKey="arg1" />
116116
</actionGroup>
117+
118+
<actionGroup name="actionGroupWithSkipReadinessActions">
119+
<comment userInput="ActionGroupSkipReadiness" stepKey="skip" skipReadiness="true"/>
120+
</actionGroup>
117121
</actionGroups>

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

+4
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@
144144
</before>
145145
</test>
146146

147+
<test name="ActionGroupSkipReadiness">
148+
<actionGroup ref="actionGroupWithSkipReadinessActions" stepKey="skipReadinessActionGroup"/>
149+
</test>
150+
147151
<test name="ActionGroupContainsStepKeyInArgText">
148152
<before>
149153
<actionGroup ref="actionGroupContainsStepKeyInArgValue" stepKey="actionGroup">

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

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
</after>
2525
<comment stepKey="basicCommentWithNoData" userInput="{{emptyData.noData}}"/>
2626
<comment stepKey="basicCommentWithDefinitelyNoData" userInput="{{emptyData.definitelyNoData}}"/>
27+
<comment stepKey="ReadinessCheckSkipped" userInput="skipReadiness" skipReadiness="true"/>
2728
<grabValueFrom stepKey="someVarDefinition"/>
2829
<acceptPopup stepKey="acceptPopupKey1"/>
2930
<amOnPage stepKey="amOnPageKey1" url="/test/url"/>

dev/tests/verification/Tests/ActionGroupGenerationTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,15 @@ public function testActionGroupWithArgContainingStepKey()
184184
{
185185
$this->generateAndCompareTest('ActionGroupContainsStepKeyInArgText');
186186
}
187+
188+
/**
189+
* Test an action group with an arg containing stepKey text
190+
*
191+
* @throws \Exception
192+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
193+
*/
194+
public function testActionGroupWithSkipReadiness()
195+
{
196+
$this->generateAndCompareTest('ActionGroupSkipReadiness');
197+
}
187198
}

src/Magento/FunctionalTestingFramework/Extension/PageReadinessExtension.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class PageReadinessExtension extends Extension
4343
*/
4444
private $ignoredActions = [
4545
'saveScreenshot',
46+
'skipReadinessCheck',
4647
'wait'
4748
];
4849

@@ -119,6 +120,8 @@ public function beforeTest(TestEvent $e)
119120
$this->testName = $e->getTest()->getMetadata()->getName();
120121
$this->uri = null;
121122

123+
$this->getDriver()->_setConfig(['skipReadiness' => false]);
124+
122125
$metrics = [];
123126
foreach ($this->config['readinessMetrics'] as $metricClass) {
124127
$metrics[] = new $metricClass($this, $failThreshold);
@@ -137,7 +140,8 @@ public function beforeTest(TestEvent $e)
137140
public function beforeStep(StepEvent $e)
138141
{
139142
$step = $e->getStep();
140-
if ($this->shouldSkipCheck($step)) {
143+
$manualSkip = $this->getDriver()->_getConfig()['skipReadiness'];
144+
if ($this->shouldSkipCheck($step, $manualSkip)) {
141145
return;
142146
}
143147

@@ -234,12 +238,13 @@ public function getTestName()
234238
* Should the given step bypass the readiness checks
235239
* todo: Implement step parameter to bypass specific metrics (or all) instead of basing on action type
236240
*
237-
* @param Step $step
241+
* @param Step $step
242+
* @param boolean $manualSkip
238243
* @return boolean
239244
*/
240-
private function shouldSkipCheck($step)
245+
private function shouldSkipCheck($step, $manualSkip)
241246
{
242-
if ($step instanceof Step\Comment || in_array($step->getAction(), $this->ignoredActions)) {
247+
if ($step instanceof Step\Comment || in_array($step->getAction(), $this->ignoredActions) || $manualSkip) {
243248
return true;
244249
}
245250
return false;

src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php

+12
Original file line numberDiff line numberDiff line change
@@ -690,4 +690,16 @@ public function amOnPage($page)
690690
parent::amOnPage($page);
691691
$this->waitForPageLoad();
692692
}
693+
694+
/**
695+
* Turn Readiness check on or off
696+
*
697+
* @param boolean $check
698+
* @throws \Exception
699+
* @return void
700+
*/
701+
public function skipReadinessCheck($check)
702+
{
703+
$this->config['skipReadiness'] = $check;
704+
}
693705
}

src/Magento/FunctionalTestingFramework/Test/Util/ActionMergeUtil.php

+39
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class ActionMergeUtil
2323
const WAIT_ATTR = 'timeout';
2424
const WAIT_ACTION_NAME = 'waitForPageLoad';
2525
const WAIT_ACTION_SUFFIX = 'WaitForPageLoad';
26+
const SKIP_READINESS_ACTION_NAME = 'skipReadinessCheck';
27+
const SKIP_READINESS_OFF_SUFFIX = 'SkipReadinessOff';
28+
const SKIP_READINESS_ON_SUFFIX = 'SkipReadinessOn';
29+
const DEFAULT_SKIP_ON_ORDER = 'before';
30+
const DEFAULT_SKIP_OFF_ORDER = 'after';
2631
const DEFAULT_WAIT_ORDER = 'after';
2732

2833
/**
@@ -78,6 +83,7 @@ public function resolveActionSteps($parsedSteps, $skipActionGroupResolution = fa
7883
{
7984
$this->mergeActions($parsedSteps);
8085
$this->insertWaits();
86+
$this->insertReadinessSkips();
8187

8288
if ($skipActionGroupResolution) {
8389
return $this->orderedSteps;
@@ -217,6 +223,39 @@ private function insertWaits()
217223
}
218224
}
219225

226+
/**
227+
* Runs through the prepared orderedSteps and calls insertWait if a step requires a wait after it.
228+
*
229+
* @return void
230+
*/
231+
private function insertReadinessSkips()
232+
{
233+
foreach ($this->orderedSteps as $step) {
234+
if (array_key_exists("skipReadiness", $step->getCustomActionAttributes())) {
235+
if ($step->getCustomActionAttributes()['skipReadiness'] == "true") {
236+
$skipReadinessOn = new ActionObject(
237+
$step->getStepKey() . self::SKIP_READINESS_ON_SUFFIX,
238+
self::SKIP_READINESS_ACTION_NAME,
239+
['state' => "true"],
240+
$step->getStepKey(),
241+
self::DEFAULT_SKIP_ON_ORDER
242+
);
243+
244+
$skipReadinessOff = new ActionObject(
245+
$step->getStepKey() . self::SKIP_READINESS_OFF_SUFFIX,
246+
self::SKIP_READINESS_ACTION_NAME,
247+
['state' => "false"],
248+
$step->getStepKey(),
249+
self::DEFAULT_SKIP_OFF_ORDER
250+
);
251+
252+
$this->insertStep($skipReadinessOn);
253+
$this->insertStep($skipReadinessOff);
254+
}
255+
}
256+
}
257+
}
258+
220259
/**
221260
* This method takes the steps from the parser and splits steps which need merge from steps that are ordered.
222261
*

src/Magento/FunctionalTestingFramework/Test/etc/Actions/commonAttributes.xsd

+8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
</xs:documentation>
3131
</xs:annotation>
3232
</xs:attribute>
33+
34+
<xs:attribute type="xs:boolean" name="skipReadiness">
35+
<xs:annotation>
36+
<xs:documentation>
37+
Flag for skipping readiness check
38+
</xs:documentation>
39+
</xs:annotation>
40+
</xs:attribute>
3341
</xs:attributeGroup>
3442

3543
<xs:attribute type="xs:string" name="userInput" id="userInput">

src/Magento/FunctionalTestingFramework/Test/etc/mergedTestSchema.xsd

+1
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,6 @@
130130
</xs:annotation>
131131
</xs:attribute>
132132
<xs:attributeGroup ref="commonActionAttributes"/>
133+
<xs:attribute type="xs:boolean" name="skipReadiness" use="prohibited"/>
133134
</xs:complexType>
134135
</xs:schema>

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

+4
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
476476

477477
foreach ($actionObjects as $actionObject) {
478478
$stepKey = $actionObject->getStepKey();
479+
479480
$customActionAttributes = $actionObject->getCustomActionAttributes();
480481
$attribute = null;
481482
$selector = null;
@@ -1281,6 +1282,9 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
12811282

12821283
$testSteps .= $dateGenerateCode;
12831284
break;
1285+
case "skipReadinessCheck":
1286+
$testSteps .= $this->wrapFunctionCall($actor, $actionObject, $customActionAttributes['state']);
1287+
break;
12841288
default:
12851289
$testSteps .= $this->wrapFunctionCall($actor, $actionObject, $selector, $input, $parameter);
12861290
}

0 commit comments

Comments
 (0)