public function BrowserWithJavascriptTest::testAssertJsCondition in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php \Drupal\FunctionalJavascriptTests\BrowserWithJavascriptTest::testAssertJsCondition()
 - 10 core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php \Drupal\FunctionalJavascriptTests\BrowserWithJavascriptTest::testAssertJsCondition()
 
File
- core/
tests/ Drupal/ FunctionalJavascriptTests/ BrowserWithJavascriptTest.php, line 46  
Class
- BrowserWithJavascriptTest
 - Tests if we can execute JavaScript in the browser.
 
Namespace
Drupal\FunctionalJavascriptTestsCode
public function testAssertJsCondition() {
  $this
    ->drupalGet('<front>');
  $session = $this
    ->getSession();
  $session
    ->resizeWindow(500, 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;
  // We expected the following assertion to fail because the window has been
  // re-sized to have a width of 500 not 400.
  $this
    ->expectException(AssertionFailedError::class);
  $this
    ->assertJsCondition($javascript, 100);
}