MDL-56994 behat: Fixed activity selector to find proper li
authorRajesh Taneja <rajesh@moodle.com>
Tue, 22 Nov 2016 03:02:52 +0000 (11:02 +0800)
committerRajesh Taneja <rajesh@moodle.com>
Tue, 22 Nov 2016 03:02:52 +0000 (11:02 +0800)
Previous to this patch, only 1 activity was
expected and if there are more than 1 activities
then it will fail. Improved step to find the
correct activity node by name

completion/tests/behat/behat_completion.php

index 8a0925e..5d80be0 100644 (file)
@@ -124,11 +124,12 @@ class behat_completion extends behat_base {
         } else {
             $imgalttext = get_string("completion-alt-auto-y", 'core_completion', $activityname);
         }
-        $csselementforactivitytype = "li.modtype_".strtolower($activitytype);
+        $activityxpath = "//li[contains(concat(' ', @class, ' '), ' modtype_" . strtolower($activitytype) . " ')]";
+        $activityxpath .= "[descendant::*[contains(text(), '" . $activityname . "')]]";
 
         $xpathtocheck = "//img[contains(@alt, '$imgalttext')]";
         $this->execute("behat_general::should_exist_in_the",
-            array($xpathtocheck, "xpath_element", $csselementforactivitytype, "css_element")
+            array($xpathtocheck, "xpath_element", $activityxpath, "xpath_element")
         );
 
     }
@@ -144,12 +145,12 @@ class behat_completion extends behat_base {
         } else {
             $imgalttext = get_string("completion-alt-auto-n", 'core_completion', $activityname);
         }
-        $csselementforactivitytype = "li.modtype_".strtolower($activitytype);
+        $activityxpath = "//li[contains(concat(' ', @class, ' '), ' modtype_" . strtolower($activitytype) . " ')]";
+        $activityxpath .= "[descendant::*[contains(text(), '" . $activityname . "')]]";
 
         $xpathtocheck = "//img[contains(@alt, '$imgalttext')]";
         $this->execute("behat_general::should_exist_in_the",
-            array($xpathtocheck, "xpath_element", $csselementforactivitytype, "css_element")
+            array($xpathtocheck, "xpath_element", $activityxpath, "xpath_element")
         );
-
     }
 }