MDL-39348 behat: Chaining strings instead of splitting strings in lines

This commit is contained in:
David Monllao
2013-05-03 10:16:44 +08:00
parent 4d40089d88
commit 00ea74cb54
9 changed files with 59 additions and 52 deletions
+4 -4
View File
@@ -72,11 +72,11 @@ class behat_admin extends behat_base {
// Admin settings does not use the same DOM structure than other moodle forms
// but we also need to use lib/behat/form_field/* to deal with the different moodle form elements.
$exception = new ElementNotFoundException($this->getSession(), '"' . $label . '" administration setting ');
$fieldxpath = "//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]
[@id=//label[contains(normalize-space(string(.)), '" . $label . "')]/@for]";
$fieldxpath = "//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]" .
"[@id=//label[contains(normalize-space(string(.)), '" . $label . "')]/@for]";
$fieldnode = $this->find('xpath', $fieldxpath, $exception);
$formfieldtypenode = $this->find('xpath', $fieldxpath . "/ancestor::div[@class='form-setting']
/child::div[contains(concat(' ', @class, ' '), ' form-')]/child::*/parent::div");
$formfieldtypenode = $this->find('xpath', $fieldxpath . "/ancestor::div[@class='form-setting']" .
"/child::div[contains(concat(' ', @class, ' '), ' form-')]/child::*/parent::div");
// Getting the class which contains the field type.
$classes = explode(' ', $formfieldtypenode->getAttribute('class'));
+18 -16
View File
@@ -112,9 +112,9 @@ class behat_backup extends behat_base {
$exception = new ExpectationException('"' . $fromcourse . '" course not found in the list of courses to import from', $this->getSession());
$fromcourse = str_replace("'", "\'", $fromcourse);
$xpath = "//div[contains(concat(' ', @class, ' '), ' ics-results ')]
/descendant::tr[contains(., '" . $fromcourse . "')]
/descendant::input[@type='radio']";
$xpath = "//div[contains(concat(' ', @class, ' '), ' ics-results ')]" .
"/descendant::tr[contains(., '" . $fromcourse . "')]" .
"/descendant::input[@type='radio']";
$radionode = $this->find('xpath', $xpath, $exception);
$radionode->check();
$radionode->click();
@@ -152,10 +152,10 @@ class behat_backup extends behat_base {
// Selecting the specified course (we can not call behat_forms::select_radio here as is in another behat subcontext).
$existingcourse = str_replace("'", "\'", $existingcourse);
$radionode = $this->find('xpath', "//div[contains(@class, 'bcs-existing-course')]
/descendant::div[@class='restore-course-search']
/descendant::tr[contains(., '" . $existingcourse . "')]
/descendant::input[@type='radio']");
$radionode = $this->find('xpath', "//div[contains(@class, 'bcs-existing-course')]" .
"/descendant::div[@class='restore-course-search']" .
"/descendant::tr[contains(., '" . $existingcourse . "')]" .
"/descendant::input[@type='radio']");
$radionode->check();
$radionode->click();
@@ -181,9 +181,9 @@ class behat_backup extends behat_base {
$this->select_backup($backupfilename);
// The first category in the list.
$radionode = $this->find('xpath', "//div[contains(@class, 'bcs-new-course')]
/descendant::div[@class='restore-course-search']
/descendant::input[@type='radio']");
$radionode = $this->find('xpath', "//div[contains(@class, 'bcs-new-course')]" .
"/descendant::div[@class='restore-course-search']" .
"/descendant::input[@type='radio']");
$radionode->check();
$radionode->click();
@@ -209,13 +209,14 @@ class behat_backup extends behat_base {
$this->select_backup($backupfilename);
// Merge without deleting radio option.
$radionode = $this->find('xpath', "//div[contains(@class, 'bcs-current-course')]
/descendant::input[@type='radio'][@name='target'][@value='1']");
$radionode = $this->find('xpath', "//div[contains(@class, 'bcs-current-course')]" .
"/descendant::input[@type='radio'][@name='target'][@value='1']");
$radionode->check();
$radionode->click();
// Pressing the continue button of the restore merging section.
$continuenode = $this->find('xpath', "//div[contains(@class, 'bcs-current-course')]/descendant::input[@type='submit'][@value='Continue']");
$continuenode = $this->find('xpath', "//div[contains(@class, 'bcs-current-course')]" .
"/descendant::input[@type='submit'][@value='Continue']");
$continuenode->click();
$this->wait();
@@ -236,13 +237,14 @@ class behat_backup extends behat_base {
$this->select_backup($backupfilename);
// Delete contents radio option.
$radionode = $this->find('xpath', "//div[contains(@class, 'bcs-current-course')]
/descendant::input[@type='radio'][@name='target'][@value='0']");
$radionode = $this->find('xpath', "//div[contains(@class, 'bcs-current-course')]" .
"/descendant::input[@type='radio'][@name='target'][@value='0']");
$radionode->check();
$radionode->click();
// Pressing the continue button of the restore merging section.
$continuenode = $this->find('xpath', "//div[contains(@class, 'bcs-current-course')]/descendant::input[@type='submit'][@value='Continue']");
$continuenode = $this->find('xpath', "//div[contains(@class, 'bcs-current-course')]" .
"/descendant::input[@type='submit'][@value='Continue']");
$continuenode->click();
$this->wait();
@@ -91,8 +91,8 @@ class behat_block_comments extends behat_base {
$exception = new ElementNotFoundException($this->getSession(), '"' . $comment . '" comment ');
$commentxpath = "//div[contains(concat(' ', @class, ' '), ' block_comments ')]
/descendant::div[@class='comment-message'][contains(., '" . $comment . "')]";
$commentxpath = "//div[contains(concat(' ', @class, ' '), ' block_comments ')]" .
"/descendant::div[@class='comment-message'][contains(., '" . $comment . "')]";
$commentnode = $this->find('xpath', $commentxpath, $exception);
// Click on delete icon.
+8 -3
View File
@@ -50,7 +50,8 @@ class behat_completion extends behat_base {
public function user_has_completed_activity($userfullname, $activityname) {
// Will throw an exception if the element can not be hovered.
$xpath = "//table[@id='completion-progress']/descendant::img[contains(@title, '" . $userfullname . ", " . $activityname . ": Completed')]";
$xpath = "//table[@id='completion-progress']" .
"/descendant::img[contains(@title, '" . $userfullname . ", " . $activityname . ": Completed')]";
return array(
new Given('I go to the current course activity completion report'),
@@ -67,7 +68,8 @@ class behat_completion extends behat_base {
*/
public function user_has_not_completed_activity($userfullname, $activityname) {
$xpath = "//table[@id='completion-progress']/descendant::img[contains(@title, '" . $userfullname . ", " . $activityname . ": Not completed')]";
$xpath = "//table[@id='completion-progress']" .
"/descendant::img[contains(@title, '" . $userfullname . ", " . $activityname . ": Not completed')]";
return array(
new Given('I go to the current course activity completion report'),
new Given('I hover "' . $xpath . '" "xpath_element"')
@@ -87,7 +89,10 @@ class behat_completion extends behat_base {
// Expand reports node if we can't see the link.
try {
$this->find('xpath', "//*[@id='settingsnav']/descendant::li/descendant::li[not(contains(@class,'collapsed'))]/descendant::p[contains(., 'Activity completion')]");
$this->find('xpath', "//*[@id='settingsnav']" .
"/descendant::li" .
"/descendant::li[not(contains(@class,'collapsed'))]" .
"/descendant::p[contains(., 'Activity completion')]");
} catch (ElementNotFoundException $e) {
$steps[] = new Given('I expand "Reports" node');
}
+7 -7
View File
@@ -126,9 +126,9 @@ class behat_course extends behat_base {
// Clicks the selected activity if it exists.
$activity = ucfirst($activity);
$activityxpath = "//div[@id='chooseform']/descendant::label
/descendant::span[contains(concat(' ', @class, ' '), ' typename ')][contains(.,'" . $activity . "')]
/parent::label/child::input";
$activityxpath = "//div[@id='chooseform']/descendant::label" .
"/descendant::span[contains(concat(' ', @class, ' '), ' typename ')][contains(.,'" . $activity . "')]" .
"/parent::label/child::input";
$activitynode = $this->find('xpath', $activityxpath);
$activitynode->doubleClick();
@@ -136,8 +136,8 @@ class behat_course extends behat_base {
// Without Javascript.
// Selecting the option from the select box which contains the option.
$selectxpath = $sectionxpath . "/descendant::div[contains(concat(' ', @class, ' '), ' section_add_menus ')]
/descendant::select[contains(., '" . $activity . "')]";
$selectxpath = $sectionxpath . "/descendant::div[contains(concat(' ', @class, ' '), ' section_add_menus ')]" .
"/descendant::select[contains(., '" . $activity . "')]";
$selectnode = $this->find('xpath', $selectxpath);
$selectnode->selectOption($activity);
@@ -279,8 +279,8 @@ class behat_course extends behat_base {
foreach ($activities as $activity) {
// Dimmed.
$this->find('xpath', "//div[contains(concat(' ', @class, ' '), ' activityinstance ')]
/a[contains(concat(' ', @class, ' '), ' dimmed ')]", $dimmedexception, $activity);
$this->find('xpath', "//div[contains(concat(' ', @class, ' '), ' activityinstance ')]" .
"/a[contains(concat(' ', @class, ' '), ' dimmed ')]", $dimmedexception, $activity);
// To check that the visibility is not clickable we check the funcionality rather than the applied style.
$visibilityiconnode = $this->find('css', 'a.editing_show img', false, $activity);
+2 -1
View File
@@ -132,7 +132,8 @@ class behat_forms extends behat_base {
// Show all fields.
$showmorestr = get_string('showmore', 'form');
$showmores = $this->find_all('xpath', "//a[contains(concat(' ', normalize-space(.), ' '), '" . $showmorestr . "')][contains(concat(' ', normalize-space(@class), ' '), ' moreless-toggler')]");
$showmores = $this->find_all('xpath', "//a[contains(concat(' ', normalize-space(.), ' '), '" . $showmorestr . "')]" .
"[contains(concat(' ', normalize-space(@class), ' '), ' moreless-toggler')]");
// We are supposed to have 'show more's here, otherwise exception.
+10 -11
View File
@@ -53,17 +53,16 @@ class behat_navigation extends behat_base {
return false;
}
$xpath = "//ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]
/child::li
/child::p[contains(concat(' ', normalize-space(@class), ' '), ' branch')]
/child::span[contains(concat(' ', normalize-space(.), ' '), '" . $nodetext . "')]
|
//ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]
/descendant::li[not(contains(concat(' ', normalize-space(@class), ' '), ' collapsed'))]
/descendant::li
/child::p[contains(concat(' ', normalize-space(@class), ' '), ' branch')]
/child::span[contains(concat(' ', normalize-space(.), ' '), '" . $nodetext . "')]
";
$xpath = "//ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" .
"/child::li" .
"/child::p[contains(concat(' ', normalize-space(@class), ' '), ' branch')]" .
"/child::span[contains(concat(' ', normalize-space(.), ' '), '" . $nodetext . "')]" .
"|" .
"//ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" .
"/descendant::li[not(contains(concat(' ', normalize-space(@class), ' '), ' collapsed'))]" .
"/descendant::li" .
"/child::p[contains(concat(' ', normalize-space(@class), ' '), ' branch')]" .
"/child::span[contains(concat(' ', normalize-space(.), ' '), '" . $nodetext . "')]";
$node = $this->find('xpath', $xpath);
$node->click();
+4 -4
View File
@@ -51,8 +51,8 @@ class behat_question extends behat_base {
*/
public function i_add_a_question_filling_the_form_with($questiontypename, TableNode $questiondata) {
$questiontypexpath = "//span[@class='qtypename'][.='" . $questiontypename . "']
/ancestor::div[@class='qtypeoption']/descendant::input";
$questiontypexpath = "//span[@class='qtypename'][.='" . $questiontypename . "']" .
"/ancestor::div[@class='qtypeoption']/descendant::input";
return array(
new Given('I follow "' . get_string('questionbank', 'question') . '"'),
@@ -81,8 +81,8 @@ class behat_question extends behat_base {
$this->find('xpath', $questionxpath, $exception);
$exception = new ExpectationException('Question "' . $questiondescription . '" state is not "' . $state . '"', $this->getSession());
$xpath = $questionxpath . "/ancestor::div[contains(concat(' ', @class, ' '), ' que ')]
/descendant::div[@class='state'][contains(., '" . $state . "')]";
$xpath = $questionxpath . "/ancestor::div[contains(concat(' ', @class, ' '), ' que ')]" .
"/descendant::div[@class='state'][contains(., '" . $state . "')]";
$this->find('xpath', $xpath, $exception);
}
+4 -4
View File
@@ -92,8 +92,8 @@ class behat_filepicker extends behat_files {
// In the current folder workspace.
$folder = $this->find(
'xpath',
"//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-folder ')]
//descendant::div[contains(concat(' ', normalize-space(.), ' '), '" . $foldername . "')]",
"//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-folder ')]" .
"//descendant::div[contains(concat(' ', normalize-space(.), ' '), '" . $foldername . "')]",
$exception,
$fieldnode
);
@@ -102,8 +102,8 @@ class behat_filepicker extends behat_files {
// And in the pathbar.
$folder = $this->find(
'xpath',
"//a[contains(concat(' ', normalize-space(@class), ' '), ' fp-path-folder-name ')]
[contains(concat(' ', normalize-space(.), ' '), '" . $foldername . "')]",
"//a[contains(concat(' ', normalize-space(@class), ' '), ' fp-path-folder-name ')]" .
"[contains(concat(' ', normalize-space(.), ' '), '" . $foldername . "')]",
$exception,
$fieldnode
);