mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-66979 group: Replace direct element interaction with steps
The W3C WebDriver leads to faster operation of individual steps which highlights where WebDriver is moving to a new step faster than the browser can process it. The solution here is to use the `execute` function to interact with the browsers as this makes use of the various wait and check steps.
This commit is contained in:
parent
3489bb1f30
commit
9ccd5030d8
1 changed files with 8 additions and 36 deletions
|
@ -48,48 +48,20 @@ class behat_groups extends behat_base {
|
||||||
* @param string $groupname
|
* @param string $groupname
|
||||||
*/
|
*/
|
||||||
public function i_add_user_to_group_members($userfullname, $groupname) {
|
public function i_add_user_to_group_members($userfullname, $groupname) {
|
||||||
|
// Select the group in the select.
|
||||||
|
$this->execute('behat_forms::i_set_the_field_to', [get_string('groups', 'core'), $this->escape($groupname)]);
|
||||||
|
|
||||||
$userfullname = behat_context_helper::escape($userfullname);
|
// Press "Add/remove users".
|
||||||
|
$this->execute('behat_general::i_click_on', [get_string('adduserstogroup', 'group'), "button"]);
|
||||||
|
|
||||||
// Using a xpath liternal to avoid problems with quotes and double quotes.
|
// Select the user.
|
||||||
$groupname = behat_context_helper::escape($groupname);
|
$this->execute('behat_forms::i_set_the_field_to', ["addselect", $this->escape($userfullname)]);
|
||||||
|
|
||||||
// We don't know the option text as it contains the number of users in the group.
|
|
||||||
$select = $this->find_field('groups');
|
|
||||||
$xpath = "//select[@id='groups']/descendant::option[contains(., $groupname)]";
|
|
||||||
$groupoption = $this->find('xpath', $xpath);
|
|
||||||
$fulloption = $groupoption->getText();
|
|
||||||
$select->selectOption($fulloption);
|
|
||||||
|
|
||||||
// This is needed by some drivers to ensure relevant event is triggred and button is enabled.
|
|
||||||
$driver = $this->getSession()->getDriver();
|
|
||||||
if ($driver instanceof \Moodle\BehatExtension\Driver\MoodleSelenium2Driver) {
|
|
||||||
$script = "Syn.trigger('change', {}, {{ELEMENT}})";
|
|
||||||
$driver->triggerSynScript($select->getXpath(), $script);
|
|
||||||
}
|
|
||||||
$this->getSession()->wait(self::get_timeout() * 1000, self::PAGE_READY_JS);
|
|
||||||
|
|
||||||
// Here we don't need to wait for the AJAX response.
|
|
||||||
$this->find_button(get_string('adduserstogroup', 'group'))->click();
|
|
||||||
|
|
||||||
// Wait for add/remove members page to be loaded.
|
|
||||||
$this->getSession()->wait(self::get_timeout() * 1000, self::PAGE_READY_JS);
|
|
||||||
|
|
||||||
// Getting the option and selecting it.
|
|
||||||
$select = $this->find_field('addselect');
|
|
||||||
$xpath = "//select[@id='addselect']/descendant::option[contains(., $userfullname)]";
|
|
||||||
$memberoption = $this->find('xpath', $xpath);
|
|
||||||
$fulloption = $memberoption->getText();
|
|
||||||
$select->selectOption($fulloption);
|
|
||||||
|
|
||||||
// Click add button.
|
// Click add button.
|
||||||
$this->find_button(get_string('add'))->click();
|
$this->execute('behat_general::i_click_on', [get_string('add', 'core'), "button"]);
|
||||||
|
|
||||||
// Wait for the page to load.
|
|
||||||
$this->getSession()->wait(self::get_timeout() * 1000, self::PAGE_READY_JS);
|
|
||||||
|
|
||||||
// Returning to the main groups page.
|
// Returning to the main groups page.
|
||||||
$this->find_button(get_string('backtogroups', 'group'))->click();
|
$this->execute('behat_general::i_click_on', [get_string('backtogroups', 'group'), "button"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue