diff --git a/dev/tests/verification/Resources/PageReplacementTest.txt b/dev/tests/verification/Resources/PageReplacementTest.txt index cda119999..6f75ee096 100644 --- a/dev/tests/verification/Resources/PageReplacementTest.txt +++ b/dev/tests/verification/Resources/PageReplacementTest.txt @@ -35,8 +35,8 @@ class PageReplacementTestCest $I->amOnPage("/John/StringLiteral2.html"); // stepKey: twoParamPageStringData $I->amOnPage("/John/" . $I->retrieveEntityField('datakey', 'firstname', 'test') . ".html"); // stepKey: twoParamPageDataPersist $I->amOnPage("/" . $I->retrieveEntityField('datakey', 'firstname', 'test') . "/StringLiteral2.html"); // stepKey: twoParamPagePersistString - $I->amOnPage("/" . getenv("MAGENTO_BACKEND_NAME") . "/backend"); // stepKey: onAdminPage - $I->amOnPage("/" . getenv("MAGENTO_BACKEND_NAME") . "/StringLiteral/page.html"); // stepKey: oneParamAdminPageString + $I->amOnPage((getenv("MAGENTO_BACKEND_BASE_URL") ? rtrim(getenv("MAGENTO_BACKEND_BASE_URL"), "/") : "") . "/" . getenv("MAGENTO_BACKEND_NAME") . "/backend"); // stepKey: onAdminPage + $I->amOnPage((getenv("MAGENTO_BACKEND_BASE_URL") ? rtrim(getenv("MAGENTO_BACKEND_BASE_URL"), "/") : "") . "/" . getenv("MAGENTO_BACKEND_NAME") . "/StringLiteral/page.html"); // stepKey: oneParamAdminPageString $I->amOnUrl("http://myFullUrl.com/"); // stepKey: onExternalPage } } diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AbstractExecutor.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AbstractExecutor.php index e27da3718..c1f03ad35 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AbstractExecutor.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AbstractExecutor.php @@ -7,7 +7,7 @@ namespace Magento\FunctionalTestingFramework\DataGenerator\Persist\Curl; use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException; -use Magento\FunctionalTestingFramework\Util\Path\UrlFormatter; +use Magento\FunctionalTestingFramework\Provider\UrlProvider; use Magento\FunctionalTestingFramework\Util\Protocol\CurlInterface; /** @@ -29,6 +29,6 @@ abstract class AbstractExecutor implements CurlInterface */ public function getBaseUrl(): string { - return UrlFormatter::format(getenv('MAGENTO_BASE_URL')); + return UrlProvider::getBaseUrl(); } } diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AdminExecutor.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AdminExecutor.php index 86b3b742f..5f2c6f365 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AdminExecutor.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AdminExecutor.php @@ -6,7 +6,8 @@ namespace Magento\FunctionalTestingFramework\DataGenerator\Persist\Curl; -use Magento\FunctionalTestingFramework\Util\Path\UrlFormatter; +use Magento\FunctionalTestingFramework\Page\Objects\PageObject; +use Magento\FunctionalTestingFramework\Provider\UrlProvider; use Magento\FunctionalTestingFramework\Util\Protocol\CurlInterface; use Magento\FunctionalTestingFramework\Util\Protocol\CurlTransport; use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException; @@ -64,16 +65,7 @@ public function __construct($removeBackend) */ public function getBaseUrl(): string { - $backendHost = getenv('MAGENTO_BACKEND_BASE_URL') - ? - UrlFormatter::format(getenv('MAGENTO_BACKEND_BASE_URL')) - : - parent::getBaseUrl(); - return empty(getenv('MAGENTO_BACKEND_NAME')) - ? - $backendHost - : - $backendHost . getenv('MAGENTO_BACKEND_NAME') . '/'; + return UrlProvider::getBaseUrl(PageObject::ADMIN_AREA); } /** diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php index 26c66acd1..6f45ae253 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php @@ -856,7 +856,8 @@ public function saveScreenshot() */ public function amOnPage($page) { - parent::amOnPage($page); + (0 === strpos($page, 'http')) ? parent::amOnUrl($page) : parent::amOnPage($page); + $this->waitForPageLoad(); } diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriverDoctor.php b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriverDoctor.php index 1407c957b..5fcbe649b 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriverDoctor.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriverDoctor.php @@ -7,6 +7,8 @@ namespace Magento\FunctionalTestingFramework\Module; use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException; +use Magento\FunctionalTestingFramework\Page\Objects\PageObject; +use Magento\FunctionalTestingFramework\Provider\UrlProvider; use Facebook\WebDriver\Remote\RemoteWebDriver; /** @@ -47,16 +49,14 @@ public function _initialize() } try { - $adminUrl = rtrim(getenv('MAGENTO_BACKEND_BASE_URL'), '/') - ?: rtrim(getenv('MAGENTO_BASE_URL'), '/') - . '/' . getenv('MAGENTO_BACKEND_NAME') . '/admin'; + $adminUrl = UrlProvider::getBaseUrl(PageObject::ADMIN_AREA); $this->loadPageAtUrl($adminUrl); } catch (\Exception $e) { $context[self::EXCEPTION_CONTEXT_ADMIN] = $e->getMessage(); } try { - $storeUrl = getenv('MAGENTO_BASE_URL'); + $storeUrl = UrlProvider::getBaseUrl(); $this->loadPageAtUrl($storeUrl); } catch (\Exception $e) { $context[self::EXCEPTION_CONTEXT_STOREFRONT] = $e->getMessage(); diff --git a/src/Magento/FunctionalTestingFramework/Provider/UrlProvider.php b/src/Magento/FunctionalTestingFramework/Provider/UrlProvider.php new file mode 100644 index 000000000..d6e3ca57b --- /dev/null +++ b/src/Magento/FunctionalTestingFramework/Provider/UrlProvider.php @@ -0,0 +1,49 @@ +getArea() == PageObject::ADMIN_AREA) { - $resolvedReplacement = "/{{_ENV.MAGENTO_BACKEND_NAME}}/" . $resolvedReplacement; + + if (get_class($object) === PageObject::class && $object->getArea() === PageObject::ADMIN_AREA) { + $urlSegments = [ + '{{_ENV.MAGENTO_BACKEND_BASE_URL}}', + '{{_ENV.MAGENTO_BACKEND_NAME}}', + $resolvedReplacement + ]; + + $resolvedReplacement = implode('/', $urlSegments); } return $resolvedReplacement; } diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index 2e7d265fa..dafbdaf7e 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -1942,20 +1942,23 @@ private function resolveRuntimeReference($args, $regex, $func) $newArgs = []; foreach ($args as $key => $arg) { + $newArgs[$key] = $arg; + preg_match_all($regex, $arg, $matches); if (!empty($matches[0])) { - $fullMatch = $matches[0][0]; - $refVariable = $matches[1][0]; - unset($matches); - $replacement = "{$func}(\"{$refVariable}\")"; + foreach ($matches[0] as $matchKey => $fullMatch) { + $refVariable = $matches[1][$matchKey]; + + $replacement = $this->getReplacement($func, $refVariable); + + $outputArg = $this->processQuoteBreaks($fullMatch, $newArgs[$key], $replacement); + $newArgs[$key] = $outputArg; + } - $outputArg = $this->processQuoteBreaks($fullMatch, $arg, $replacement); - $newArgs[$key] = $outputArg; + unset($matches); continue; } - $newArgs[$key] = $arg; } - // override passed in args for use later. return $newArgs; } @@ -2202,4 +2205,20 @@ private function hasDecimalPoint(string $outStr) { return strpos($outStr, localeconv()['decimal_point']) !== false; } + + /** + * Supports fallback for BACKEND URL + * + * @param string $func + * @param string $refVariable + * @return string + */ + private function getReplacement($func, $refVariable): string + { + if ($refVariable === 'MAGENTO_BACKEND_BASE_URL') { + return "({$func}(\"{$refVariable}\") ? rtrim({$func}(\"{$refVariable}\"), \"/\") : \"\")"; + } + + return "{$func}(\"{$refVariable}\")"; + } }