3 namespace Drupal\Tests\simpletest\FunctionalJavascript;
5 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
8 * Tests if we can execute JavaScript in the browser.
12 class BrowserWithJavascriptTest extends JavascriptTestBase {
14 public function testJavascript() {
15 $this->drupalGet('<front>');
16 $session = $this->getSession();
18 $session->resizeWindow(400, 300);
23 e = d.documentElement,
24 g = d.getElementsByTagName('body')[0],
25 x = w.innerWidth || e.clientWidth || g.clientWidth,
26 y = w.innerHeight || e.clientHeight|| g.clientHeight;
27 return x == 400 && y == 300;
30 $this->assertJsCondition($javascript);
33 public function testAssertJsCondition() {
34 $this->drupalGet('<front>');
35 $session = $this->getSession();
37 $session->resizeWindow(500, 300);
42 e = d.documentElement,
43 g = d.getElementsByTagName('body')[0],
44 x = w.innerWidth || e.clientWidth || g.clientWidth,
45 y = w.innerHeight || e.clientHeight|| g.clientHeight;
46 return x == 400 && y == 300;
50 // We expected the following assertion to fail because the window has been
51 // re-sized to have a width of 500 not 400.
52 $this->setExpectedException(\PHPUnit_Framework_AssertionFailedError::class);
53 $this->assertJsCondition($javascript, 100);
57 * Tests creating screenshots.
59 public function testCreateScreenshot() {
60 $this->drupalGet('<front>');
61 $this->createScreenshot('public://screenshot.jpg');
62 $this->assertFileExists('public://screenshot.jpg');