【问题标题】:Unhandled Error in Selenium with Laravel 5使用 Laravel 5 处理 Selenium 中的未处理错误
【发布时间】:2016-01-12 06:39:49
【问题描述】:

我将 Selenium 与 PHPUnit 和 Laracast 集成库一起使用。

问题是当我运行测试时它出现了一个奇怪的错误,但我在任何地方都没有找到它。

代码如下:

<?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 = 'test@user.com';
        $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 正在工作。

有人知道我做错了什么吗?

提前致谢!

【问题讨论】:

    标签: php laravel selenium phpunit


    【解决方案1】:

    好吧,经过大量时间和学习后,我将多解释一下我的情况,然后得出结论。

    我正在使用带有 Selenium 的 Laravel 5。因为我使用的是 selenium 而不是 Laravel 的 IntegratedTests,所以我必须设置一个测试域。我使用的是 nginx,所以我更改了 .env 文件并创建了一个新域。由于我在同一个 Homestead 中开发了大量项目,因此我无法使用默认的 localhost。

    所以,结论:

    • 我不得不在我的 nginx 中创建另一个域来测试它
    • 我不得不用测试数据库更改我的 .env 文件
    • 我必须通过以下方式设置 Selenium 无头工作:
      • sudo apt-get install xvfb firefox
      • DISPLAY=:0 xvfb-run --server-args="-screen 0, 2560x2560x24" java -jar selenium-server-standalone-2.48.1.jar

    之后你就可以正常运行测试了

    【讨论】:

      【解决方案2】:

      一切都按预期工作,但我需要代码才能在 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

      【讨论】:

      • 问题是我需要在 Scrutinizer 中配置整个东西,对吗?设置主机,配置一个nginx服务器……对吧?
      • 您可以只在审查器中使用默认详细信息。
      猜你喜欢
      • 2015-03-09
      • 1970-01-01
      • 2015-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-07
      • 2018-09-19
      相关资源
      最近更新 更多