3 namespace Drupal\FunctionalJavascriptTests;
6 * Tests if we can execute JavaScript in the browser.
10 class BrowserWithJavascriptTest extends WebDriverTestBase {
12 public function testJavascript() {
13 $this->drupalGet('<front>');
14 $session = $this->getSession();
16 $session->resizeWindow(400, 300);
21 e = d.documentElement,
22 g = d.getElementsByTagName('body')[0],
23 x = w.innerWidth || e.clientWidth || g.clientWidth,
24 y = w.innerHeight || e.clientHeight|| g.clientHeight;
25 return x == 400 && y == 300;
28 $this->assertJsCondition($javascript);
31 public function testAssertJsCondition() {
32 $this->drupalGet('<front>');
33 $session = $this->getSession();
35 $session->resizeWindow(500, 300);
40 e = d.documentElement,
41 g = d.getElementsByTagName('body')[0],
42 x = w.innerWidth || e.clientWidth || g.clientWidth,
43 y = w.innerHeight || e.clientHeight|| g.clientHeight;
44 return x == 400 && y == 300;
48 // We expected the following assertion to fail because the window has been
49 // re-sized to have a width of 500 not 400.
50 $this->setExpectedException(\PHPUnit_Framework_AssertionFailedError::class);
51 $this->assertJsCondition($javascript, 100);
55 * Tests creating screenshots.
57 public function testCreateScreenshot() {
58 $this->drupalGet('<front>');
59 $this->createScreenshot('public://screenshot.jpg');
60 $this->assertFileExists('public://screenshot.jpg');