MDL-70148 qtype: Update qtype steps to new key interaction
authorAndrew Nicols <andrew@nicols.co.uk>
Tue, 23 Jun 2020 03:09:58 +0000 (11:09 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Tue, 17 Nov 2020 07:14:43 +0000 (15:14 +0800)
Note: The ddmarker question type was previously getting the number of
keypresses wrong. This was because it was using both keyDown/keyUp, and
also keyPress. As a result each keypress was essentially happening two
times.

question/type/ddimageortext/tests/behat/behat_qtype_ddimageortext.php
question/type/ddmarker/tests/behat/behat_qtype_ddmarker.php
question/type/ddmarker/tests/behat/preview.feature
question/type/ddwtos/tests/behat/behat_qtype_ddwtos.php

index ced73dc..d2fc17d 100644 (file)
@@ -80,10 +80,10 @@ class behat_qtype_ddimageortext extends behat_base {
     public function i_type_on_place_in_the_drag_and_drop_onto_image_question($keys, $placenumber) {
         $node = $this->get_selected_node('xpath_element', $this->drop_xpath($placenumber));
         $this->ensure_node_is_visible($node);
+
+        $node->focus();
         foreach (str_split($keys) as $key) {
-            $node->keyDown($key);
-            $node->keyPress($key);
-            $node->keyUp($key);
+            behat_base::type_keys($this->getSession(), [$key]);
             $this->wait_for_pending_js();
         }
     }
index 9a74a13..c90480a 100644 (file)
@@ -103,18 +103,11 @@ class behat_qtype_ddmarker extends behat_base {
      * @Given /^I type "(?P<direction>up|down|left|right)" "(?P<repeats>\d+)" times on marker "(?P<marker>[^"]*)" in the drag and drop markers question$/
      */
     public function i_type_on_marker_in_the_drag_and_drop_markers_question($direction, $repeats, $marker) {
-        $keycodes = array(
-            'up'    => chr(38),
-            'down'  => chr(40),
-            'left'  => chr(37),
-            'right' => chr(39),
-        );
         $node = $this->get_selected_node('xpath_element', $this->marker_xpath($marker, true));
         $this->ensure_node_is_visible($node);
+        $node->focus();
         for ($i = 0; $i < $repeats; $i++) {
-            $node->keyDown($keycodes[$direction]);
-            $node->keyPress($keycodes[$direction]);
-            $node->keyUp($keycodes[$direction]);
+            $this->execute('behat_general::i_press_named_key', ['', $direction]);
         }
     }
 }
index 560c688..049dec2 100644 (file)
@@ -50,8 +50,8 @@ Feature: Preview a drag-drop marker question
     # Keep window large else drag will scroll the window to find element.
     And I change window size to "medium"
     And I wait "2" seconds
-    And I type "up" "44" times on marker "Railway station" in the drag and drop markers question
-    And I type "right" "13" times on marker "Railway station" in the drag and drop markers question
+    And I type "up" "88" times on marker "Railway station" in the drag and drop markers question
+    And I type "right" "26" times on marker "Railway station" in the drag and drop markers question
     And I press "Submit and finish"
     Then the state of "Please place the markers on the map of Milton Keynes" question is shown as "Partially correct"
     And I should see "Mark 0.25 out of 1.00"
index f04131d..c15dba0 100644 (file)
@@ -79,10 +79,9 @@ class behat_qtype_ddwtos extends behat_base {
     public function i_type_into_space_in_the_drag_and_drop_into_text_question($keys, $spacenumber) {
         $node = $this->get_selected_node('xpath_element', $this->drop_xpath($spacenumber));
         $this->ensure_node_is_visible($node);
+        $node->focus();
         foreach (str_split($keys) as $key) {
-            $node->keyDown($key);
-            $node->keyPress($key);
-            $node->keyUp($key);
+            behat_base::type_keys($this->getSession(), [$key]);
             $this->wait_for_pending_js();
         }
     }