From 48f0f973eb26d96416cf0975d15e34969d02ab14 Mon Sep 17 00:00:00 2001
From: Damyon Wiese <damyon@moodle.com>
Date: Tue, 29 Apr 2014 16:23:31 +0800
Subject: [PATCH] MDL-45231 Behat: fixes for chromedriver and safari

Call focus on a node before clicking on it to make sure it's scrolled into view.
---
 lib/behat/behat_base.php        | 5 +++++
 lib/tests/behat/behat_forms.php | 1 +
 2 files changed, 6 insertions(+)

diff --git a/lib/behat/behat_base.php b/lib/behat/behat_base.php
index 8c60cec..0e58037 100644
--- a/lib/behat/behat_base.php
+++ b/lib/behat/behat_base.php
@@ -536,6 +536,11 @@ class behat_base extends Behat\MinkExtension\Context\RawMinkContext {
         // Exception if it timesout and the element is still there.
         $msg = 'The "' . $node->getXPath() . '" xpath node is not visible and it should be visible';
         $exception = new ExpectationException($msg, $this->getSession());
+        try {
+            $node->focus();
+        } catch (Exception $e) {
+            // ignore
+        }
 
         // It will stop spinning once the isVisible() method returns true.
         $this->spin(
diff --git a/lib/tests/behat/behat_forms.php b/lib/tests/behat/behat_forms.php
index b686efb..a1b5d91 100644
--- a/lib/tests/behat/behat_forms.php
+++ b/lib/tests/behat/behat_forms.php
@@ -57,6 +57,7 @@ class behat_forms extends behat_base {
 
         // Ensures the button is present.
         $buttonnode = $this->find_button($button);
+        $this->ensure_node_is_visible($buttonnode);
         $buttonnode->press();
     }
 
-- 
1.8.3.2

