From 370e88d4fe4814f300382c46e014cb4efa3d125b Mon Sep 17 00:00:00 2001 From: David Monllao Date: Mon, 24 Feb 2014 18:14:57 +0800 Subject: [PATCH] MDL-44440 behat: Other fixes to make clean work properly - Update the step to follow links inside a treeview to work also when JS is disabled. - Make regions accept header and footer. - Change some locators refering to non-clean compatible regions. - Restricting click to the table row in forum tracking because seems to conflict with the navigation bar when using narrow window sizes. --- .../behat/tests/behat/basic_actions.feature | 4 ++-- .../tests/behat/manipulate_forms.feature | 3 +-- .../behat/tests/behat/nasty_strings.feature | 3 +-- auth/tests/behat/login.feature | 8 +++---- lib/behat/classes/behat_selectors.php | 2 +- lib/tests/behat/behat_navigation.php | 21 +++++++++++++------ .../tests/behat/track_read_posts.feature | 4 ++-- .../upload/tests/behat/upload_file.feature | 3 +-- 8 files changed, 27 insertions(+), 21 deletions(-) diff --git a/admin/tool/behat/tests/behat/basic_actions.feature b/admin/tool/behat/tests/behat/basic_actions.feature index 4f482dc6cb7..36f28a8a2e5 100644 --- a/admin/tool/behat/tests/behat/basic_actions.feature +++ b/admin/tool/behat/tests/behat/basic_actions.feature @@ -40,7 +40,7 @@ Feature: Page contents assertions And I log in as "admin" And I follow "Course 1" When I dock "Administration" block - Then I should not see "Question bank" in the "region-pre" "region" + Then I should not see "Question bank" in the ".block-region" "css_element" And I click on "//div[@id='dock']/descendant::h2[normalize-space(.)='Administration']" "xpath_element" @javascript @@ -50,4 +50,4 @@ Feature: Page contents assertions | Course 1 | C1 | 0 | And I log in as "admin" When I dock "Administration" block - Then I should not see "Turn editing on" in the "region-pre" "region" + Then I should not see "Turn editing on" in the ".block-region" "css_element" diff --git a/admin/tool/behat/tests/behat/manipulate_forms.feature b/admin/tool/behat/tests/behat/manipulate_forms.feature index ce44fad1f34..c069a79e3f7 100644 --- a/admin/tool/behat/tests/behat/manipulate_forms.feature +++ b/admin/tool/behat/tests/behat/manipulate_forms.feature @@ -7,8 +7,7 @@ Feature: Forms manipulation @javascript Scenario: Basic forms manipulation Given I log in as "admin" - And I follow "Admin User" - And I follow "Edit profile" + And I navigate to "Edit profile" node in "My profile settings" When I set the field "First name" to "Field value" And I set the field "Text editor" to "Plain text area" And I set the field "Unmask" to "1" diff --git a/admin/tool/behat/tests/behat/nasty_strings.feature b/admin/tool/behat/tests/behat/nasty_strings.feature index c67d6cd6c13..cfdd9e763aa 100644 --- a/admin/tool/behat/tests/behat/nasty_strings.feature +++ b/admin/tool/behat/tests/behat/nasty_strings.feature @@ -10,8 +10,7 @@ Feature: Transform steps arguments | fullname | shortname | category | | Course 1 | C1 | 0 | And I log in as "admin" - And I follow "Admin User" - And I follow "Edit profile" + And I navigate to "Edit profile" node in "My profile settings" Scenario: Use nasty strings on steps arguments When I set the field "Surname" to "$NASTYSTRING1" diff --git a/auth/tests/behat/login.feature b/auth/tests/behat/login.feature index eff7f6fb6b4..9ba4537d4c3 100644 --- a/auth/tests/behat/login.feature +++ b/auth/tests/behat/login.feature @@ -6,12 +6,12 @@ Feature: Authentication Scenario: Log in with the predefined admin user with Javascript disabled Given I log in as "admin" - Then I should see "You are logged in as Admin User" + Then I should see "You are logged in as Admin User" in the "page-footer" "region" @javascript Scenario: Log in with the predefined admin user with Javascript enabled Given I log in as "admin" - Then I should see "You are logged in as Admin User" + Then I should see "You are logged in as Admin User" in the "page-footer" "region" Scenario: Log in as an existing admin user filling the form Given the following "users" exists: @@ -22,7 +22,7 @@ Feature: Authentication And I set the field "Username" to "testuser" And I set the field "Password" to "testuser" And I press "Log in" - Then I should see "You are logged in as" + Then I should see "You are logged in as" in the "page-footer" "region" Scenario: Log in as an unexisting user filling the form Given the following "users" exists: @@ -38,4 +38,4 @@ Feature: Authentication Scenario: Log out Given I log in as "admin" When I log out - Then I should see "You are not logged in" + Then I should see "You are not logged in" in the "page-footer" "region" diff --git a/lib/behat/classes/behat_selectors.php b/lib/behat/classes/behat_selectors.php index 48688b077f5..d9d9246f60a 100644 --- a/lib/behat/classes/behat_selectors.php +++ b/lib/behat/classes/behat_selectors.php @@ -89,7 +89,7 @@ XPATH //div[contains(concat(' ', normalize-space(@class), ' '), concat(' ', %locator%, ' '))] | //div[contains(concat(' ', normalize-space(@class), ' '), ' block ')]/descendant::h2[normalize-space(.) = %locator%]/ancestor::div[contains(concat(' ', normalize-space(@class), ' '), ' block ')] XPATH , 'region' => << <<hasClass('collapsed') || ($node->hasAttribute('data-loaded') && $node->getAttribute('data-loaded') == 0)) { $xpath = "/p[contains(concat(' ', normalize-space(@class), ' '), ' tree_item ')]/span"; $nodetoexpand = $node->find('xpath', $xpath); - $this->ensure_node_is_visible($nodetoexpand); - $nodetoexpand->click(); + + if ($this->running_javascript()) { + $this->ensure_node_is_visible($nodetoexpand); + $nodetoexpand->click(); + } } // If sub-parent nodes then get to the last one. @@ -214,8 +217,10 @@ class behat_navigation extends behat_base { $xpath = "/p[contains(concat(' ', normalize-space(@class), ' '), ' tree_item ')]"; if ($node->hasClass('collapsed')) { $nodetoexpand = $node->find('xpath', $xpath); - $this->ensure_node_is_visible($nodetoexpand); - $nodetoexpand->click(); + if ($this->running_javascript()) { + $this->ensure_node_is_visible($nodetoexpand); + $nodetoexpand->click(); + } } } } @@ -227,12 +232,16 @@ class behat_navigation extends behat_base { "/a[normalize-space(.)=" . $nodetextliteral . "]"; $node = $node->find('xpath', $xpath); - // Throw exxeption if no node found. + // Throw exception if no node found. if (!$node) { throw new ExpectationException('Navigation node "' . $nodetext . ' not found under "' . $parentnodes . '" block', $this->getSession()); } - $this->ensure_node_is_visible($node); + + if ($this->running_javascript()) { + $this->ensure_node_is_visible($node); + } + $node->click(); } } diff --git a/mod/forum/tests/behat/track_read_posts.feature b/mod/forum/tests/behat/track_read_posts.feature index da92f8605e3..ad871284e25 100644 --- a/mod/forum/tests/behat/track_read_posts.feature +++ b/mod/forum/tests/behat/track_read_posts.feature @@ -59,7 +59,7 @@ Feature: A teacher can set one of 3 possible options for tracking read forum pos And I follow "Test forum name" And I follow "Track unread posts" And I wait to be redirected - And I follow "1" + And I click on "1" "link" in the "Admin User" "table_row" And I follow "Course 1" And I should not see "1 unread post" @@ -156,7 +156,7 @@ Feature: A teacher can set one of 3 possible options for tracking read forum pos And I follow "Test forum name" And I follow "Track unread posts" And I wait to be redirected - And I follow "1" + And I click on "1" "link" in the "Admin User" "table_row" And I follow "Course 1" And I should not see "1 unread post" diff --git a/repository/upload/tests/behat/upload_file.feature b/repository/upload/tests/behat/upload_file.feature index 4a932635b5f..baf94253c93 100644 --- a/repository/upload/tests/behat/upload_file.feature +++ b/repository/upload/tests/behat/upload_file.feature @@ -10,8 +10,7 @@ Feature: Upload files | fullname | shortname | category | | Course 1 | C1 | 0 | And I log in as "admin" - And I follow "Admin User" - And I follow "My private files" + And I navigate to "My private files" node in "My profile" And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager Then I should see "1" elements in "Files" filemanager And I should see "empty.txt" in the "div.fp-content" "css_element"