laravel / dusk

Laravel Dusk provides simple end-to-end testing and browser automation.
https://laravel.com/docs/dusk
MIT License
1.87k stars 319 forks source link

Laravel Dusk on Travis CI return errors "Unable to locate element" #564

Closed henryonsoftware closed 5 years ago

henryonsoftware commented 5 years ago

Hello everyone! I'm developing Browser Test using Dusk. I can run php artisan dusk on my local and it's worked. But when I integrated with Travis CI, it's returned errors.

Error

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

Link error on Travis here

.travis.yml

sudo: required

dist: trusty

language: php

php:
  - '7.2'

addons:
   chrome: stable

install:
   - cp .env.travis .env
   - composer self-update
   - travis_retry composer install --no-interaction --prefer-dist --no-suggest

before_script:
   - mysql -e 'create database pingtocoffee_test;'
   - php artisan key:generate
   - php artisan migrate --force
   - google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &
   - php artisan serve &

script:
   - phpunit
   - php artisan dusk

.env.travis

# App name
APP_NAME="Ping to coffee"

# App environment. Have 3 values: local|testing|production
APP_ENV=local

# App secret key. Run `php artisan key:generate` to generate.
APP_KEY=ApplicationKey

# App debug, set true to turn on.
APP_DEBUG=false

# App URL
APP_URL=http://localhost

# App default timezone, set default (UTC + 00:00)
APP_DEFAULT_TIMEZONE=UTC

# Disable sign up option, set true to turn off sign up.
APP_DISABLE_SIGNUP=false

LOG_CHANNEL=stack

# Database connection information
DB_CONNECTION=testing
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=DatabaseName
DB_USERNAME=DatabaseUsername
DB_PASSWORD=DatabasePassword
DB_TEST_DATABASE=pingtocoffee_test
DB_TEST_USERNAME=root
DB_TEST_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120

# Queue driver: sync|database|beanstalkd|sqs|redis
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

# Mail configuration information
MAIL_DRIVER=MailProtocol
MAIL_HOST=MailHost
MAIL_PORT=MailPort
MAIL_USERNAME=MailUsername
MAIL_PASSWORD=MailPassword
MAIL_ENCRYPTION=MailEncryption
MAIL_FROM_ADDRESS=MailFromAddress
MAIL_FROM_NAME=MailFromName

# Pusher configuration information
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

# File system driver, config in config/filesystems.php.
# Ex: local|public|s3|...
FILESYSTEM_DRIVER=public

# Sentry DNS
SENTRY_LARAVEL_DSN=

LoginTest.php


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

class LoginTest extends DuskTestCase
{
    use DatabaseMigrations;

    /**
     * Test redirect after login.
     *
     * @throws \Throwable
     */
    public function testRedirectCorrectAfterLogin()
    {
        $user = $this->signUp();
        $this->browse(function (Browser $browser) use ($user) {
            $browser->visit(new Login())
                ->type("email", $user->email)
                ->type("password", "secret")
                ->press("Log In")
                ->assertPathIs("/dashboard");
        });
    }
}

I already tried this way but not work for me https://github.com/laravel/dusk/issues/454 Any help?

staudenmeir commented 5 years ago

Try APP_URL=http://127.0.0.1:8000 in your .env.travis file.

henryonsoftware commented 5 years ago

It's worked like a charm. Thanks so much @staudenmeir !