From 92d4a6a16b1392e603f882408b81636a2d65137f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Mon, 9 May 2022 10:02:11 +0200 Subject: [PATCH] MOBILE-4061 behat: Handle custom url async function --- .../tests/behat/behat_app.php | 14 ++++++++++-- src/testing/services/behat-runtime.ts | 22 +++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/local-moodleappbehat/tests/behat/behat_app.php b/local-moodleappbehat/tests/behat/behat_app.php index e17c9e1fd..2d59da7ec 100644 --- a/local-moodleappbehat/tests/behat/behat_app.php +++ b/local-moodleappbehat/tests/behat/behat_app.php @@ -731,9 +731,10 @@ class behat_app extends behat_base { throw new DriverException('Invalid custom link title - ' . $title); } - $url = "moodlemobile://link=" . urlencode($pageurl); + $urlscheme = $this->get_mobile_url_scheme(); + $url = "$urlscheme://link=" . urlencode($pageurl); - $this->evaluate_script("return window.urlSchemes.handleCustomURL('$url')"); + $this->evaluate_async_script("return window.behat.handleCustomURL('$url')"); $this->wait_for_pending_js(); } @@ -1180,4 +1181,13 @@ class behat_app extends behat_base { return $result; } + /** + * Returns the current mobile url scheme of the site. + */ + private function get_mobile_url_scheme() { + $mobilesettings = get_config('tool_mobile'); + + return !empty($mobilesettings->forcedurlscheme) ? $mobilesettings->forcedurlscheme : 'moodlemobile'; + } + } diff --git a/src/testing/services/behat-runtime.ts b/src/testing/services/behat-runtime.ts index a13bb61a1..10d573b74 100644 --- a/src/testing/services/behat-runtime.ts +++ b/src/testing/services/behat-runtime.ts @@ -14,6 +14,7 @@ import { TestsBehatDomUtils } from './behat-dom'; import { TestsBehatBlocking } from './behat-blocking'; +import { CoreCustomURLSchemes } from '@services/urlschemes'; /** * Behat runtime servive with public API. @@ -35,14 +36,31 @@ export class TestsBehatRuntime { pressStandard: TestsBehatRuntime.pressStandard, scrollTo: TestsBehatRuntime.scrollTo, setField: TestsBehatRuntime.setField, + handleCustomURL: TestsBehatRuntime.handleCustomURL, }; } + /** + * Handles a custom URL. + * + * @param url Url to open. + * @return OK if successful, or ERROR: followed by message. + */ + static async handleCustomURL(url: string): Promise { + try { + await CoreCustomURLSchemes.handleCustomURL(url); + + return 'OK'; + } catch (error) { + return 'ERROR: ' + error.message; + } + } + /** * Function to find and click an app standard button. * - * @param button Type of button to press - * @return OK if successful, or ERROR: followed by message + * @param button Type of button to press. + * @return OK if successful, or ERROR: followed by message. */ static pressStandard(button: string): string { this.log('Action - Click standard button: ' + button);