2016-03-08 14 views
6

Mi sto diventando triste,Selenio e Laravel 5.2

Io uso Laravel 5.2 e sto sviluppando i miei test unitari.

In laravel 5.1, è possibile utilizzare la grande lib integrato da usare selenio, ma non sembra di lavorare in laravel 5.2

Quindi, in pratica, c'è qualche tipo di integrazione tra L5.2 e selenio, o è imposibile usarlo bene?

In questo caso, dovrei definitivamente soggiornato in L5.1 come test è una parte fondamentale della mia app :(

+2

https://laracasts.com/discuss/channels/testing/has-anyone-tried-laravel-integrated-package-in-laravel-52 – haakym

risposta

0

È necessario installare il pacchetto PHPUnit_selenium utilizzando compositore

composer require --dev phpunit/phpunit-selenium 

Crea Selenio test classe caso all'interno laravel/test/

<?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; 
    } 
} 

e creare nuovi banco di prova per la visita home page URL

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

e comando di marcia di prova phpunit dal terminale documento

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

Riferimento: