diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/Test/Objects/ActionObjectTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/Test/Objects/ActionObjectTest.php index b5aa8c4b1..8e3a1d579 100644 --- a/dev/tests/unit/Magento/FunctionalTestFramework/Test/Objects/ActionObjectTest.php +++ b/dev/tests/unit/Magento/FunctionalTestFramework/Test/Objects/ActionObjectTest.php @@ -191,6 +191,8 @@ public function testTimeoutFromElement() /** * {{PageObject.url}} should be replaced with someUrl.html + * + * @throws /Exception */ public function testResolveUrl() { @@ -213,6 +215,40 @@ public function testResolveUrl() $this->assertEquals($expected, $actionObject->getCustomActionAttributes()); } + /** + * {{PageObject}} should not be replaced and should elicit a warning in console + * + * @throws /Exception + */ + public function testResolveUrlWithNoAttribute() + { + // Set up mocks + $actionObject = new ActionObject('merge123', 'amOnPage', [ + 'url' => '{{PageObject}}' + ]); + $pageObject = new PageObject('PageObject', '/replacement/url.html', 'Test', [], false, "test"); + $pageObjectList = ["PageObject" => $pageObject]; + $instance = AspectMock::double( + PageObjectHandler::class, + ['getObject' => $pageObject, 'getAllObjects' => $pageObjectList] + )->make(); // bypass the private constructor + AspectMock::double(PageObjectHandler::class, ['getInstance' => $instance]); + + // Expect this warning to get generated + $this->expectOutputString( + "WARNING: Page url attribute not found for {{PageObject}} and is required for amOnPage." . PHP_EOL + ); + + // Call the method under test + $actionObject->resolveReferences(); + + // Verify + $expected = [ + 'url' => '{{PageObject}}' + ]; + $this->assertEquals($expected, $actionObject->getCustomActionAttributes()); + } + /** * {{PageObject.url(param)}} should be replaced */ diff --git a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php index 87b8d0a12..e2bd106d1 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php @@ -372,6 +372,13 @@ private function resolveUrlReference() $replacement = $this->findAndReplaceReferences(PageObjectHandler::getInstance(), $url); if ($replacement) { $this->resolvedCustomAttributes[ActionObject::ACTION_ATTRIBUTE_URL] = $replacement; + $allPages = PageObjectHandler::getInstance()->getAllObjects(); + if ( + $replacement === $url + && array_key_exists(trim($url, "{}"), $allPages) + ) { + echo("WARNING: Page url attribute not found for ${url} and is required for $this->type." . PHP_EOL); + } } }