MDL-78806 behat: Create a step that for checking the page title
Create a Behat step "the page title should contain ':title'" to check the page title.
This commit is contained in:
@@ -2280,4 +2280,36 @@ EOF;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the page title contains a given string.
|
||||
*
|
||||
* @Given the page title should contain ":title"
|
||||
* @param string $title The string that should be present on the page title.
|
||||
*/
|
||||
public function the_page_title_should_contain(string $title): void {
|
||||
$session = $this->getSession();
|
||||
if ($this->running_javascript()) {
|
||||
// When running on JS, the page title can be changed via JS, so it's more reliable to get the actual page title via JS.
|
||||
$actualtitle = $session->evaluateScript("return document.title");
|
||||
} else {
|
||||
$titleelement = $session->getPage()->find('css', 'head title');
|
||||
if ($titleelement === null) {
|
||||
// Throw an exception if a page title is not present on the page.
|
||||
throw new ElementNotFoundException(
|
||||
$this->getSession(),
|
||||
'<title> element',
|
||||
'css',
|
||||
'head title'
|
||||
);
|
||||
}
|
||||
$actualtitle = $titleelement->getText();
|
||||
}
|
||||
|
||||
if (strpos($actualtitle, $title) === false) {
|
||||
throw new ExpectationException(
|
||||
"'$title' was not found from the current page title '$actualtitle'",
|
||||
$session
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ information provided here is intended especially for developers.
|
||||
If it's necessary to override this, pass `false` to its new optional parameter `$appendsitename`.
|
||||
* New page title separator constant `moodle_page:TITLE_SEPARATOR` has been created to help standardise the separators used in page
|
||||
titles.
|
||||
* New Behat step \behat_general::the_page_title_should_contain() has been added to allow checking of page titles. You can use this
|
||||
when writing feature files to check that the page title contains the expected string.
|
||||
e.g. `And the page title should contain "Some title"`
|
||||
|
||||
=== 4.1.5 ===
|
||||
* Added a new render of caption for the table in render_caption. It can be used by
|
||||
|
||||
Reference in New Issue
Block a user