dusk: Laravel Dusk on Travis CI - Unable to locate element

Hello together. I’m currently facing a problem with Laravel Dusk on Travis CI.

Error

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)

Local Environment I’ve to mention that all tests (phpunit & dusk) are working on my local machine.

Travis Environment Except of the tests where an element is needed als tests are working as well.

Set Travis ENV as well. Link to Travis-CI Test-Message Full Error Message Log from Travis-CI

I also tried different ways of selecting the element like:

  • -> type(‘email’, $user->email)
  • ->type(‘@email’, $user->email and then define it in the elements method.

#454 Checked already this out. Not working as well for me. Unfortunately am at the end with my knowledge… any suggestions?

Cheers, Stan

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

Sign-In-Test

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);
            });
        }

Login Template Blade

<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.testing

    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

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (8 by maintainers)

Most upvoted comments

This problem is solved easily, specifying the url in the .env file, in my case, as I am using a virtual host, change APP_URL = http: //app.local instead of APP_URL = http: // localhost (by default in laravel). This way you can access the view and laravel dusk can find the input and what you define to complete your test.