require_once(__DIR__ . '/../../behat/behat_base.php');
use Behat\Mink\Exception\ExpectationException as ExpectationException,
- Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
+ Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException,
+ Behat\Mink\Exception\DriverException as DriverException;
/**
* Cross component steps definitions.
$this->getSession()->reload();
}
+ /**
+ * Follows the page redirection. Use this step after any action that shows a message and waits for a redirection
+ *
+ * @Given /^I wait to be redirected$/
+ */
+ public function i_wait_to_be_redirected() {
+
+ // Xpath and processes based on core_renderer::redirect_message(), core_renderer::$metarefreshtag and
+ // moodle_page::$periodicrefreshdelay possible values.
+ if (!$metarefresh = $this->getSession()->getPage()->find('xpath', "//head/descendant::meta[@http-equiv='refresh']")) {
+ // We don't fail the scenario if no redirection with message is found to avoid race condition false failures.
+ return false;
+ }
+
+ $content = $metarefresh->getAttribute('content');
+ if (strstr($content, 'url') != false) {
+
+ list($waittime, $url) = explode(';', $metarefresh->getAttribute('content'));
+
+ // Cleaning the URL value.
+ $url = trim(substr($url, strpos($url, 'http')));
+
+ } else {
+ // Just wait then.
+ $waittime = $content;
+ }
+
+
+ // Wait until the URL change is executed.
+ if ($this->running_javascript()) {
+ $this->getSession()->wait($waittime * 1000, false);
+
+ } else if (!empty($url)) {
+ // We redirect directly as we can not wait for an automatic redirection.
+ $this->getSession()->getDriver()->getClient()->request('get', $url);
+
+ } else {
+ // Reload the page if no URL was provided.
+ $this->getSession()->getDriver()->reload();
+ }
+ }
+
/**
* Switches to the specified window. Useful when interacting with popup windows.
*
* @param int $seconds
*/
public function i_wait_seconds($seconds) {
+
+ if (!$this->running_javascript()) {
+ throw new DriverException('Waits are disabled in scenarios without Javascript support');
+ }
+
$this->getSession()->wait($seconds * 1000, false);
}
* @Given /^I wait until the page is ready$/
*/
public function wait_until_the_page_is_ready() {
+
+ if (!$this->running_javascript()) {
+ throw new DriverException('Waits are disabled in scenarios without Javascript support');
+ }
+
$this->getSession()->wait(self::TIMEOUT, '(document.readyState === "complete")');
}
// Escaping $forumname as it has been stripped automatically by the transformer.
return array(
new Given('I follow "' . $this->escape($forumname) . '"'),
- new Given('I press "Add a new discussion topic"'),
+ new Given('I press "' . get_string('addanewdiscussion', 'mod_forum') . '"'),
new Given('I fill the moodle form with:', $table),
- new Given('I press "Post to forum"'),
- new Given('I wait "5" seconds')
+ new Given('I press "' . get_string('posttoforum', 'mod_forum') . '"'),
+ new Given('I wait to be redirected')
);
}
* 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.
*
* @Given /^I reply "(?P<post_subject_string>(?:[^"]|\\")*)" post from "(?P<forum_name_string>(?:[^"]|\\")*)" forum with:$/
- * @param mixed $postname The subject of the post
- * @param mixed $forumname The forum name
+ * @param string $postname The subject of the post
+ * @param string $forumname The forum name
* @param TableNode $table
*/
public function i_reply_post_from_forum_with($postsubject, $forumname, TableNode $table) {
return array(
new Given('I follow "' . $this->escape($forumname) . '"'),
new Given('I follow "' . $this->escape($postsubject) . '"'),
- new Given('I follow "Reply"'),
+ new Given('I follow "' . get_string('reply', 'mod_forum') . '"'),
new Given('I fill the moodle form with:', $table),
- new Given('I press "Post to forum"'),
- new Given('I wait "5" seconds')
+ new Given('I press "' . get_string('posttoforum', 'mod_forum') . '"'),
+ new Given('I wait to be redirected')
);
+
}
}
And I add a new discussion to "Test forum name" forum with:
| Subject | Forum post subject |
| Message | This is the body |
- And I wait "6" seconds
- @javascript
Scenario: Edit forum post
When I follow "Forum post subject"
And I follow "Edit"
| Subject | Edited post subject |
| Message | Edited post body |
And I press "Save changes"
- And I wait "6" seconds
+ And I wait to be redirected
Then I should see "Edited post subject"
And I should see "Edited post body"