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:
@@ -2188,4 +2188,37 @@ 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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
This files describes API changes in core libraries and APIs,
|
||||
information provided here is intended especially for developers.
|
||||
|
||||
=== 3.9.24 ===
|
||||
* 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"`
|
||||
|
||||
===3.9.22===
|
||||
* Added a new parameter in address_in_subnet to give us the ability to check for 0.0.0.0 or not.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user