2015-10-14 31 views
3

我使用Selenium和PHPUnit以及Laracast集成庫一起工作。Selenium和Laravel 5中的未處理錯誤

事情是,當我運行測試時,它出現了一個奇怪的錯誤,我沒有在任何地方找到它。

的代碼如下:

<?php 

use Laracasts\Integrated\Extensions\Selenium as SeleniumTestCase; 
use Laracasts\Integrated\Services\Laravel\Application as Laravel; 
use App\Models\User; 
use App\Models\App; 
use App\Models\Role; 

class SeleniumTests extends SeleniumTestCase 
{ 

    protected $baseUrl = 'http://localhost:4444/wd/hub'; 

    use Laravel; 

    /** 
    * 
    * Creates a user with email $email and password $password 
    * 
    * @param string $email Email of the user 
    * @param string $password Password of the user 
    * 
    * @return User 
    */ 
    private function createAdminUser($email, $password) 
    { 
     $user = new User; 
     $user->name = rand(1000000000, 999999999999)." user ".rand(1000000000, 999999999999); 
     $user->email = $email; 
     $user->password = \Hash::make($password); 
     $user->save(); 

     $adminRole = Role::where('name', 'admin')->first(); 

     $user->attachRole($adminRole); 

     return \App\Models\User::find($user->id); 
    } 

    /** 
    * @test 
    * Test a login of a registered user 
    * 
    * @return void 
    */ 
    public function testLoginOK() 
    { 
     $email = '[email protected]'; 
     $password = 'us3rP4ssW0rd'; 

     $this->createAdminUser($email, $password); 

     $this->visit('auth/login') 
      ->type($email, 'email') 
      ->type($password, 'password') 
      ->andSnap() 
      ->press('Continue') 
      ->seePageIs('dashboard'); 
    } 

而且我收到的錯誤是:

{ 
    "sessionId": null, 
    "status": 13, 
    "state": "unhandled error", 
    "value": { 
    "message": "GET \/auth\/login\nBuild info: version: '2.48.1', revision: 'd80083d', time: '2015-10-08 21:11:00'\nSystem info: host: 'homestead', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-24-generic', java.version: '1.7.0_79'\nDriver info: driver.version: unknown", 
    "suppressed": [ 

    ], 
    "localizedMessage": "GET \/auth\/login\nBuild info: version: '2.48.1', revision: 'd80083d', time: '2015-10-08 21:11:00'\nSystem info: host: 'homestead', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-24-generic', java.version: '1.7.0_79'\nDriver info: driver.version: unknown", 
    "buildInformation": null, 
    "cause": null, 
    "systemInformation": "System info: host: 'homestead', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-24-generic', java.version: '1.7.0_79'", 
    "supportUrl": null, 
    "class": "org.openqa.selenium.UnsupportedCommandException", 
    "additionalInformation": "\nDriver info: driver.version: unknown", 
    "hCode": 138828459, 
    "stackTrace": [ 
     null, 
     null, 
     null, 
     null, 
     null, 
     null, 
     null, 
     null, 
     null, 
     null, 
     null, 
     null, 
     null, 
     null, 
     null, 
     null, 
     null, 
     null, 
     null 
    ] 
    }, 
    "class": "org.openqa.selenium.remote.Response", 
    "hCode": 1122669771 
} 

由於額外的信息:如果我把protected $baseUrl = 'http://{my_development_url}';代替protected $baseUrl = 'http://localhost:4444/wd/hub';一切按預期工作,但我需要代碼在Scrutinizer上工作,所以我不能這樣做。

如果不是訪問auth/login我訪問/它出現一個帶按鈕的儀表板,所以我猜Selenium正在工作。

有沒有人有關於我做錯了什麼的線索?

提前致謝!

回答

1

那麼,經過大量的時間和學習,我會解釋更多一點我的情況,我會得出結論。

我使用Laravel 5與Selenium。由於我使用硒而不是Laravel的IntegratedTests,因此我必須設置一個測試域。我使用nginx,所以我改變了我的.env文件並創建了一個新的域。由於我在同一個Homestead開發了大量項目,因此我無法使用默認的localhost。

所以,結論:

  • 我要創建我的nginx的另一個域來測試它
  • 我不得不改變我。與測試數據庫
  • ENV文件我不得不安裝硒通過做工作無頭:
    • sudo apt-get install xvfb firefox
    • DISPLAY=:0 xvfb-run --server-args="-screen 0, 2560x2560x24" java -jar selenium-server-standalone-2.48.1.jar

之後,你就可以運行測試正確

0

一切都按預期工作,但我需要代碼在Scrutinizer上工作,所以我不能這樣做。

看起來您的解決方案是一種環境類型。你將要在這裏使用env()輔助方法。

public function __construct() 
{ 
    $this->baseUrl = env('TEST_BASEURL', 'http://{my_development_url}'); 
} 

然後,只需這一行添加到您的.ENV:

TEST_BASEURL = http://localhost:4444/wd/hub


這裏是哪裏找到更多的文檔:http://laravel.com/docs/master/#environment-configuration

+0

事情是,我需要在Scrutinizer中配置整個事情,對吧?設置主機,配置一個nginx服務器......對吧? –

+0

您可以在scrutinizer中使用默認的詳細信息。 –