public function JSWebAssert::assertVisibleInViewport in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php \Drupal\FunctionalJavascriptTests\JSWebAssert::assertVisibleInViewport()
Tests that a node, or its specific corner, is visible in the viewport.
Note: Always set the viewport size. This can be done in your test with \Behat\Mink\Session->resizeWindow(). Drupal CI JavaScript tests by default use a viewport of 1024x768px.
Parameters
string $selector_type: The element selector type (CSS, XPath).
string|array $selector: The element selector. Note: the first found element is used.
bool|string $corner: (Optional) The corner to test: topLeft, topRight, bottomRight, bottomLeft. Or FALSE to check the complete element (default).
string $message: (optional) A message for the exception.
Throws
\Behat\Mink\Exception\ElementHtmlException When the element doesn't exist.
\Behat\Mink\Exception\ElementNotFoundException When the element is not visible in the viewport.
File
- core/
tests/ Drupal/ FunctionalJavascriptTests/ JSWebAssert.php, line 261
Class
- JSWebAssert
- Defines a class with methods for asserting presence of elements during tests.
Namespace
Drupal\FunctionalJavascriptTestsCode
public function assertVisibleInViewport($selector_type, $selector, $corner = FALSE, $message = 'Element is not visible in the viewport.') {
$node = $this->session
->getPage()
->find($selector_type, $selector);
if ($node === NULL) {
if (is_array($selector)) {
$selector = implode(' ', $selector);
}
throw new ElementNotFoundException($this->session
->getDriver(), 'element', $selector_type, $selector);
}
// Check if the node is visible on the page, which is a prerequisite of
// being visible in the viewport.
if (!$node
->isVisible()) {
throw new ElementHtmlException($message, $this->session
->getDriver(), $node);
}
$result = $this
->checkNodeVisibilityInViewport($node, $corner);
if (!$result) {
throw new ElementHtmlException($message, $this->session
->getDriver(), $node);
}
}