Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 20 |
Selenium | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 20 |
_initialize() | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 8 |
|||
_failed(\Codeception\TestCase $test, $error) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
_afterStep(\Codeception\Step $step) | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 3 |
|||
_saveScreenshot($filename) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
<?php | |
namespace Codeception\Module; | |
/** | |
* | |
* Uses Mink to launch and manipulate Selenium Server (formerly the Selenium RC Server). | |
* | |
* But we recommend you to use **Selenium 2 WebDriver** as it is an evolution of SeleniumRC and grants you more stable results. | |
* For manipulation with Selenium WebDriver use [Selenium2](/docs/modules/Selenium2) module | |
* | |
* Note, all method takes CSS selectors to fetch elements. | |
* For links, buttons, fields you can use names/values/ids of elements. | |
* For form fields you can use name of matched label. | |
* | |
* Will save a screenshot of browser window to log directory on fail. | |
* | |
* ## Installation | |
* | |
* [Download Selenium RC Server](http://seleniumhq.org/download) | |
* | |
* Execute it: `java -jar selenium-server-standalone-x.xx.xxx.jar` | |
* | |
* Best used with Firefox browser. | |
* | |
* Don't forget to turn on Db repopulation if you are using database. | |
* | |
* ## Configuration | |
* | |
* * url *required* - start url for your app | |
* * browser *required* - browser that would be launched | |
* * host - Selenium server host (localhost by default) | |
* * port - Selenium server port (4444 by default) | |
* * delay - set delay between actions in milliseconds (1/1000 of second) if they run too fast | |
* | |
* ## Public Properties | |
* | |
* * session - contains Mink Session | |
*/ | |
class Selenium extends \Codeception\Util\MinkJS | |
{ | |
protected $requiredFields = array('browser', 'url'); | |
protected $config = array('host' => '127.0.0.1', 'port' => '4444', 'delay' => 0); | |
public function _initialize() { | |
$client = new \Selenium\Client($this->config['host'], $this->config['port']); | |
$driver = new \Behat\Mink\Driver\SeleniumDriver( | |
$this->config['browser'], $this->config['url'], $client | |
); | |
$this->session = new \Behat\Mink\Session($driver); | |
parent::_initialize(); | |
} | |
public function _failed(\Codeception\TestCase $test, $error) { | |
$this->_saveScreenshot(\Codeception\Configuration::logDir().basename($test->getFileName()).'.fail.png'); | |
$this->debug("Screenshot was saved into 'log' dir"); | |
$this->session->stop(); | |
} | |
// please, add more custom Selenium functions here | |
public function _afterStep(\Codeception\Step $step) { | |
if ($this->config['delay']) usleep($this->config['delay'] * 1000); | |
} | |
public function _saveScreenshot($filename) | |
{ | |
$this->session->getDriver()->getBrowser()->captureEntirePageScreenshot($filename,''); | |
} | |
} |