Selenium and Laravel 5.2

I feel sad

I am using Laravel 5.2 and I am developing my unit tests.

In Laravel 5.1 you can use a large integrated lib to use selenium, but it does not work in Laravel 5.2

So, basically, is there any kind of integration between L5.2 and Selenium, or is it impossible to use?

In this case, I must finally stay in L5.1, since testing is a fundamental part of my application :(

+6
source share
1 answer

You need to install the PHPUnit_selenium package using composer

composer require --dev phpunit/phpunit-selenium 

Create selenium test class inside laravel / tests /

 <?php class SeleniumTestCase extends PHPUnit_Extensions_Selenium2TestCase { /** * The base URL to use while testing the application. * * @var string */ protected function setUp() { $this->setBrowser('firefox'); $this->setBrowserUrl('http://localhost:8000/'); } protected function visit($path) { $this->url($path); return $this; } protected function see($text, $tag = 'body') { print_r(request()->session()->all()); //method call by tag name; $this->assertContains($text,$this->byTag($tag)->text()); return $this; } protected function pressByName($text){ $this->byName($text)->click(); return $this; } protected function pressByTag(){ $this->byTag('button')->click(); return $this; } protected function type($value, $name) { $this->byName($name)->value($value); return $this; } protected function hold($seconds){ sleep($seconds); return $this; } } 

and Create a new test case to visit the homepage URL

 <?php class ExampleTest extends SeleniumTestCase { /** * A basic functional test example. * * @return void */ public function testTitle() { $this->visit('/') ->see('Site title','title'); } } 

and execute the PHPunit test command from the terminal

 java -jar /usr/local/bin/selenium-server-standalone-2.35.0.jar 

Reference document:

0
source

All Articles