Chris@17
|
1 <?php
|
Chris@17
|
2
|
Chris@17
|
3 namespace Drupal\FunctionalJavascriptTests;
|
Chris@17
|
4
|
Chris@17
|
5 /**
|
Chris@17
|
6 * Tests if we can execute JavaScript in the browser.
|
Chris@17
|
7 *
|
Chris@17
|
8 * @group javascript
|
Chris@17
|
9 */
|
Chris@17
|
10 class BrowserWithJavascriptTest extends WebDriverTestBase {
|
Chris@17
|
11
|
Chris@17
|
12 public function testJavascript() {
|
Chris@17
|
13 $this->drupalGet('<front>');
|
Chris@17
|
14 $session = $this->getSession();
|
Chris@17
|
15
|
Chris@17
|
16 $session->resizeWindow(400, 300);
|
Chris@17
|
17 $javascript = <<<JS
|
Chris@17
|
18 (function(){
|
Chris@17
|
19 var w = window,
|
Chris@17
|
20 d = document,
|
Chris@17
|
21 e = d.documentElement,
|
Chris@17
|
22 g = d.getElementsByTagName('body')[0],
|
Chris@17
|
23 x = w.innerWidth || e.clientWidth || g.clientWidth,
|
Chris@17
|
24 y = w.innerHeight || e.clientHeight|| g.clientHeight;
|
Chris@17
|
25 return x == 400 && y == 300;
|
Chris@17
|
26 }());
|
Chris@17
|
27 JS;
|
Chris@17
|
28 $this->assertJsCondition($javascript);
|
Chris@17
|
29 }
|
Chris@17
|
30
|
Chris@17
|
31 public function testAssertJsCondition() {
|
Chris@17
|
32 $this->drupalGet('<front>');
|
Chris@17
|
33 $session = $this->getSession();
|
Chris@17
|
34
|
Chris@17
|
35 $session->resizeWindow(500, 300);
|
Chris@17
|
36 $javascript = <<<JS
|
Chris@17
|
37 (function(){
|
Chris@17
|
38 var w = window,
|
Chris@17
|
39 d = document,
|
Chris@17
|
40 e = d.documentElement,
|
Chris@17
|
41 g = d.getElementsByTagName('body')[0],
|
Chris@17
|
42 x = w.innerWidth || e.clientWidth || g.clientWidth,
|
Chris@17
|
43 y = w.innerHeight || e.clientHeight|| g.clientHeight;
|
Chris@17
|
44 return x == 400 && y == 300;
|
Chris@17
|
45 }());
|
Chris@17
|
46 JS;
|
Chris@17
|
47
|
Chris@17
|
48 // We expected the following assertion to fail because the window has been
|
Chris@17
|
49 // re-sized to have a width of 500 not 400.
|
Chris@17
|
50 $this->setExpectedException(\PHPUnit_Framework_AssertionFailedError::class);
|
Chris@17
|
51 $this->assertJsCondition($javascript, 100);
|
Chris@17
|
52 }
|
Chris@17
|
53
|
Chris@17
|
54 /**
|
Chris@17
|
55 * Tests creating screenshots.
|
Chris@17
|
56 */
|
Chris@17
|
57 public function testCreateScreenshot() {
|
Chris@17
|
58 $this->drupalGet('<front>');
|
Chris@17
|
59 $this->createScreenshot('public://screenshot.jpg');
|
Chris@17
|
60 $this->assertFileExists('public://screenshot.jpg');
|
Chris@17
|
61 }
|
Chris@17
|
62
|
Chris@17
|
63 }
|