From c94a0d1890791a2aa9c5afa38b5a6affd8f2c3c2 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Thu, 28 Mar 2013 18:02:30 +0800 Subject: [PATCH 1/3] MDL-38788 behat: New tests with Javascript disabled Add a block and add an activity/resource tests. The add an activity with JS disabled test includes MDLQA-2446 automation. --- blocks/tests/behat/add_blocks.feature | 10 +++-- course/tests/behat/add_activities.feature | 48 ++++++++++++++--------- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/blocks/tests/behat/add_blocks.feature b/blocks/tests/behat/add_blocks.feature index 7ee5644c176..47caaaaeac8 100644 --- a/blocks/tests/behat/add_blocks.feature +++ b/blocks/tests/behat/add_blocks.feature @@ -4,8 +4,7 @@ Feature: Add blocks As a teacher I need to add blocks to pages - @javascript - Scenario: Add a block to a course + Background: Given the following "users" exists: | username | firstname | lastname | email | | student1 | Student | 1 | student1@asd.com | @@ -21,4 +20,9 @@ Feature: Add blocks And I follow "Course 1" And I turn editing mode on When I add the "Blog menu" block - Then I should see "View all of my entries" + Then I should see "View my entries about this course" + + @javascript + Scenario: Add a block to a course with Javascript enabled + + Scenario: Add a block to a course with Javascript disabled diff --git a/course/tests/behat/add_activities.feature b/course/tests/behat/add_activities.feature index 1c77c4488c7..932bca0d259 100644 --- a/course/tests/behat/add_activities.feature +++ b/course/tests/behat/add_activities.feature @@ -4,8 +4,7 @@ Feature: Add activities to courses As a teacher I need to add activites to a course - @javascript - Scenario: Add an activity to the course + Background: Given the following "users" exists: | username | firstname | lastname | email | | student1 | Student | 1 | student1@asd.com | @@ -19,8 +18,11 @@ Feature: Add activities to courses | student2 | C1 | student | And I log in as "admin" And I follow "Course 1" - When I turn editing mode on - And I add a "Database" to section "3" and I fill the form with: + And I turn editing mode on + + @javascript + Scenario: Add an activity to a course + When I add a "Database" to section "3" and I fill the form with: | Name | Test name | | Description | Test database description | | Required entries | 9 | @@ -35,21 +37,29 @@ Feature: Add activities to courses @javascript Scenario: Add an activity without the required fields - Given the following "users" exists: - | username | firstname | lastname | email | - | student1 | Student | 1 | student1@asd.com | - | student2 | Student | 2 | student2@asd.com | - And the following "courses" exists: - | fullname | shortname | format | - | Course 1 | C1 | topics | - And the following "course enrolments" exists: - | user | course | role | - | student1 | C1 | student | - | student2 | C1 | student | - And I log in as "admin" - And I follow "Course 1" - When I turn editing mode on - And I add a "Database" to section "3" and I fill the form with: + When I add a "Database" to section "3" and I fill the form with: | Name | Test name | Then I should see "Adding a new" And I should see "Required" + + Scenario: Add an activity to a course with Javascript disabled + Then I should see "Add a resource to section 'Topic 1'" + And I should see "Add an activity to section 'Topic 1'" + And I should see "Add a resource to section 'Topic 2'" + And I should see "Add an activity to section 'Topic 2'" + And I should see "Add a resource to section 'Topic 3'" + And I should see "Add an activity to section 'Topic 3'" + And I add a "Label" to section "2" + And I should see "Adding a new Label to Topic 2" + And I fill the moodle form with: + | Label text | I'm a label | + And I press "Save and return to course" + And I add a "Database" to section "3" + And I should see "Adding a new Database to Topic 3" + And I fill the moodle form with: + | Name | Test database name | + | Description | Test database description | + And I press "Save and return to course" + And I should not see "Adding a new" + And I should see "Test database name" + And I should see "I'm a label" From cd7ea8f0ccf59865ee2d73d133f13e6d0456d4f4 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Thu, 28 Mar 2013 18:03:27 +0800 Subject: [PATCH 2/3] MDL-38788 behat: Generic form elements interaction compatibile with JS disabled --- lib/tests/behat/behat_forms.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/tests/behat/behat_forms.php b/lib/tests/behat/behat_forms.php index fd82d95bbb8..b40cdb02d82 100644 --- a/lib/tests/behat/behat_forms.php +++ b/lib/tests/behat/behat_forms.php @@ -176,7 +176,9 @@ class behat_forms extends behat_base { $selectnode->selectOption($option); // Adding a click as Selenium requires it to fire some JS events. - $selectnode->click(); + if ($this->running_javascript()) { + $selectnode->click(); + } } /** @@ -192,7 +194,9 @@ class behat_forms extends behat_base { $radionode->check(); // Adding a click as Selenium requires it to fire some JS events. - $radionode->click(); + if ($this->running_javascript()) { + $radionode->click(); + } } /** From 1c00d6f636f9128c8c667d71d584925366edb2ec Mon Sep 17 00:00:00 2001 From: David Monllao Date: Thu, 28 Mar 2013 18:05:05 +0800 Subject: [PATCH 3/3] MDL-38788 behat: Add a block and add an activity steps definitions compatible with JS disabled --- blocks/tests/behat/behat_blocks.php | 11 ++++++++- course/tests/behat/behat_course.php | 36 ++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/blocks/tests/behat/behat_blocks.php b/blocks/tests/behat/behat_blocks.php index c90f1df87b3..1c8f70d9aa1 100644 --- a/blocks/tests/behat/behat_blocks.php +++ b/blocks/tests/behat/behat_blocks.php @@ -46,7 +46,16 @@ class behat_blocks extends behat_base { * @param string $blockname */ public function i_add_the_block($blockname) { - return new Given('I select "' . $blockname . '" from "bui_addblock"'); + $steps = new Given('I select "' . $blockname . '" from "bui_addblock"'); + + // If we are running without javascript we need to submit the form. + if (!$this->running_javascript()) { + $steps = array( + $steps, + new Given('I click on "Go" "button" in the "#add_block" "css_element"') + ); + } + return $steps; } } diff --git a/course/tests/behat/behat_course.php b/course/tests/behat/behat_course.php index 0f1e0ca0e0b..51dae371df0 100644 --- a/course/tests/behat/behat_course.php +++ b/course/tests/behat/behat_course.php @@ -83,15 +83,35 @@ class behat_course extends behat_base { */ public function i_add_to_section($activity, $section) { - // Clicks add activity or resource section link. - $sectionxpath = "//*[@id='section-" . $section . "']/*/*/*/div[@class='section-modchooser']/span/a"; - $sectionnode = $this->find('xpath', $sectionxpath); - $sectionnode->click(); + $sectionxpath = "//*[@id='section-" . $section . "']"; + + if ($this->running_javascript()) { + + // Clicks add activity or resource section link. + $sectionxpath = $sectionxpath . "/descendant::div[@class='section-modchooser']/span/a"; + $sectionnode = $this->find('xpath', $sectionxpath); + $sectionnode->click(); + + // Clicks the selected activity if it exists. + $activityxpath = ".//label[contains(.,'" . $activity . "')]/input"; + $activitynode = $this->find('xpath', $activityxpath); + $activitynode->doubleClick(); + + } else { + // 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 . "')]"; + $selectnode = $this->find('xpath', $selectxpath); + $selectnode->selectOption($activity); + + // Go button. + $gobuttonxpath = $selectxpath . "/ancestor::form/descendant::input[@type='submit']"; + $gobutton = $this->find('xpath', $gobuttonxpath); + $gobutton->click(); + } - // Clicks the selected activity if it exists. - $activityxpath = ".//label[contains(.,'" . $activity . "')]/input"; - $activitynode = $this->find('xpath', $activityxpath); - $activitynode->doubleClick(); } }