Skip to content

Commit

Permalink
MDL-42625 behat: Step definitions + related changes in features
Browse files Browse the repository at this point in the history
In general aiming for compatibility with multiple browsers,
firefox, chrome and phantomjs to be more specific.

* Removing hardcoded waits
* Adding @_alert, @_switch_window and @_switch_frame tags,
  to label actions that different drivers have problems with.
* Adding missing @_files_upload and @_only_local tags to features that
  uploads files.
* Fixing a few wait for page ready what specified miliseconds.
* New methods to ensure elements (usual selectors), sections and editors
  are ready to interact with
* Changing the select an option implementation to deal with the different
  drivers implementations when listening to JS events.
  • Loading branch information
David Monllao committed Dec 6, 2013
1 parent 333db2e commit d1e55a4
Show file tree
Hide file tree
Showing 31 changed files with 670 additions and 241 deletions.
4 changes: 2 additions & 2 deletions admin/tests/behat/behat_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function i_set_the_following_administration_settings_values(TableNode $ta
// We expect admin block to be visible, otherwise go to homepage.
if (!$this->getSession()->getPage()->find('css', '.block_settings')) {
$this->getSession()->visit($this->locate_path('/'));
$this->wait(self::TIMEOUT, '(document.readyState === "complete")');
$this->wait(self::TIMEOUT * 1000, self::PAGE_READY_JS);
}

// Search by label.
Expand All @@ -68,7 +68,7 @@ public function i_set_the_following_administration_settings_values(TableNode $ta
$submitsearch = $this->find('css', 'form.adminsearchform input[type=submit]');
$submitsearch->press();

$this->wait(self::TIMEOUT, '(document.readyState === "complete")');
$this->wait(self::TIMEOUT * 1000, self::PAGE_READY_JS);

// 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.
Expand Down
12 changes: 4 additions & 8 deletions backup/util/ui/tests/behat/behat_backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function i_backup_course_using_this_options($backupcourse, $options = fal
$this->find_button(get_string('backupstage4action', 'backup'))->press();

// Waiting for it to finish.
$this->wait(10);
$this->wait();

// Last backup continue button.
$this->find_button(get_string('backupstage16action', 'backup'))->press();
Expand Down Expand Up @@ -301,7 +301,7 @@ protected function process_restore($options) {

// Review, no options here.
$this->find_button(get_string('restorestage16action', 'backup'))->press();
$this->wait(10);
$this->wait();

// Last restore continue button, redirected to restore course after this.
$this->find_button(get_string('restorestage32action', 'backup'))->press();
Expand Down Expand Up @@ -343,19 +343,15 @@ protected function fill_backup_restore_form($options) {
/**
* Waits until the DOM is ready.
*
* @param int To override the default timeout
* @return void
*/
protected function wait($timeout = false) {
protected function wait() {

if (!$this->running_javascript()) {
return;
}

if (!$timeout) {
$timeout = self::TIMEOUT;
}
$this->getSession()->wait($timeout, '(document.readyState === "complete")');
$this->getSession()->wait(self::TIMEOUT * 1000, self::PAGE_READY_JS);
}

}
4 changes: 2 additions & 2 deletions backup/util/ui/tests/behat/duplicate_activities.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Feature: Duplicate activities
And I add a "Database" to section "1" and I fill the form with:
| Name | Test database name |
| Description | Test database description |
And I open "Test database name" actions menu
When I click on "Duplicate" "link" in the "Test database name" activity
And I duplicate "Test database name" activity
And I wait until section "1" is available
And I open "Test database name" actions menu
And I click on "Edit settings" "link" in the "Test database name" activity
And I fill the moodle form with:
Expand Down
12 changes: 3 additions & 9 deletions badges/tests/behat/award_badge.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ Feature: Award badges
As an admin
I need to add criteria to badges in the system

Background:
Given I am on homepage
And I log in as "admin"

@javascript
Scenario: Award profile badge
Given I expand "Site administration" node
Given I log in as "admin"
And I expand "Site administration" node
And I expand "Badges" node
And I follow "Add a new badge"
And I fill the moodle form with:
Expand Down Expand Up @@ -46,6 +43,7 @@ Feature: Award badges
| username | firstname | lastname | email |
| teacher | teacher | 1 | teacher1@asd.com |
| student | student | 1 | student1@asd.com |
And I log in as "admin"
And I expand "Site administration" node
And I expand "Badges" node
And I follow "Add a new badge"
Expand Down Expand Up @@ -89,7 +87,6 @@ Feature: Award badges
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
| student2 | C1 | student |
And I log out
And I log in as "teacher1"
And I follow "Course 1"
And I click on "//span[text()='Badges']" "xpath_element" in the "Administration" "block"
Expand Down Expand Up @@ -133,7 +130,6 @@ Feature: Award badges
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And I log out
And I log in as "admin"
And I set the following administration settings values:
| Enable completion tracking | 1 |
Expand Down Expand Up @@ -172,7 +168,6 @@ Feature: Award badges
And I follow "Home"
And I follow "Course 1"
And I press "Mark as complete: Test assignment name"
And I wait "2" seconds
And I expand "My profile" node
And I follow "My badges"
Then I should see "Course Badge"
Expand All @@ -190,7 +185,6 @@ Feature: Award badges
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And I log out
And I log in as "admin"
And I set the following administration settings values:
| Enable completion tracking | 1 |
Expand Down
5 changes: 1 addition & 4 deletions blocks/comments/tests/behat/behat_block_comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ public function i_add_comment_to_comments_block($comment) {

$this->find_link(get_string('savecomment'))->click();

// Wait for the AJAX request.
$this->getSession()->wait(4 * 1000, false);

} else {

$commentstextarea = $this->find('css', '.block_comments form textarea', $exception);
Expand Down Expand Up @@ -103,7 +100,7 @@ public function i_delete_comment_from_comments_block($comment) {
$deleteicon = $this->find('css', '.comment-delete a img', $deleteexception, $commentnode);
$deleteicon->click();

// Wait for the AJAX request.
// Wait for the animation to finish, in theory is just 1 sec, adding 4 just in case.
$this->getSession()->wait(4 * 1000, false);
}

Expand Down
2 changes: 1 addition & 1 deletion blog/tests/behat/comment.feature
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Feature: Comment on a blog entry
And I follow "Save comment"
When I click on ".comment-delete a" "css_element"
# Waiting for the animation to finish.
And I wait "2" seconds
And I wait "4" seconds
Then I should not see "$My own >nasty< \"string\"!"
And I follow "Blog post from user 1"
And I click on ".comment-link" "css_element"
Expand Down
18 changes: 8 additions & 10 deletions completion/tests/behat/restrict_activity_by_date.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ Feature: Restrict activity availability through date conditions
And I set the following administration settings values:
| Enable conditional access | 1 |
And I log out

@javascript
Scenario: Show activity greyed-out to students when available from date is in future
Given I log in as "teacher1"
And I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
# Adding the page like this because id_available*_enabled needs to be clicked to trigger the action.
And I add a "Assignment" to section "1"
And I expand all fieldsets

@javascript
Scenario: Show activity greyed-out to students when available from date is in future
Given I click on "id_availablefrom_enabled" "checkbox"
And I fill the moodle form with:
| Assignment name | Test assignment 1 |
| Description | This assignment is restricted by date |
Expand All @@ -36,7 +39,6 @@ Feature: Restrict activity availability through date conditions
| id_availablefrom_month | 12 |
| id_availablefrom_year | 2050 |
| id_showavailability | 1 |
And I click on "id_availablefrom_enabled" "checkbox"
And I press "Save and return to course"
And I log out
When I log in as "student1"
Expand All @@ -47,10 +49,7 @@ Feature: Restrict activity availability through date conditions

@javascript
Scenario: Show activity hidden to students when available until date is in past
Given I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "2"
Given I click on "id_availableuntil_enabled" "checkbox"
And I fill the moodle form with:
| Assignment name | Test assignment 2 |
| Description | This assignment is restricted by date |
Expand All @@ -60,7 +59,6 @@ Feature: Restrict activity availability through date conditions
| id_availableuntil_month | 2 |
| id_availableuntil_year | 2013 |
| id_showavailability | 0 |
And I click on "id_availableuntil_enabled" "checkbox"
And I press "Save and return to course"
And I log out
When I log in as "student1"
Expand Down
7 changes: 6 additions & 1 deletion completion/tests/behat/restrict_activity_by_grade.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ Feature: Restrict activity availability through grade conditions
| Description | Grade this assignment to revoke restriction on restricted assignment |
| assignsubmission_onlinetext_enabled | 1 |
| assignsubmission_file_enabled | 0 |
And I add a "Page" to section "2" and I fill the form with:
# Adding the page like this because id_availableform_enabled needs to be clicked to trigger the action.
And I add a "Page" to section "2"
And I expand all fieldsets
And I click on "id_availablefrom_enabled" "checkbox"
And I fill the moodle form with:
| Name | Test page name |
| Description | Restricted page, till grades in Grade assignment is at least 20% |
| Page content | Test page contents |
| id_conditiongradegroup_0_conditiongradeitemid | 2 |
| id_conditiongradegroup_0_conditiongrademin | 20 |
| id_showavailability | 1 |
And I press "Save and return to course"
And I log out
When I log in as "student1"
And I follow "Course 1"
Expand Down
2 changes: 2 additions & 0 deletions course/tests/behat/add_activities.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ Feature: Add activities to courses
Scenario: Add an activity without the required fields
When I add a "Database" to section "3" and I fill the form with:
| Name | Test name |
And I press "Save and return to course"
Then I should see "Adding a new"
And I should see "Required"
And I press "Cancel"

Scenario: Add an activity to a course with Javascript disabled
Then I should see "Add a resource to section 'Topic 1'"
Expand Down
Loading

0 comments on commit d1e55a4

Please sign in to comment.