MDL-66979 behat: Update passwordunmask form field control

Update the passwordunmask form field type for behat to interact with the
form element as a human would rather than via synthetic event triggers.
This commit is contained in:
Andrew Nicols 2020-06-26 13:18:17 +08:00
parent 2a969d891a
commit fd5621554a

View File

@ -48,28 +48,21 @@ class behat_form_passwordunmask extends behat_form_text {
* @return void
*/
public function set_value($value) {
if ($this->running_javascript()) {
$id = $this->field->getAttribute('id');
$js = <<<JS
(function() {
require(["jquery"], function($) {
var wrapper = $(document.getElementById("{$id}")).closest('[data-passwordunmask="wrapper"]');
wrapper.find('[data-passwordunmask="edit"]').trigger("click");
});
})();
JS;
behat_base::execute_script_in_session($this->session, $js);
if (!$this->running_javascript()) {
$this->field->setValue($value);
return;
}
$this->field->setValue($value);
$id = $this->field->getAttribute('id');
$wrapper = $this->field->getParent()->getParent()->find('css', '[data-passwordunmask="wrapper"]');
$wrapper->click();
$this->wait_for_pending_js();
// Ensure all pending JS is finished.
if ($this->running_javascript()) {
// Press enter key after setting password, so we have a stable page.
$this->field->keyDown(13);
$this->field->keyPress(13);
$this->field->keyUp(13);
$this->session->wait(behat_base::get_timeout() * 1000, behat_base::PAGE_READY_JS);
}
behat_base::type_keys($this->session, str_split($value));
$this->wait_for_pending_js();
// Press enter key after setting password to save.
behat_base::type_keys($this->session, [behat_keys::ENTER]);
}
}