Laravel Dusk Travis Ci

时间:2018-02-28 13:05:19

标签: php laravel travis-ci laravel-dusk

我遇到了使用Laravel Dusk在Travics CI上运行测试的问题。

本地每个测试都按预期执行,但只要我在Travis CI上执行它,就会出现以下错误。

我还将类型方法的选择器替换为( - >类型('电子邮件',$ user->电子邮件))或( - >类型(' #mail&#) 39;,$ user->电子邮件)没有变化。

Travis的完整错误日志

有什么想法吗?

干杯,斯坦

错误

2) Tests\Browser\Tests\Auth\SignInTest::a_user_can_sign_in
Facebook\WebDriver\Exception\NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"body textarea[name='#email']"}
  (Session info: headless chrome=64.0.3282.186)
  (Driver info: chromedriver=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.4.0-101-generic x86_64)

登录页面

public function assert(Browser $browser)
    {
        $browser->assertPathIs($this->url());
    }

    public function signIn(Browser $browser, $email = null, $password = null)
    {
        $browser
            ->resize(1920, 1080)
            ->type('@login-email', $email)
            ->type('@login-password', $password)
            ->click('@login-button');
    }


    /**
     * Get the element shortcuts for the page.
     *
     * @return array
     */
    public function elements()
    {
        return [
        ];
    }

用户可以登录方法

 public function a_user_can_sign_in()
        {
            $path = route('login');

            $user = factory(User::class)->create([

                'name' => 'Max Mustermann',
                'email' => 'max.mustermann@testing.ch',
                'password' => bcrypt('password')

            ]);

            $this->browse(function ($browser) use ($path, $user) {
                $browser
                    ->visit(new SignInPage)
                    ->signIn($user->email, 'password')
                    ->assertPathIs('/backend/users/dashboard')
                    ->assertSeeIn('.navbar', $user->name);
            });
        }

登录电子邮件balde元素

<div class="form-group row">

                            <div class="col-lg-8 offset-2">
                                <input   dusk="login-email"
                                        title="E-mail"
                                        placeholder="E-mail"
                                        id="email"
                                        type="email"
                                        class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}"
                                        name="email"
                                        value="{{ old('email') }}"
                                        required
                                        autofocus
                                >

                                @if ($errors->has('email'))
                                    <div class="invalid-feedback">
                                        <strong>{{ $errors->first('email') }}</strong>
                                    </div>
                                @endif
                            </div>
                        </div>

.env Dusk文件

APP_NAME=Testing
    APP_ENV=testing
    APP_KEY=
    APP_DEBUG=true
    APP_LOG_LEVEL=debug
    APP_URL=http://do.testing.test

    DB_CONNECTION=pgsql
    DB_DATABASE=testing
    DB_USERNAME=postgres
    DB_PASSWORD=

    BROADCAST_DRIVER=log
    CACHE_DRIVER=array
    SESSION_DRIVER=database
    QUEUE_DRIVER=sync

    MAIL_FROM_NAME= Testing
    MAIL_FROM_ADDRESS=do@testing.test

    MAIL_DRIVER=log

Travis.yml文件

sudo: true

dist: trusty

language: php

env:
  global:
    - CC_TEST_REPORTER_ID=

addons:
  chrome: stable

  code_climate:
    repo_token:
      secure:

php:
  - 7.2

services:
  - redis-server
  - postgres

before_script:
   - psql -c 'create database testing;' -U postgres
   - cp .env.travis .env
   - cp phpunit.travis.xml phpunit.xml

    - google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &
    - php artisan serve &

install:
   - travis_retry composer install --no-interaction --prefer-dist --no-suggest

   - cp .env.travis .env
   - cp phpunit.travis.xml phpunit.xml

   - php artisan key:generate

script:
  - phpunit
  - php artisan dusk

after_script:
  - vendor/bin/test-reporter

after_success:
  - chmod +x ./tests.sh; ./tests.sh

1 个答案:

答案 0 :(得分:0)

要使Dusk与Travis CI配合使用,您可以像这样更新APP_URL:

APP_URL=127.0.0.1:8000

有关更多信息,请参见https://laravel.com/docs/6.x/dusk#continuous-integration