2016-03-08 119 views
6

我越來越傷心,Selenium和Laravel 5.2

我使用Laravel 5.2,並且正在開發我的單元測試。

在Laravel 5.1,你可以使用大集成的lib用硒,但它似乎並沒有在Laravel 5.2

所以基本上工作,有15.2和硒之間的任何一種整合的,或者很好地使用它是不可能的?

在這種情況下,我應該明確地留在L5.1作爲測試我的應用程序:(

+2

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

回答

0

的基本組成部分,您需要使用作曲家

composer require --dev phpunit/phpunit-selenium 

創建Selenium測試安裝PHPUnit_selenium包裏面laravel /測試案例類/

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

,並創建新的測試用例訪問主頁的網址

從終端

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

參考文獻10

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

和運行指令的PHPUnit測試: