function BrowserWithJavascriptTest::testJavascript

Same name in other branches
  1. 9 core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php \Drupal\FunctionalJavascriptTests\BrowserWithJavascriptTest::testJavascript()
  2. 8.9.x core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php \Drupal\FunctionalJavascriptTests\BrowserWithJavascriptTest::testJavascript()
  3. 11.x core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php \Drupal\FunctionalJavascriptTests\BrowserWithJavascriptTest::testJavascript()

File

core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php, line 26

Class

BrowserWithJavascriptTest
Tests if we can execute JavaScript in the browser.

Namespace

Drupal\FunctionalJavascriptTests

Code

public function testJavascript() : void {
    $this->drupalGet('<front>');
    $session = $this->getSession();
    $session->resizeWindow(400, 300);
    $javascript = <<<JS
    (function(){
        var w = window,
        d = document,
        e = d.documentElement,
        g = d.getElementsByTagName('body')[0],
        x = w.innerWidth || e.clientWidth || g.clientWidth,
        y = w.innerHeight || e.clientHeight|| g.clientHeight;
        return x == 400 && y == 300;
    }())
JS;
    $this->assertJsCondition($javascript);
    // Ensure that \Drupal\Tests\UiHelperTrait::isTestUsingGuzzleClient() works
    // as expected.
    $this->assertFalse($this->isTestUsingGuzzleClient());
}

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