15 use Facebook\WebDriver\WebDriverBy;
16 use Facebook\WebDriver\WebDriverDimension;
17 use Facebook\WebDriver\WebDriverExpectedCondition;
18 use Facebook\WebDriver\Remote\DesiredCapabilities;
19 use Facebook\WebDriver\Remote\RemoteWebDriver;
21 if (!class_exists(
'\Facebook\WebDriver\Remote\RemoteWebDriver')) {
22 throw new ConfigurationException(
23 'SeleniumTestCase requires Facebook\WebDriver. '.
24 'If you are using composer, add facebook/webdriver '.
25 'as dependency to your project');
39 private static $displayWidths = [
49 private static $height = 768;
54 if (!defined(
'TEST_SERVER')) {
55 throw new \RuntimeException(
"Constant TEST_SERVER not defined, e.g. define(TEST_SERVER, 'localhost:8500')");
57 return "http://".TEST_SERVER;
61 if (!defined(
'SELENIUM_SERVER')) {
62 throw new \RuntimeException(
"Constant SELENIUM_SERVER not defined, e.g. define(SELENIUM_SERVER, 'localhost:8001')");
64 return "http://".SELENIUM_SERVER;
68 $screenshot = $this->driver->takeScreenshot();
69 file_put_contents(
'log/'.$filename.
'.png', $screenshot);
73 $this->driver = RemoteWebDriver::create(self::getSeleniumUrl(), DesiredCapabilities::phantomjs());
79 if (isset(self::$displayWidths[$size])) {
80 $this->
setWindowSize(self::$displayWidths[$size], self::$height);
85 $this->driver->manage()->window()->setSize(
new WebDriverDimension($width, $height));
92 protected function wait($seconds) {
93 $this->driver->manage()->timeouts()->implicitlyWait($seconds);
102 return $this->driver->findElement(WebDriverBy::xpath($xpath));
110 protected function login($user, $password) {
111 $this->driver->get(self::getAppUrl());
112 $this->driver->wait(10, 1000)->until(
113 WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::name(
'user'))
116 $this->driver->findElement(WebDriverBy::name(
'user'))->sendKeys($user);
117 $this->driver->findElement(WebDriverBy::name(
'password'))->sendKeys($password);
118 $this->
byXpath(
"//span[contains(text(),'Sign in')]")->click();
byXpath($xpath)
Get the DOM element matching the given xpath.
setWindowSize($width, $height)
login($user, $password)
Log into the application.
ConfigurationException signals an exception in the configuration.
takeScreenShot($filename)
DatabaseTestCase is the base class for test cases that need database support.
SeleniumTestCase is the base class for test cases that run with Selenium.