1
votes

I'm running into a Problem running tests on Travics CI with Laravel Dusk.

Locally every test is performing as expected but as soon as I execute them on Travis CI, I get the following errors.

I also replaced the selectors of the type method to ( ->type('email', $user->email) ) or (->type('#email', $user->email) no changes.

Full Error Log from Travis

Any ideas?

Cheers, Stan

Error

  1. 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)

sign in page

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 [
        ];
    }

user can sign in method

 public function a_user_can_sign_in()
        {
            $path = route('login');
    
            $user = factory(User::class)->create([
    
                'name' => 'Max Mustermann',
                'email' => '[email protected]',
                '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);
            });
        }

Login email balde element

<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 File

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
    [email protected]
    
    MAIL_DRIVER=log

Travis.yml File

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
The errors seems to be coming from a different test a_user_can_send_a_reset_password_email. - Camilo
The problem is that your unit tests use a chrome driver in order to open a browser. Travis doesn't use a x-server so it can't open a browser to simulate clicks. - Maël Pedretti
What @MaëlPedretti mentions is true. You will need to install additional packages to use Dusk within Travis. This is explained in the documentation. - Camilo
@Camilo Sorry, i had multiple of these errors. I updated the error messing to the showing example. - Stan Barrows
@MaëlPedretti I also followed the Example of the Larave Documentation. Same result. The way I used was just from another example. I've updated the travis.yml file as it shows in Laravels documentation. - Stan Barrows

1 Answers

0
votes

To make Dusk work with Travis CI you can update the APP_URL like this:

APP_URL=127.0.0.1:8000

Please see https://laravel.com/docs/6.x/dusk#continuous-integration for more information.