Skip to content

MQE-1157: Add readiness bypass to test actions #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions dev/tests/verification/Resources/ActionGroupSkipReadiness.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
namespace Magento\AcceptanceTest\_default\Backend;

use Magento\FunctionalTestingFramework\AcceptanceTester;
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
use Magento\FunctionalTestingFramework\DataGenerator\Persist\DataPersistenceHandler;
use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\CredentialStore;
use \Codeception\Util\Locator;
use Yandex\Allure\Adapter\Annotation\Features;
use Yandex\Allure\Adapter\Annotation\Stories;
use Yandex\Allure\Adapter\Annotation\Title;
use Yandex\Allure\Adapter\Annotation\Description;
use Yandex\Allure\Adapter\Annotation\Parameter;
use Yandex\Allure\Adapter\Annotation\Severity;
use Yandex\Allure\Adapter\Model\SeverityLevel;
use Yandex\Allure\Adapter\Annotation\TestCaseId;

/**
*/
class ActionGroupSkipReadinessCest
{
/**
* @Features({"TestModule"})
* @Parameter(name = "AcceptanceTester", value="$I")
* @param AcceptanceTester $I
* @return void
* @throws \Exception
*/
public function ActionGroupSkipReadiness(AcceptanceTester $I)
{
$I->skipReadinessCheck(true);
$I->comment("ActionGroupSkipReadiness");
$I->skipReadinessCheck(false);
}
}
3 changes: 3 additions & 0 deletions dev/tests/verification/Resources/BasicFunctionalTest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class BasicFunctionalTestCest
{
$I->comment("");
$I->comment("");
$I->skipReadinessCheck(true);
$I->comment("skipReadiness");
$I->skipReadinessCheck(false);
$someVarDefinition = $I->grabValueFrom();
$I->acceptPopup();
$I->amOnPage("/test/url");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,8 @@
</arguments>
<see selector=".selector" userInput="{{sameStepKeyAsArg}}" stepKey="arg1" />
</actionGroup>

<actionGroup name="actionGroupWithSkipReadinessActions">
<comment userInput="ActionGroupSkipReadiness" stepKey="skip" skipReadiness="true"/>
</actionGroup>
</actionGroups>
4 changes: 4 additions & 0 deletions dev/tests/verification/TestModule/Test/ActionGroupTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@
</before>
</test>

<test name="ActionGroupSkipReadiness">
<actionGroup ref="actionGroupWithSkipReadinessActions" stepKey="skipReadinessActionGroup"/>
</test>

<test name="ActionGroupContainsStepKeyInArgText">
<before>
<actionGroup ref="actionGroupContainsStepKeyInArgValue" stepKey="actionGroup">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
</after>
<comment stepKey="basicCommentWithNoData" userInput="{{emptyData.noData}}"/>
<comment stepKey="basicCommentWithDefinitelyNoData" userInput="{{emptyData.definitelyNoData}}"/>
<comment stepKey="ReadinessCheckSkipped" userInput="skipReadiness" skipReadiness="true"/>
<grabValueFrom stepKey="someVarDefinition"/>
<acceptPopup stepKey="acceptPopupKey1"/>
<amOnPage stepKey="amOnPageKey1" url="/test/url"/>
Expand Down
11 changes: 11 additions & 0 deletions dev/tests/verification/Tests/ActionGroupGenerationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,15 @@ public function testActionGroupWithArgContainingStepKey()
{
$this->generateAndCompareTest('ActionGroupContainsStepKeyInArgText');
}

/**
* Test an action group with an arg containing stepKey text
*
* @throws \Exception
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
*/
public function testActionGroupWithSkipReadiness()
{
$this->generateAndCompareTest('ActionGroupSkipReadiness');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class PageReadinessExtension extends Extension
*/
private $ignoredActions = [
'saveScreenshot',
'skipReadinessCheck',
'wait'
];

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

$this->getDriver()->_setConfig(['skipReadiness' => false]);

$metrics = [];
foreach ($this->config['readinessMetrics'] as $metricClass) {
$metrics[] = new $metricClass($this, $failThreshold);
Expand All @@ -137,7 +140,8 @@ public function beforeTest(TestEvent $e)
public function beforeStep(StepEvent $e)
{
$step = $e->getStep();
if ($this->shouldSkipCheck($step)) {
$manualSkip = $this->getDriver()->_getConfig()['skipReadiness'];
if ($this->shouldSkipCheck($step, $manualSkip)) {
return;
}

Expand Down Expand Up @@ -234,12 +238,13 @@ public function getTestName()
* Should the given step bypass the readiness checks
* todo: Implement step parameter to bypass specific metrics (or all) instead of basing on action type
*
* @param Step $step
* @param Step $step
* @param boolean $manualSkip
* @return boolean
*/
private function shouldSkipCheck($step)
private function shouldSkipCheck($step, $manualSkip)
{
if ($step instanceof Step\Comment || in_array($step->getAction(), $this->ignoredActions)) {
if ($step instanceof Step\Comment || in_array($step->getAction(), $this->ignoredActions) || $manualSkip) {
return true;
}
return false;
Expand Down
12 changes: 12 additions & 0 deletions src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,4 +669,16 @@ public function amOnPage($page)
parent::amOnPage($page);
$this->waitForPageLoad();
}

/**
* Turn Readiness check on or off
*
* @param boolean $check
* @throws \Exception
* @return void
*/
public function skipReadinessCheck($check)
{
$this->config['skipReadiness'] = $check;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class ActionMergeUtil
const WAIT_ATTR = 'timeout';
const WAIT_ACTION_NAME = 'waitForPageLoad';
const WAIT_ACTION_SUFFIX = 'WaitForPageLoad';
const SKIP_READINESS_ACTION_NAME = 'skipReadinessCheck';
const SKIP_READINESS_OFF_SUFFIX = 'SkipReadinessOff';
const SKIP_READINESS_ON_SUFFIX = 'SkipReadinessOn';
const DEFAULT_SKIP_ON_ORDER = 'before';
const DEFAULT_SKIP_OFF_ORDER = 'after';
const DEFAULT_WAIT_ORDER = 'after';

/**
Expand Down Expand Up @@ -78,6 +83,7 @@ public function resolveActionSteps($parsedSteps, $skipActionGroupResolution = fa
{
$this->mergeActions($parsedSteps);
$this->insertWaits();
$this->insertReadinessSkips();

if ($skipActionGroupResolution) {
return $this->orderedSteps;
Expand Down Expand Up @@ -217,6 +223,39 @@ private function insertWaits()
}
}

/**
* Runs through the prepared orderedSteps and calls insertWait if a step requires a wait after it.
*
* @return void
*/
private function insertReadinessSkips()
{
foreach ($this->orderedSteps as $step) {
if (array_key_exists("skipReadiness", $step->getCustomActionAttributes())) {
if ($step->getCustomActionAttributes()['skipReadiness'] == "true") {
$skipReadinessOn = new ActionObject(
$step->getStepKey() . self::SKIP_READINESS_ON_SUFFIX,
self::SKIP_READINESS_ACTION_NAME,
['state' => "true"],
$step->getStepKey(),
self::DEFAULT_SKIP_ON_ORDER
);

$skipReadinessOff = new ActionObject(
$step->getStepKey() . self::SKIP_READINESS_OFF_SUFFIX,
self::SKIP_READINESS_ACTION_NAME,
['state' => "false"],
$step->getStepKey(),
self::DEFAULT_SKIP_OFF_ORDER
);

$this->insertStep($skipReadinessOn);
$this->insertStep($skipReadinessOff);
}
}
}
}

/**
* This method takes the steps from the parser and splits steps which need merge from steps that are ordered.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
</xs:documentation>
</xs:annotation>
</xs:attribute>

<xs:attribute type="xs:boolean" name="skipReadiness">
<xs:annotation>
<xs:documentation>
Flag for skipping readiness check
</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:attributeGroup>

<xs:attribute type="xs:string" name="userInput" id="userInput">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,6 @@
</xs:annotation>
</xs:attribute>
<xs:attributeGroup ref="commonActionAttributes"/>
<xs:attribute type="xs:boolean" name="skipReadiness" use="prohibited"/>
</xs:complexType>
</xs:schema>
4 changes: 4 additions & 0 deletions src/Magento/FunctionalTestingFramework/Util/TestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "

foreach ($actionObjects as $actionObject) {
$stepKey = $actionObject->getStepKey();

$customActionAttributes = $actionObject->getCustomActionAttributes();
$attribute = null;
$selector = null;
Expand Down Expand Up @@ -1271,6 +1272,9 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "

$testSteps .= $dateGenerateCode;
break;
case "skipReadinessCheck":
$testSteps .= $this->wrapFunctionCall($actor, $actionObject, $customActionAttributes['state']);
break;
default:
$testSteps .= $this->wrapFunctionCall($actor, $actionObject, $selector, $input, $parameter);
}
Expand Down