2016-04-20 09:56:34 -07:00
< ? php
2018-11-23 12:29:20 +00:00
namespace Drupal\FunctionalJavascriptTests ;
2016-04-20 09:56:34 -07:00
/**
* Tests if we can execute JavaScript in the browser .
*
* @ group javascript
*/
2018-11-23 12:29:20 +00:00
class BrowserWithJavascriptTest extends WebDriverTestBase {
2016-04-20 09:56:34 -07:00
public function testJavascript () {
$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 );
}
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 -> setExpectedException ( \PHPUnit_Framework_AssertionFailedError :: class );
$this -> assertJsCondition ( $javascript , 100 );
}
2016-08-03 13:22:33 -07:00
/**
* Tests creating screenshots .
*/
public function testCreateScreenshot () {
$this -> drupalGet ( '<front>' );
$this -> createScreenshot ( 'public://screenshot.jpg' );
$this -> assertFileExists ( 'public://screenshot.jpg' );
}
2016-04-20 09:56:34 -07:00
}