Skip to content

Mqe 2270 #786

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 2 commits into from
Aug 18, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -260,25 +260,6 @@ public function testGetAllTestObjectsWithInvalidExtends()
$toh->getAllObjects();
}

/**
* Function used to set mock for parser return and force init method to run between tests.
*
* @param array $data
* @throws \Exception
*/
private function setMockParserOutput($data)
{
// clear test object handler value to inject parsed content
$property = new \ReflectionProperty(TestObjectHandler::class, 'testObjectHandler');
$property->setAccessible(true);
$property->setValue(null);

$mockDataParser = AspectMock::double(TestDataParser::class, ['readTestData' => $data])->make();
$instance = AspectMock::double(ObjectManager::class, ['create' => $mockDataParser])
->make(); // bypass the private constructor
AspectMock::double(ObjectManagerFactory::class, ['getObjectManager' => $instance]);
}

/**
* Validate test object when ENABLE_PAUSE is set to true
*
Expand All @@ -299,7 +280,7 @@ public function testGetTestObjectWhenEnablePause()

$resolverMock = new MockModuleResolverBuilder();
$resolverMock->setup();
$this->setMockParserOutput($mockData);
ObjectHandlerUtil::mockTestObjectHandlerWitData($mockData);

// run object handler method
$toh = TestObjectHandler::getInstance();
Expand All @@ -325,7 +306,7 @@ public function testGetTestObjectWhenEnablePause()
$expectedFailedActionObject2 = new ActionObject(
'pauseWhenFailed',
'pause',
[]
[ActionObject::PAUSE_ACTION_INTERNAL_ATTRIBUTE => true]
);

$expectedBeforeHookObject = new TestHookObject(
Expand Down
25 changes: 23 additions & 2 deletions src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
class MagentoWebDriver extends WebDriver
{
use AttachmentSupport;
use Pause;
use Pause {
pause as codeceptPause;
}

const MAGENTO_CRON_INTERVAL = 60;
const MAGENTO_CRON_COMMAND = 'cron:run';
Expand Down Expand Up @@ -843,7 +845,7 @@ public function _failed(TestInterface $test, $fail)
if ($this->pngReport === null && $this->htmlReport === null) {
$this->saveScreenshot();
if (getenv('ENABLE_PAUSE') === 'true') {
$this->pause();
$this->pause(true);
}
}

Expand Down Expand Up @@ -1028,4 +1030,23 @@ public function switchToIFrame($locator = null)
$this->webDriver->switchTo()->frame($els[0]);
}
}

/**
* Invoke Codeption pause()
*
* @param boolean $pauseOnFail
* @return void
*/
public function pause($pauseOnFail = false)
{
if (!\Codeception\Util\Debug::isEnabled()) {
return;
}

if ($pauseOnFail) {
print(PHP_EOL . "Failure encountered. Pausing execution..." . PHP_EOL . PHP_EOL);
}

$this->codeceptPause();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class ActionObject
const ACTION_TYPE_COMMENT = 'comment';
const ACTION_TYPE_HELPER = 'helper';
const INVISIBLE_STEP_ACTIONS = ['retrieveEntityField', 'getSecret'];
const PAUSE_ACTION_INTERNAL_ATTRIBUTE = 'pauseOnFail';

/**
* The unique identifier for the action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ public function createDefaultFailedHook($parentName)
{
$defaultSteps['saveScreenshot'] = new ActionObject("saveScreenshot", "saveScreenshot", []);
if (getenv('ENABLE_PAUSE') === 'true') {
$defaultSteps['pauseWhenFailed'] = new ActionObject('pauseWhenFailed', 'pause', []);
$defaultSteps['pauseWhenFailed'] = new ActionObject(
'pauseWhenFailed',
'pause',
[ActionObject::PAUSE_ACTION_INTERNAL_ATTRIBUTE => true]
);
}

$hook = new TestHookObject(
Expand Down
10 changes: 10 additions & 0 deletions src/Magento/FunctionalTestingFramework/Util/TestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,16 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato

$testSteps .= $dateGenerateCode;
break;
case "pause":
$pauseAttr = $actionObject->getCustomActionAttributes(
ActionObject::PAUSE_ACTION_INTERNAL_ATTRIBUTE
);
if ($pauseAttr) {
$testSteps .= sprintf("\t\t$%s->%s(%s);", $actor, $actionObject->getType(), 'true');
} else {
$testSteps .= sprintf("\t\t$%s->%s();", $actor, $actionObject->getType());
}
break;
case "comment":
$input = $input === null ? strtr($value, ['$' => '\$', '{' => '\{', '}' => '\}']) : $input;
// Combining userInput from native XML comment and <comment/> action to fall-through 'default' case
Expand Down