Merge pull request #40 from NoelDeMartin/MOBILE-3898

MOBILE-3898 behat: Remove generic transformers
main
Dani Palou 2021-10-21 12:05:55 +02:00 committed by GitHub
commit ccc79f4ab5
1 changed files with 16 additions and 24 deletions

View File

@ -159,9 +159,10 @@ class behat_app extends behat_base {
*
* @Then /^I should( not)? find (".+") in the app$/
* @param bool $not
* @param object $locator
* @param string $locator
*/
public function i_find_in_the_app(bool $not, object $locator) {
public function i_find_in_the_app(bool $not, string $locator) {
$locator = $this->parse_element_locator($locator);
$locatorjson = json_encode($locator);
$this->spin(function() use ($not, $locatorjson) {
@ -185,10 +186,11 @@ class behat_app extends behat_base {
* Check if elements are selected in the app.
*
* @Then /^(".+") should( not)? be selected in the app$/
* @param object $locator
* @param string $locator
* @param bool $not
*/
public function be_selected_in_the_app(object $locator, bool $not = false) {
public function be_selected_in_the_app(string $locator, bool $not = false) {
$locator = $this->parse_element_locator($locator);
$locatorjson = json_encode($locator);
$this->spin(function() use ($locatorjson, $not) {
@ -474,7 +476,7 @@ class behat_app extends behat_base {
: $page->find('xpath', '//core-login-site-onboarding');
if ($element) {
$this->i_press_in_the_app($this->parse_element_locator('"Skip"'));
$this->i_press_in_the_app('"Skip"');
}
// Login screen found.
@ -503,7 +505,7 @@ class behat_app extends behat_base {
global $CFG;
$this->i_set_the_field_in_the_app($this->islegacy ? 'campus.example.edu' : 'Your site', $CFG->wwwroot);
$this->i_press_in_the_app($this->parse_element_locator($this->islegacy ? '"Connect!"' : '"Connect to your site"'));
$this->i_press_in_the_app($this->islegacy ? '"Connect!"' : '"Connect to your site"');
$this->wait_for_pending_js();
}
@ -520,7 +522,7 @@ class behat_app extends behat_base {
// Note there are two 'Log in' texts visible (the title and the button) so we have to use
// a 'near' value here.
$this->i_press_in_the_app($this->parse_element_locator('"Log in" near "Forgotten"'));
$this->i_press_in_the_app('"Log in" near "Forgotten"');
// Wait until the main page appears.
$this->spin(
@ -649,10 +651,11 @@ class behat_app extends behat_base {
* distinguish visible items and the app always has many non-visible items in the DOM.
*
* @Then /^I press (".+") in the app$/
* @param object $locator Element locator
* @param string $locator Element locator
* @throws DriverException If the press doesn't work
*/
public function i_press_in_the_app(object $locator) {
public function i_press_in_the_app(string $locator) {
$locator = $this->parse_element_locator($locator);
$locatorjson = json_encode($locator);
$this->spin(function() use ($locatorjson) {
@ -677,11 +680,12 @@ class behat_app extends behat_base {
*
* @Then /^I (unselect|select) (".+") in the app$/
* @param string $selectedtext
* @param object $locator
* @param string $locator
* @throws DriverException If the press doesn't work
*/
public function i_select_in_the_app(string $selectedtext, object $locator) {
public function i_select_in_the_app(string $selectedtext, string $locator) {
$selected = $selectedtext === 'select' ? 'YES' : 'NO';
$locator = $this->parse_element_locator($locator);
$locatorjson = json_encode($locator);
$this->spin(function() use ($selectedtext, $selected, $locatorjson) {
@ -936,11 +940,10 @@ class behat_app extends behat_base {
/**
* Parse an element locator string.
*
* @Transform /^".+"$/
* @param string $text Element locator string.
* @return object
*/
public function parse_element_locator($text): object {
public function parse_element_locator(string $text): object {
preg_match('/^"((?:[^"]|\\")*?)"(?: "([^"]*?)")?(?: near "((?:[^"]|\\")*?)"(?: "([^"]*?)")?)?$/', $text, $matches);
$locator = [
@ -958,17 +961,6 @@ class behat_app extends behat_base {
return (object) $locator;
}
/**
* Parse a negation string.
*
* @Transform /^not $/
* @param string $not Negation string.
* @return bool
*/
public function parse_negation(string $not): bool {
return !empty($not);
}
/**
* Replaces $WWWROOT for the url of the Moodle site.
*