From 460a0a74c4bf029098fea3e7c16ed0ce9d4ef666 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 16 Aug 2019 11:32:12 +0800 Subject: [PATCH] MDL-66378 behat: JS does not work with newlines in an xpath --- lib/tests/behat/behat_general.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index 81a46a0c5d7..1c37206450c 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -856,8 +856,13 @@ class behat_general extends behat_base { list($preselector, $prelocator) = $this->transform_selector($preselectortype, $preelement); list($postselector, $postlocator) = $this->transform_selector($postselectortype, $postelement); - $prexpath = $this->find($preselector, $prelocator, false, $containernode)->getXpath(); - $postxpath = $this->find($postselector, $postlocator, false, $containernode)->getXpath(); + $newlines = [ + "\r\n", + "\r", + "\n", + ]; + $prexpath = str_replace($newlines, ' ', $this->find($preselector, $prelocator, false, $containernode)->getXpath()); + $postxpath = str_replace($newlines, ' ', $this->find($postselector, $postlocator, false, $containernode)->getXpath()); if ($this->running_javascript()) { // The xpath to do this was running really slowly on certain Chrome versions so we are using