From d1e52f70862e7252cd202435ebd288bc767c21bf Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 26 Jun 2020 13:18:17 +0800 Subject: [PATCH] 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. --- .../form_field/behat_form_passwordunmask.php | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/lib/behat/form_field/behat_form_passwordunmask.php b/lib/behat/form_field/behat_form_passwordunmask.php index cfc48c26c74..91840fdfdce 100644 --- a/lib/behat/form_field/behat_form_passwordunmask.php +++ b/lib/behat/form_field/behat_form_passwordunmask.php @@ -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 = <<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]); } }