From afecc583aabb2224d7abdf4502daa7cb6760b5e9 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 12 Nov 2020 13:17:29 +0800 Subject: [PATCH] MDL-66979 behat: Remove manually triggered events Behat should not trigger Synthetic browser events. It is incorrect to do so as the UI should be used to trigger events correctly. The W3C WebDriver specification explicitly states when and where these events will be triggered from (the browser) and therefore there is no ambiguity and no need to synthetically trigger them from Behat. --- lib/behat/form_field/behat_form_checkbox.php | 19 ------------- lib/behat/form_field/behat_form_select.php | 29 -------------------- 2 files changed, 48 deletions(-) diff --git a/lib/behat/form_field/behat_form_checkbox.php b/lib/behat/form_field/behat_form_checkbox.php index 5cd624aca21..67ba66c30cc 100644 --- a/lib/behat/form_field/behat_form_checkbox.php +++ b/lib/behat/form_field/behat_form_checkbox.php @@ -57,9 +57,6 @@ class behat_form_checkbox extends behat_form_field { // Check it if it should be checked and it is not. $this->field->click(); - // Trigger the onchange event as triggered when 'checking' the checkbox. - $this->trigger_on_change(); - } else if (empty($value) && $this->field->isChecked()) { if (!$this->running_javascript()) { @@ -69,9 +66,6 @@ class behat_form_checkbox extends behat_form_field { // Uncheck if it is checked and shouldn't. $this->field->click(); - - // Trigger the onchange event as triggered when 'checking' the checkbox. - $this->trigger_on_change(); } } @@ -103,17 +97,4 @@ class behat_form_checkbox extends behat_form_field { return false; } - - /** - * Trigger on change event. - */ - protected function trigger_on_change() { - $driver = $this->session->getDriver(); - if ($driver instanceof \Moodle\BehatExtension\Driver\MoodleSelenium2Driver) { - $driver->triggerSynScript( - $this->field->getXPath(), - "Syn.trigger('change', {}, {{ELEMENT}})" - ); - } - } } diff --git a/lib/behat/form_field/behat_form_select.php b/lib/behat/form_field/behat_form_select.php index 071c0d40595..26e646f165c 100644 --- a/lib/behat/form_field/behat_form_select.php +++ b/lib/behat/form_field/behat_form_select.php @@ -67,35 +67,6 @@ class behat_form_select extends behat_form_field { // By default, assume the passed value is a non-multiple option. $this->field->selectOption(trim($value)); } - - // Wait for all the possible AJAX requests that have been - // already triggered by selectOption() to be finished. - if ($this->running_javascript()) { - // Trigger change event and click on first skip link, as some OS/browsers (Phantomjs, Mac-FF), - // don't close select option field and trigger event. - if (!$singleselect) { - $dialoguexpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' moodle-dialogue-focused ')]"; - if (!$node = $this->session->getDriver()->find($dialoguexpath)) { - $script = "Syn.trigger('change', {}, {{ELEMENT}})"; - try { - $driver = $this->session->getDriver(); - if ($driver instanceof \Moodle\BehatExtension\Driver\MoodleSelenium2Driver) { - $driver->triggerSynScript($this->field->getXpath(), $script); - } - $driver->click('//body//div[@class="skiplinks"]'); - } catch (\Exception $e) { - return; - } - } else { - try { - $this->session->getDriver()->click($dialoguexpath); - } catch (\Exception $e) { - return; - } - } - } - $this->session->wait(behat_base::get_timeout() * 1000, behat_base::PAGE_READY_JS); - } } /**