function JSWebAssert::assertVisibleInViewport

Same name in other branches
  1. 9 core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php \Drupal\FunctionalJavascriptTests\JSWebAssert::assertVisibleInViewport()
  2. 8.9.x core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php \Drupal\FunctionalJavascriptTests\JSWebAssert::assertVisibleInViewport()
  3. 11.x 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 326

Class

JSWebAssert
Defines a class with methods for asserting presence of elements during tests.

Namespace

Drupal\FunctionalJavascriptTests

Code

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);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.