MOBILE-4061 behat: Handle custom url async function

main
Pau Ferrer Ocaña 2022-05-09 10:02:11 +02:00
parent 064ea15f8b
commit 92d4a6a16b
2 changed files with 32 additions and 4 deletions

View File

@ -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';
}
}

View File

@ -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<string> {
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);