From 5fa28d262631c970496f5d6a520dba49c1d712bb Mon Sep 17 00:00:00 2001 From: Tom Reece Date: Fri, 13 Mar 2020 11:30:41 -0500 Subject: [PATCH] MQE-2019: Remove dead code: Magento Readiness --- .../Resources/ActionGroupSkipReadiness.txt | 35 -- .../ActionGroupSkipReadiness.xml | 13 - .../Extension/PageReadinessExtension.php | 240 ------------ .../ReadinessMetrics/AbstractMetricCheck.php | 364 ------------------ .../ReadinessMetrics/DocumentReadyState.php | 43 --- .../ReadinessMetrics/JQueryAjaxRequests.php | 58 --- .../ReadinessMetrics/MagentoLoadingMasks.php | 54 --- .../PrototypeAjaxRequests.php | 58 --- .../ReadinessMetrics/RequireJsDefinitions.php | 60 --- .../Module/MagentoWebDriver.php | 12 - .../Test/Util/ActionMergeUtil.php | 37 -- .../Test/etc/mergedTestSchema.xsd | 7 - .../Util/TestGenerator.php | 3 - 13 files changed, 984 deletions(-) delete mode 100644 dev/tests/verification/Resources/ActionGroupSkipReadiness.txt delete mode 100644 dev/tests/verification/TestModule/Test/ActionGroupTest/ActionGroupSkipReadiness.xml delete mode 100644 src/Magento/FunctionalTestingFramework/Extension/PageReadinessExtension.php delete mode 100644 src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/AbstractMetricCheck.php delete mode 100644 src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/DocumentReadyState.php delete mode 100644 src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/JQueryAjaxRequests.php delete mode 100644 src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/MagentoLoadingMasks.php delete mode 100644 src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/PrototypeAjaxRequests.php delete mode 100644 src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/RequireJsDefinitions.php diff --git a/dev/tests/verification/Resources/ActionGroupSkipReadiness.txt b/dev/tests/verification/Resources/ActionGroupSkipReadiness.txt deleted file mode 100644 index 891054638..000000000 --- a/dev/tests/verification/Resources/ActionGroupSkipReadiness.txt +++ /dev/null @@ -1,35 +0,0 @@ -Test filesverification/TestModule/Test/ActionGroupTest/ActionGroupSkipReadiness.xml
") - */ -class ActionGroupSkipReadinessCest -{ - /** - * @Features({"TestModule"}) - * @Parameter(name = "AcceptanceTester", value="$I") - * @param AcceptanceTester $I - * @return void - * @throws \Exception - */ - public function ActionGroupSkipReadiness(AcceptanceTester $I) - { - $I->comment("Entering Action Group actionGroupWithSkipReadinessActions (skipReadinessActionGroup)"); - $I->skipReadinessCheck(true); - $I->comment("ActionGroupSkipReadiness"); - $I->skipReadinessCheck(false); - $I->comment("Exiting Action Group actionGroupWithSkipReadinessActions (skipReadinessActionGroup)"); - } -} diff --git a/dev/tests/verification/TestModule/Test/ActionGroupTest/ActionGroupSkipReadiness.xml b/dev/tests/verification/TestModule/Test/ActionGroupTest/ActionGroupSkipReadiness.xml deleted file mode 100644 index 776a6f10f..000000000 --- a/dev/tests/verification/TestModule/Test/ActionGroupTest/ActionGroupSkipReadiness.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - diff --git a/src/Magento/FunctionalTestingFramework/Extension/PageReadinessExtension.php b/src/Magento/FunctionalTestingFramework/Extension/PageReadinessExtension.php deleted file mode 100644 index 2dfcbec1a..000000000 --- a/src/Magento/FunctionalTestingFramework/Extension/PageReadinessExtension.php +++ /dev/null @@ -1,240 +0,0 @@ -getAction() pattern - * - * @var array - */ - private $ignoredActions = [ - 'saveScreenshot', - 'skipReadinessCheck', - 'wait' - ]; - - /** - * @var Logger - */ - private $logger; - - /** - * Logger verbosity - * - * @var boolean - */ - private $verbose; - - /** - * Array of readiness metrics, initialized during beforeTest event - * - * @var AbstractMetricCheck[] - */ - private $readinessMetrics; - - /** - * The name of the active test - * - * @var string - */ - private $testName; - - /** - * Initialize local vars - * - * @return void - * @throws \Exception - */ - public function _initialize() - { - $this->logger = LoggingUtil::getInstance()->getLogger(get_class($this)); - $this->verbose = MftfApplicationConfig::getConfig()->verboseEnabled(); - parent::_initialize(); - } - - /** - * Initialize the readiness metrics for the test - * - * @param TestEvent $e - * @return void - * @throws \Exception - */ - public function beforeTest(TestEvent $e) - { - parent::beforeTest($e); - if (isset($this->config['resetFailureThreshold'])) { - $failThreshold = intval($this->config['resetFailureThreshold']); - } else { - $failThreshold = 3; - } - - $this->testName = $e->getTest()->getMetadata()->getName(); - - $this->getDriver()->_setConfig(['skipReadiness' => false]); - - $metrics = []; - foreach ($this->config['readinessMetrics'] as $metricClass) { - $metrics[] = new $metricClass($this, $failThreshold); - } - - $this->readinessMetrics = $metrics; - } - - /** - * Waits for busy page flags to disappear before executing a step - * - * @param StepEvent $e - * @return void - * @throws \Exception - */ - public function beforeStep(StepEvent $e) - { - $step = $e->getStep(); - $manualSkip = $this->getDriver()->_getConfig()['skipReadiness']; - if ($this->shouldSkipCheck($step, $manualSkip)) { - return; - } - - $this->resetMetricTracker($step); - - $metrics = $this->readinessMetrics; - - $this->waitForReadiness($metrics); - - /** @var AbstractMetricCheck $metric */ - foreach ($metrics as $metric) { - $metric->finalizeForStep($step); - } - } - - /** - * Check if page has changed, if so reset metric tracking - * - * @param Step $step - * @return void - */ - private function resetMetricTracker($step) - { - if ($this->pageChanged($step)) { - $this->logDebug( - 'Page URI changed; resetting readiness metric failure tracking', - [ - 'step' => $step->__toString(), - 'newUri' => $this->getUri() - ] - ); - /** @var AbstractMetricCheck $metric */ - foreach ($this->readinessMetrics as $metric) { - $metric->resetTracker(); - } - } - } - - /** - * Wait for page readiness. - * @param array $metrics - * @return void - * @throws \Codeception\Exception\ModuleRequireException - * @throws \Facebook\WebDriver\Exception\NoSuchElementException - */ - private function waitForReadiness($metrics) - { - // todo: Implement step parameter to override global timeout configuration - if (isset($this->config['timeout'])) { - $timeout = intval($this->config['timeout']); - } else { - $timeout = $this->getDriver()->_getConfig()['pageload_timeout']; - } - - try { - $this->getDriver()->webDriver->wait($timeout)->until( - function () use ($metrics) { - $passing = true; - - /** @var AbstractMetricCheck $metric */ - foreach ($metrics as $metric) { - try { - if (!$metric->runCheck()) { - $passing = false; - } - } catch (UnexpectedAlertOpenException $exception) { - } - } - return $passing; - } - ); - } catch (TimeoutException $exception) { - } - } - - /** - * Gets the name of the active test - * - * @return string - */ - public function getTestName() - { - return $this->testName; - } - - /** - * 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 boolean $manualSkip - * @return boolean - */ - private function shouldSkipCheck($step, $manualSkip) - { - if ($step instanceof Step\Comment || in_array($step->getAction(), $this->ignoredActions) || $manualSkip) { - return true; - } - return false; - } - - /** - * If verbose, log the given message to logger->debug including test context information - * - * @param string $message - * @param array $context - * @return void - * @SuppressWarnings(PHPMD) - */ - private function logDebug($message, $context = []) - { - if ($this->verbose) { - $logContext = [ - 'test' => $this->testName, - 'uri' => $this->getUri() - ]; - foreach ($this->readinessMetrics as $metric) { - $logContext[$metric->getName()] = $metric->getStoredValue(); - $logContext[$metric->getName() . '.failCount'] = $metric->getFailureCount(); - } - $context = array_merge($logContext, $context); - //TODO REMOVE THIS LINE, UNCOMMENT LOGGER - //$this->logger->info($message, $context); - } - } -} diff --git a/src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/AbstractMetricCheck.php b/src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/AbstractMetricCheck.php deleted file mode 100644 index 8b611283d..000000000 --- a/src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/AbstractMetricCheck.php +++ /dev/null @@ -1,364 +0,0 @@ -extension = $extension; - $this->logger = LoggingUtil::getInstance()->getLogger(get_class($this)); - $this->verbose = MftfApplicationConfig::getConfig()->verboseEnabled(); - - // If the clearFailureOnPage() method is overridden, use the configured failure threshold - // If not, the default clearFailureOnPage() method does nothing so don't worry about resetting failures - $reflector = new \ReflectionMethod($this, 'clearFailureOnPage'); - if ($reflector->getDeclaringClass()->getName() === get_class($this)) { - $this->resetFailureThreshold = $resetFailureThreshold; - } else { - $this->resetFailureThreshold = -1; - } - - $this->resetTracker(); - } - - /** - * Does the given value pass the readiness metric - * - * @param mixed $value - * @return boolean - */ - abstract protected function doesMetricPass($value); - - /** - * Retrieve the active value for the metric to check from the page - * - * @return mixed - * @throws UnexpectedAlertOpenException - */ - abstract protected function fetchValueFromPage(); - - /** - * Override this method to reset the actual state of the page to make the metric pass - * This method is called when too many identical failures were encountered in a row - * - * @return void - */ - protected function clearFailureOnPage() - { - return; - } - - /** - * Get the base class name of the metric implementation - * - * @return string - */ - public function getName() - { - $clazz = get_class($this); - $namespaceBreak = strrpos($clazz, '\\'); - if ($namespaceBreak !== false) { - $clazz = substr($clazz, $namespaceBreak + 1); - } - return $clazz; - } - - /** - * Fetches a new value for the metric and checks if it passes, clearing the failure tracking if so - * - * Even on a success, the readiness check will continue to be run until all metrics pass at the same time in order - * to catch cases where a slow request of one metric can trigger calls for other metrics that were previously - * thought ready - * - * @return boolean - * @throws UnexpectedAlertOpenException - */ - public function runCheck() - { - if ($this->doesMetricPass($this->getCurrentValue(true))) { - $this->setTracker($this->getCurrentValue(), 0); - return true; - } - - return false; - } - - /** - * Update the state of the metric including tracked failure state and checking if a failing value is stuck and - * needs to be reset so future checks can be accurate - * - * Called when the readiness check is finished (either all metrics pass or the check has timed out) - * - * @param Step $step - * @return void - */ - public function finalizeForStep($step) - { - try { - $currentValue = $this->getCurrentValue(); - } catch (UnexpectedAlertOpenException $exception) { - $this->debugLog( - 'An alert is open, bypassing javascript-based metric check', - ['step' => $step->__toString()] - ); - return; - } - - if ($this->doesMetricPass($currentValue)) { - $this->setTracker($currentValue, 0); - } else { - // If failure happened on the same value as before, increment the fail count, otherwise set at 1 - if (!isset($this->storedValue) || $currentValue !== $this->getStoredValue()) { - $failCount = 1; - } else { - $failCount = $this->getFailureCount() + 1; - } - $this->setTracker($currentValue, $failCount); - - $this->errorLog('Failed readiness check', ['step' => $step->__toString()]); - - if ($this->resetFailureThreshold >= 0 && $failCount >= $this->resetFailureThreshold) { - $this->debugLog( - 'Too many failures, assuming metric is stuck and resetting state', - ['step' => $step->__toString()] - ); - $this->resetMetric(); - } - } - } - - /** - * Helper function to retrieve the driver being used to run the test - * - * @return WebDriver - * @throws ModuleRequireException - */ - protected function getDriver() - { - return $this->extension->getDriver(); - } - - /** - * Helper function to execute javascript code, see WebDriver::executeJs for more information - * - * @param string $script - * @param array $arguments - * @return mixed - * @throws ModuleRequireException - */ - protected function executeJs($script, $arguments = []) - { - return $this->extension->getDriver()->executeJS($script, $arguments); - } - - /** - * Gets the current state of the given variable - * Fetches an updated value if not known or $refresh is true - * - * @param boolean $refresh - * @return mixed - * @throws UnexpectedAlertOpenException - */ - private function getCurrentValue($refresh = false) - { - if ($refresh) { - unset($this->currentValue); - } - if (!isset($this->currentValue)) { - $this->currentValue = $this->fetchValueFromPage(); - } - return $this->currentValue; - } - - /** - * Returns the value of the given variable for the previous check - * - * @return mixed - */ - public function getStoredValue() - { - return $this->storedValue ?? null; - } - - /** - * The current count of sequential identical failures - * Used to detect potentially stuck metrics - * - * @return integer - */ - public function getFailureCount() - { - return $this->failCount; - } - - /** - * Update the state of the page to pass the metric and clear the saved failure state - * Called when a failure is found to be stuck - * - * @return void - */ - private function resetMetric() - { - $this->clearFailureOnPage(); - $this->resetTracker(); - } - - /** - * Tracks the most recent value and the number of identical failures in a row - * - * @param mixed $value - * @param integer $failCount - * @return void - */ - public function setTracker($value, $failCount) - { - unset($this->currentValue); - $this->storedValue = $value; - $this->failCount = $failCount; - } - - /** - * Resets the tracked metric values on a new page or stuck failure - * - * @return void - */ - public function resetTracker() - { - unset($this->currentValue); - unset($this->storedValue); - $this->failCount = 0; - } - - /** - * Log the given message to logger->error including context information - * - * @param string $message - * @param array $context - * @return void - * @SuppressWarnings(PHPMD) - */ - protected function errorLog($message, $context = []) - { - $context = array_merge($this->getLogContext(), $context); - //TODO REMOVE THIS LINE, UNCOMMENT LOGGER - //$this->logger->error($message, $context); - } - - /** - * Log the given message to logger->info including context information - * - * @param string $message - * @param array $context - * @return void - * @SuppressWarnings(PHPMD) - */ - protected function infoLog($message, $context = []) - { - $context = array_merge($this->getLogContext(), $context); - //TODO REMOVE THIS LINE, UNCOMMENT LOGGER - //$this->logger->info($message, $context); - } - - /** - * If verbose, log the given message to logger->debug including context information - * - * @param string $message - * @param array $context - * @return void - * @SuppressWarnings(PHPMD) - */ - protected function debugLog($message, $context = []) - { - if ($this->verbose) { - $context = array_merge($this->getLogContext(), $context); - //TODO REMOVE THIS LINE, UNCOMMENT LOGGER - //$this->logger->debug($message, $context); - } - } - - /** - * Base context information to include in all log messages: test name, current URI, metric state - * Reports most recent stored value, not current value, so call setTracker() first to update - * - * @return array - */ - private function getLogContext() - { - return [ - 'test' => $this->extension->getTestName(), - 'uri' => $this->extension->getUri(), - $this->getName() => $this->getStoredValue(), - $this->getName() . '.failCount' => $this->getFailureCount() - ]; - } -} diff --git a/src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/DocumentReadyState.php b/src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/DocumentReadyState.php deleted file mode 100644 index 26cf91aa7..000000000 --- a/src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/DocumentReadyState.php +++ /dev/null @@ -1,43 +0,0 @@ -executeJS('return document.readyState;'); - } -} diff --git a/src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/JQueryAjaxRequests.php b/src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/JQueryAjaxRequests.php deleted file mode 100644 index c005923d3..000000000 --- a/src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/JQueryAjaxRequests.php +++ /dev/null @@ -1,58 +0,0 @@ -executeJS( - 'if (!!window.jQuery) { - return window.jQuery.active; - } - return 0;' - ) - ); - } - - /** - * Active request count can get stuck above zero if an exception is thrown during a callback, causing the - * ajax handler method to fail before decrementing the request count - * - * @return void - * @throws UnexpectedAlertOpenException - */ - protected function clearFailureOnPage() - { - $this->executeJS('if (!!window.jQuery) { window.jQuery.active = 0; };'); - } -} diff --git a/src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/MagentoLoadingMasks.php b/src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/MagentoLoadingMasks.php deleted file mode 100644 index 4f15524ba..000000000 --- a/src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/MagentoLoadingMasks.php +++ /dev/null @@ -1,54 +0,0 @@ -getDriver()->webDriver->findElements($driverLocator); - foreach ($maskElements as $element) { - try { - if ($element->isDisplayed()) { - return "$maskLocator : " . $element ->getID(); - } - } catch (NoSuchElementException $e) { - } catch (StaleElementReferenceException $e) { - } - } - } - return null; - } -} diff --git a/src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/PrototypeAjaxRequests.php b/src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/PrototypeAjaxRequests.php deleted file mode 100644 index 2fc8f70cb..000000000 --- a/src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/PrototypeAjaxRequests.php +++ /dev/null @@ -1,58 +0,0 @@ -executeJS( - 'if (!!window.Prototype) { - return window.Ajax.activeRequestCount; - } - return 0;' - ) - ); - } - - /** - * Active request count can get stuck above zero if an exception is thrown during a callback, causing the - * ajax handler method to fail before decrementing the request count - * - * @return void - * @throws UnexpectedAlertOpenException - */ - protected function clearFailureOnPage() - { - $this->executeJS('if (!!window.Prototype) { window.Ajax.activeRequestCount = 0; };'); - } -} diff --git a/src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/RequireJsDefinitions.php b/src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/RequireJsDefinitions.php deleted file mode 100644 index 6df470123..000000000 --- a/src/Magento/FunctionalTestingFramework/Extension/ReadinessMetrics/RequireJsDefinitions.php +++ /dev/null @@ -1,60 +0,0 @@ -executeJS($script); - if ($moduleInProgress === 'null') { - $moduleInProgress = null; - } - return $moduleInProgress; - } -} diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php index 26c66acd1..b02675163 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php @@ -860,18 +860,6 @@ public function amOnPage($page) $this->waitForPageLoad(); } - /** - * Turn Readiness check on or off - * - * @param boolean $check - * @return void - * @throws \Exception - */ - public function skipReadinessCheck($check) - { - $this->config['skipReadiness'] = $check; - } - /** * Clean Javascript errors in internal array * diff --git a/src/Magento/FunctionalTestingFramework/Test/Util/ActionMergeUtil.php b/src/Magento/FunctionalTestingFramework/Test/Util/ActionMergeUtil.php index 159822db1..28a7d405d 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Util/ActionMergeUtil.php +++ b/src/Magento/FunctionalTestingFramework/Test/Util/ActionMergeUtil.php @@ -23,9 +23,6 @@ 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'; @@ -86,7 +83,6 @@ public function resolveActionSteps($parsedSteps, $skipActionGroupResolution = fa { $this->mergeActions($parsedSteps); $this->insertWaits(); - $this->insertReadinessSkips(); if ($skipActionGroupResolution) { return $this->orderedSteps; @@ -233,39 +229,6 @@ 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. * diff --git a/src/Magento/FunctionalTestingFramework/Test/etc/mergedTestSchema.xsd b/src/Magento/FunctionalTestingFramework/Test/etc/mergedTestSchema.xsd index 6ded366bb..6690ef8dd 100644 --- a/src/Magento/FunctionalTestingFramework/Test/etc/mergedTestSchema.xsd +++ b/src/Magento/FunctionalTestingFramework/Test/etc/mergedTestSchema.xsd @@ -136,13 +136,6 @@ - - - - Flag for skipping readiness check. - - - diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index 275c01c8f..e0543463d 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -1334,9 +1334,6 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato $testSteps .= $dateGenerateCode; break; - case "skipReadinessCheck": - $testSteps .= $this->wrapFunctionCall($actor, $actionObject, $customActionAttributes['state']); - break; case "comment": $input = $input === null ? strtr($value, ['$' => '\$', '{' => '\{', '}' => '\}']) : $input; // Combining userInput from native XML comment and action to fall-through 'default' case