如何使用具有码头组成的laravel黄昏?

时间:2018-06-18 03:25:12

标签: php laravel laravel-5 laravel-5.6 laravel-dusk

对不起,我的英语不流利...... 我有一些问题。

我正在使用docker-compose为Laravel应用程序创建开发环境。 当我构建测试时,我无法使用Laravel Dusk ......

docker-compose.yml

version: '2' 

services:
  web: 
    build: ./docker-config/php
    volumes:
      - .:/var/www
    depends_on:
      - mysql

  nginx: 
    image: nginx
    ports:
      - "80:80"
    volumes:
      - .:/var/www
      - ./docker-config/nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - web

  mysql:
    image: mysql:5.7
    environment:
      MYSQL_DATABASE: development
      MYSQL_ROOT_USER: root 
      MYSQL_ROOT_PASSWORD: testdb 
      MYSQL_USER: test 
      MYSQL_PASSWORD: testdb
    volumes:
      - db-data:/var/lib/mysql

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    environment:
      - PMA_ARBITRARY=1
      - PMA_HOST=mysql
      - PMA_USER=root
      - PMA_PASSWORD=testdb
    links:
      - mysql
    ports:
      - 8080:80
    volumes:
      - /sessions

  selenium:
    image: selenium/standalone-chrome
    ports:
      - 4444:4444

volumes:
  db-data:
    driver: local

DuskTestCase.php

<?php

namespace Tests;

use Laravel\Dusk\TestCase as BaseTestCase;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;

abstract class DuskTestCase extends BaseTestCase
{
    use CreatesApplication;

    protected function baseUrl()
    {
        return 'http://nginx';
    }

    /**
     * Prepare for Dusk test execution.
     *
     * @beforeClass
     * @return void
     */
    public static function prepare()
    {
       //static::startChromeDriver();
    }

    /**
     * Create the RemoteWebDriver instance.
     *
     * @return \Facebook\WebDriver\Remote\RemoteWebDriver
     */
    protected function driver()
    {
        $options = (new ChromeOptions)->addArguments([
            '--disable-gpu',
            '--headless'
        ]);

        return RemoteWebDriver::create(
            'http://selenium:4444/wd/hub', DesiredCapabilities::chrome()->setCapability(
                ChromeOptions::CAPABILITY, $options)>setCapability(ChromeOptions::CAPABILITY, $options
            )
        );
    }
}

ExampleTest.php

<?php

namespace Tests\Browser;

use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;

class ExampleTest extends DuskTestCase
{
    /**
     * A basic browser test example.
     *
     * @return void
     */
    public function testBasicExample()
    {
        $this->browse(function (Browser $browser) {
            $browser->visit('/')
                    ->assertSee('Laravel');
        });
    }
}

我可以访问“http://localhost”并看到文字“Laravel”。

docker-compose exec web php artisan dusk 在我发出错误消息之后。 我试试docker-compose run web composer update facebook/webdriver。但我看到一些错误......

There was 1 error:

1) Tests\Browser\ExampleTest::testBasicExample
Error: Call to undefined method 
Facebook\WebDriver\Remote\RemoteWebDriver::getCapabilities()

/var/www/vendor/laravel/dusk/src/Browser.php:257
/var/www/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:152
/var/www/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:153
/var/www/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:77
/var/www/tests/Browser/ExampleTest.php:21

ERRORS!
Tests: 1, Assertions: 1, Errors: 1.

有什么问题?

1 个答案:

答案 0 :(得分:0)

我不确定这个错误的实际原因(我的代码与您的代码相似似乎有点不同),但肯定是符合:

ChromeOptions::CAPABILITY, $options)>setCapability(ChromeOptions::CAPABILITY, $options

您在-

之前错过了>setCapability

应该是:

ChromeOptions::CAPABILITY, $options)->setCapability(ChromeOptions::CAPABILITY, $options