Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-40246 mod_forum: Changing scenario to non-JS

Also replacing hardcoded waits for a
wait to be redirected.
  • Loading branch information...
commit ff46f989982954b1653a8677101f4f08bbceede3 1 parent e978b66
David Monllaó dmonllao authored
55 lib/tests/behat/behat_general.php
@@ -28,7 +28,8 @@
28 28 require_once(__DIR__ . '/../../behat/behat_base.php');
29 29
30 30 use Behat\Mink\Exception\ExpectationException as ExpectationException,
31   - Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
  31 + Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException,
  32 + Behat\Mink\Exception\DriverException as DriverException;
32 33
33 34 /**
34 35 * Cross component steps definitions.
@@ -64,6 +65,48 @@ public function reload() {
64 65 }
65 66
66 67 /**
  68 + * Follows the page redirection. Use this step after any action that shows a message and waits for a redirection
  69 + *
  70 + * @Given /^I wait to be redirected$/
  71 + */
  72 + public function i_wait_to_be_redirected() {
  73 +
  74 + // Xpath and processes based on core_renderer::redirect_message(), core_renderer::$metarefreshtag and
  75 + // moodle_page::$periodicrefreshdelay possible values.
  76 + if (!$metarefresh = $this->getSession()->getPage()->find('xpath', "//head/descendant::meta[@http-equiv='refresh']")) {
  77 + // We don't fail the scenario if no redirection with message is found to avoid race condition false failures.
  78 + return false;
  79 + }
  80 +
  81 + $content = $metarefresh->getAttribute('content');
  82 + if (strstr($content, 'url') != false) {
  83 +
  84 + list($waittime, $url) = explode(';', $metarefresh->getAttribute('content'));
  85 +
  86 + // Cleaning the URL value.
  87 + $url = trim(substr($url, strpos($url, 'http')));
  88 +
  89 + } else {
  90 + // Just wait then.
  91 + $waittime = $content;
  92 + }
  93 +
  94 +
  95 + // Wait until the URL change is executed.
  96 + if ($this->running_javascript()) {
  97 + $this->getSession()->wait($waittime * 1000, false);
  98 +
  99 + } else if (!empty($url)) {
  100 + // We redirect directly as we can not wait for an automatic redirection.
  101 + $this->getSession()->getDriver()->getClient()->request('get', $url);
  102 +
  103 + } else {
  104 + // Reload the page if no URL was provided.
  105 + $this->getSession()->getDriver()->reload();
  106 + }
  107 + }
  108 +
  109 + /**
67 110 * Switches to the specified window. Useful when interacting with popup windows.
68 111 *
69 112 * @Given /^I switch to "(?P<window_name_string>(?:[^"]|\\")*)" window$/
@@ -110,6 +153,11 @@ public function click_link($link) {
110 153 * @param int $seconds
111 154 */
112 155 public function i_wait_seconds($seconds) {
  156 +
  157 + if (!$this->running_javascript()) {
  158 + throw new DriverException('Waits are disabled in scenarios without Javascript support');
  159 + }
  160 +
113 161 $this->getSession()->wait($seconds * 1000, false);
114 162 }
115 163
@@ -119,6 +167,11 @@ public function i_wait_seconds($seconds) {
119 167 * @Given /^I wait until the page is ready$/
120 168 */
121 169 public function wait_until_the_page_is_ready() {
  170 +
  171 + if (!$this->running_javascript()) {
  172 + throw new DriverException('Waits are disabled in scenarios without Javascript support');
  173 + }
  174 +
122 175 $this->getSession()->wait(self::TIMEOUT, '(document.readyState === "complete")');
123 176 }
124 177
17 mod/forum/tests/behat/behat_mod_forum.php
@@ -51,10 +51,10 @@ public function i_add_a_forum_discussion_to_forum_with($forumname, TableNode $ta
51 51 // Escaping $forumname as it has been stripped automatically by the transformer.
52 52 return array(
53 53 new Given('I follow "' . $this->escape($forumname) . '"'),
54   - new Given('I press "Add a new discussion topic"'),
  54 + new Given('I press "' . get_string('addanewdiscussion', 'mod_forum') . '"'),
55 55 new Given('I fill the moodle form with:', $table),
56   - new Given('I press "Post to forum"'),
57   - new Given('I wait "5" seconds')
  56 + new Given('I press "' . get_string('posttoforum', 'mod_forum') . '"'),
  57 + new Given('I wait to be redirected')
58 58 );
59 59 }
60 60
@@ -62,8 +62,8 @@ public function i_add_a_forum_discussion_to_forum_with($forumname, TableNode $ta
62 62 * Adds a reply to the specified post of the specified forum. The step begins from the forum's page or from the forum's course page.
63 63 *
64 64 * @Given /^I reply "(?P<post_subject_string>(?:[^"]|\\")*)" post from "(?P<forum_name_string>(?:[^"]|\\")*)" forum with:$/
65   - * @param mixed $postname The subject of the post
66   - * @param mixed $forumname The forum name
  65 + * @param string $postname The subject of the post
  66 + * @param string $forumname The forum name
67 67 * @param TableNode $table
68 68 */
69 69 public function i_reply_post_from_forum_with($postsubject, $forumname, TableNode $table) {
@@ -71,10 +71,11 @@ public function i_reply_post_from_forum_with($postsubject, $forumname, TableNode
71 71 return array(
72 72 new Given('I follow "' . $this->escape($forumname) . '"'),
73 73 new Given('I follow "' . $this->escape($postsubject) . '"'),
74   - new Given('I follow "Reply"'),
  74 + new Given('I follow "' . get_string('reply', 'mod_forum') . '"'),
75 75 new Given('I fill the moodle form with:', $table),
76   - new Given('I press "Post to forum"'),
77   - new Given('I wait "5" seconds')
  76 + new Given('I press "' . get_string('posttoforum', 'mod_forum') . '"'),
  77 + new Given('I wait to be redirected')
78 78 );
  79 +
79 80 }
80 81 }
4 mod/forum/tests/behat/edit_post_student.feature
@@ -33,9 +33,7 @@ Feature: Students can edit or delete their forum posts within a set time limit
33 33 And I add a new discussion to "Test forum name" forum with:
34 34 | Subject | Forum post subject |
35 35 | Message | This is the body |
36   - And I wait "6" seconds
37 36
38   - @javascript
39 37 Scenario: Edit forum post
40 38 When I follow "Forum post subject"
41 39 And I follow "Edit"
@@ -43,7 +41,7 @@ Feature: Students can edit or delete their forum posts within a set time limit
43 41 | Subject | Edited post subject |
44 42 | Message | Edited post body |
45 43 And I press "Save changes"
46   - And I wait "6" seconds
  44 + And I wait to be redirected
47 45 Then I should see "Edited post subject"
48 46 And I should see "Edited post body"
49 47

0 comments on commit ff46f98

Please sign in to comment.
Something went wrong with that request. Please try again.