2016-03-08 31 views
6

Tôi đang buồn,Selenium và Laravel 5.2

Tôi sử dụng Laravel 5.2 và tôi phát hiện các thử nghiệm đơn vị của mình.

Trong Laravel 5.1, bạn có thể sử dụng lib tích hợp tuyệt vời để sử dụng selen, nhưng nó dường như không làm việc trong Laravel 5.2

Vì vậy, về cơ bản, Có bất kỳ loại tích hợp giữa L5.2 và Selenium, hoặc là nó không thể sử dụng nó độc đáo?

Trong trường hợp này, tôi nên dứt khoát đã ở trong L5.1 như thử nghiệm là một phần cơ bản của ứng dụng của tôi :(

+2

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

Trả lời

0

Bạn cần cài đặt gói PHPUnit_selenium sử dụng nhà soạn nhạc

composer require --dev phpunit/phpunit-selenium 

Tạo Selenium thử nghiệm lớp trường hợp bên laravel/kiểm tra/

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

và Tạo trường hợp thử nghiệm mới đã ghé thăm trang nhà url

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

và Run lệnh kiểm tra PHPUnit từ thiết bị đầu cuối tài liệu

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

tham khảo:

Các vấn đề liên quan