Giter Site home page Giter Site logo

chilio / laravel-dusk-ci Goto Github PK

View Code? Open in Web Editor NEW
159.0 7.0 51.0 355 KB

Docker Test suite for Laravel Dusk in gitlab CI

License: MIT License

Shell 21.93% PHP 31.54% Dockerfile 46.53%
gitlab-ci laravel-dusk docker dusk chromedriver phpunit ci-test browser-testing browser-tests dusk-tests

laravel-dusk-ci's Introduction

Browser Tests with Laravel Dusk in Gitlab CI/CD Pipelines.

Docker pulls GitHub issues GitHub stars GitHub license

This is a complete test suite for running tests (Unit, Feature, Browser) on your Laravel installation.

It uses Laravel Dusk for browser tests via a Docker executor runner in GitLab.

With this package, you don't need to worry, about Chrome or chromedriver compatibility. This is done automatically, to make your Browser Testing with Laravel Dusk, as easy, as possible.

Versions:

Deprecated versions:

Laravel dusk? Find more in Laravel Docs Laravel 10.x | Laravel 9.x | Laravel 8.x | Laravel 7.x | Laravel 6.x | Laravel 5.8

Gitlab? Find more on gitlab

Gitlab Continous Integration CI ? Find more on gitlab-runner

You may be wondering why deprecated versions are still available. The main reason is to allow for browser testing of your older Laravel applications while you're transitioning to newer versions.

This plug-and-play package is designed for your CI testing environment in GitLab.

All you need to do is select the appropriate version of your PHP interpreter (based on your Laravel version), and you should be ready to go.

Colours indicate the current state of PHP's life cycle and supported versions. Please note that all published images are fully functional and entirely usable for testing purposes.

Compatibility

LARAVEL VERSION COMPATIBLE PHP VERSIONS
10.x YES
9.x YES
8.x YES
7.x YES
6.x YES
5.8 YES
5.7 YES
5.6 YES
5.5 YES
5.4 Reported working
5.3 and below Not tested

With no modifications needed, you should be up and running in seconds. However, please carefully read the notes that follow.

For now DuskTestCase.php needs to be modified in all cases. THIS package is not going to work without -no-sandbox directive in this file.... Please read more about it, under Usage...

In case of any issues, please read the current documentation thoroughly, check existing issues (including closed ones) on GitHub, and finally, report a new issue on GitHub.

If this package proves to be useful to you, please star it on Docker Hub or GitHub to increase its visibility to other users.

Changelog

  • 2023-12-30 - stable tag refers php-8.2 from now on

  • 2023-12-30 - latest tag refers php-8.3 from now on

  • 2023-12-20 - php-8.3 tag released with latest versions of chrome and chromedriver

  • 2023-04-29 - latest tag refers php-8.2 from now on

  • 2022-12-16 - php-8.2 tag added with thanks to @pepijnolivier

  • 2022-12-16 - Latest chromedriver compatibility updated up to v.109

  • 2022-09-01 - latest tag refers php-8.1 from now on

  • 2022-09-01 - Latest chromedriver compatibility updated up to v.105 with thanks to @Velzeboer

  • 2022-04-16 - Laravel 9 compatibility confirmed

  • 2022-04-16 - php-8.1 tag added

  • 2022-04-16 - Latest chromedriver compatibility updated up to v.101

  • 2021-11-03 - Latest chromedriver compatibility updated up to v.96

  • 2021-11-03 - stable tag refers php-7.4 from now on

  • 2021-10-28 - latest tag refers php-8.0 from now on and stable tag refers to php-7.2

  • 2021-10-28 - php imagick extension added to all images except deprecated php-7.1

  • 2021-10-12 - Latest chromedriver compatibility updated up to v.95

  • 2021-01-29 - Latest chromedriver compatibility updated up to v.89

  • 2020-12-03 - PHP 8.0 version released in php-8.0 tag + latest chromedriver compatibility updated

  • 2020-10-23 - PHP 8.0 RC in php-8.rc tag tested with Laravel 8

  • 2020-10-20 - Latest chromedriver compatibility updated up to v.87

  • 2020-09-15 - Laravel 8 compatibility confirmed in php-7.3, php-7.4 and latest tags

  • 2020-08-17 - Latest chromedriver compatibility updated v.85

  • 2020-05-15 - latest PHP versions, Laravel 7 compatibility confirmed

  • 2020-02-17 - Node updated to 12.x LTS

  • 2019-12-12 - Latest for now refers to PHP 7.4

  • 2019-12-12 - PHP 7.4 in php-7.4 tag

  • 2019-12-12 - Latest chromedriver compatibility updated v.78 & v.79

  • 2019-09-27 - Latest chromedriver compatibility updated v.77

  • 2019-09-24 - chilio/laravel-dusk-ci:old-stable is deprecated for now. Use it only with old Laravel versions (before 5.5)

  • 2019-05-06 - Latest chromedriver compatibility updated v.75

  • 2019-04-04 - Latest chromedriver compatibility updated v.74

  • 2018-12-20 - PHP 7.3 in php-7.3 tag

  • 2018-10-24 - Update to ubuntu:bionic (18.04), Install php-geos and link default php command to php7.2 in latest tag

  • 2018-10-09 - Updated to nodejs v8

  • 2018-10-06 - Latest chromedriver compatibility updated

  • 2018-07-24 - mysql 8.0 and mysql:latest are now supported, but you need to make some modifications to your .gitlab-ci.yml. Unfortunately for now you cannot simply run mysql in services, as it was before.

    Simple workaround, is to change in services: (everywhere you call mysql service) to:

services:
     - name: mysql:latest
       command: ["--default-authentication-plugin=mysql_native_password"]

You need to make sure your Laravel config/database.php has these modes array also:

'mysql' => [
            ...
            'prefix' => '',
            'strict' => true,
            'engine' => null,
            'modes'       => [
                'ONLY_FULL_GROUP_BY',
                'STRICT_TRANS_TABLES',
                'NO_ZERO_IN_DATE',
                'NO_ZERO_DATE',
                'ERROR_FOR_DIVISION_BY_ZERO',
                'NO_ENGINE_SUBSTITUTION',
            ],
        ],
  • 2018-05-14 - chilio/laravel-dusk-ci:stable ships now with php 7.2 and chrome versions check enabled
  • 2018-05-14 - chilio/laravel-dusk-ci:stable moved to chilio/laravel-dusk-ci:old-stable. If you encounter any problems use the old one, or post issues...
  • 2018-05-08 - Automatic Chrome and chromedriver versions check and fix - works only in chilio/laravel-dusk-ci:latest for now, if you experience errors with this please use chilio/laravel-dusk-ci:stable or chilio/laravel-dusk-ci:php-7.2
  • 2018-02-16 - New command introduced - versions - works only in chilio/laravel-dusk-ci:latest for now
  • 2018-02-15 - chilio/laravel-dusk-ci:latest - tested with Laravel 5.6 and dusk 3.0
  • 2017-12-20 - chilio/laravel-dusk-ci:latest uses php 7.2 from now on, as it is marked as working without issues
  • 2017-12-01 - php 7.2 support added, latest tag refers still to php 7.1 for now, so if you want to use 7.2, please choose exact docker tag : chilio/laravel-dusk-ci:php-7.2
  • 2017-09-10 - initial release, with php 7.1 for laravel 5.5

Documentation

What's included? (versions depend on image/tag)

Libs included
PHP
Xdebug
NGINX
Chromedriver
Chrome
NODEJS
NPM
YARN
BOWER
PHPUNIT
NODE-SASS
GULP

To see exact versions of installed packages, please run versions command in your script declaration in .gitlab-ci.yml, as in examples.

Available additional commands:

configure-laravel - sets up file permissions, generates laravel key, migrates and seeds db, checks and enforces chromedriver compatibility

start-nginx-ci-project - configures and starts nginx with php-fpm

versions - shows versions of included packages and enabled php modules.

Databases:

This build is tested with mysql, but also works with other docker db engines

To successfully run mysql add to your test routine:

services:

โ€‹ mysql:5.7 #or specify any downwards version of mysql. mysql:latest will not work out of the box, therefore please check changelog

And in your .env or your .env candidate file to use, mark mysql as the corresponding resource (DB_HOST=mysql)

If you receive errors like

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known

probably you have other mysql instance running in your host system with that name. In this case you may need to provide db-alias for your test. More info here

Usage:

Make sure your DuskTestCase class in /tests/DuskTestCase.php matches all attributes, like drive options, host url, and port, like in this example DuskTestCase.php # there are some modifications which you need to apply (especially --no-sandbox in $options for driver)!!!, these changes should not affect your local dev environment, otherwise there might be something else wrong with your project.

In your .gitlab-ci.yml use this image like:

image: chilio/laravel-dusk-ci:latest# you can experiment with other images, which might address your needs.

add script lines:

- cp .env.example .env # remember to have APP_URL=http://localhost and DB_HOST=mysql

- configure-laravel # preparations to run project

- start-nginx-ci-project # Here we start webserver, so this is important before running dusk

Finally you can run all your tests served by nginx | php-fpm via:

- php artisan dusk

Note on using chromedriver versions:

Laravel Dusk ships with included chromedriver for linux, mac and windows. The examples here allow you to run dusk tests with these included chromedrivers (for linux in this case).

As of 2018-05-08 this package automatically fixes eventual problems with chrome or chromedriver. Therefore following changes to your app should not be necessary.

However, if you encounter problems, especially errors, with incorrect chromedriver version on your local machine, or this docker image, you can use, this package inbuilt own chromedriver. This option brings, a little bit more compatibility to your project, since Chrome is updated much more often, then chromedriver. In order to do that, you need to make only 2 script modifications:

  1. In DuskTestCase.php comment out starting chromedriver like// static::startChromeDriver();. In that case, to make your local development working, before issuing php artisan dusk command, you need to install proper chromedriver version manually, and make sure your chromedriver version matches Chrome, running on your local machine. You need to make sure chromedriver is started/running also. Due to different systems and configurations, that's beyond the scope of this documentation. Just to make clear here, in this case you are responsible for updating your own chromedriver with your current installation of Chrome. Since Chrome updates are pretty often, that's the suggested way to go, to keep your local dev running, while other packages are a little behind...
  2. In .gitlab-ci.yml add - chromedriver & before running - php artisan dusk. This will start system inbuilt chromedriver and not the one, that is shipped with laravel dusk, cause it might be outdated and causing problems with your local development.

Further example script commands (if needed in your case):

- cp phpunit.xml.ci phpunit.xml # In case ,you don't want to interfere, with your local test environment, you can apply this approach for ci tests. Make sure, to create phpunit.xml.ci, in your project and phpunit.dusk.xml. You can specify, 2 separate files for your tests, one for phpunit and one for dusk, you can use examples, from this repo or modify them to suite your needs...

- composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts

- bower install --quiet

- npm run dev or if you are on yarn registry - yarn run dev

- ./vendor/phpunit/phpunit/phpunit -v --coverage-text --colors --stderr# to run phpunit with version specified in your project

Examples:

DuskTestCase.php # with all modifications to successfully run php artisan dusk tests

phpunit.dusk.xml # If exists in project root, this file will be automatically injected when dusk is run, in case, you want to define any custom variables for your tests like DBs, Caches etc.

phpunit.xml.ci # in case, you want to customize phpunit tests in CI , remember to copy this to phpunit.xml by adding - cp phpunit.xml.ci phpunit.xml to your gitlab-ci.yml.

gitlab-ci.yml # with stages, cache, and artifacts, assuming you are using scripts like "dev" in package.json.

Troubleshooting:

  • If you encounter problems, try different versions in this order: chilio/laravel-dusk-ci:latest, chilio/laravel-dusk-ci:stable and finally chilio/laravel-dusk-ci:dev which should solve your issues straight away...
  • You can always try specific PHP version like for example chilio/laravel-dusk-ci:php-7.3
  • In your dusk tests remember to use ->waitFor() extensively, to make sure, your pages are rendered properly, before test fails. Usually, CI test environments are much slower, than production or your local dev, cause they need to build caches from scratch.
  • By default, all dusk browser tests are run with resolution 1920x720 with color depth 24 (bits), if you need to change that, add/modify SCREEN_RESOLUTION in your .gitlab-ci.yml in variables: section, like for example SCREEN_RESOLUTION: 1280x720x24
  • if you experience /bootstrap/autoload.php errors, make sure your appropriate phpunit configs are updated, especially in line bootstrap="vendor/autoload.php"
  • if you get errors, about wrong chromedriver version, or errors about Laravel dusk not able to connect on port 9515, please check Note on using chromedriver versions
  • if you get warning about mysql Service runner probably didn't start properly or other strange behaviours make sure to remove all cache and artifacts routines. Depending on your workflow, they might introduce problems to your tests

Disclaimer

Images mentioned above are intended for testing purposes in CI environments only. Production usage is not recommended.

laravel-dusk-ci's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-dusk-ci's Issues

Failed to open storage/logs/laravel.log: Permission denied

I'm using your excellent Docker image in GitLab CI. Thank you!! But I seem to have one problem.

In my Dusk tests, (which are all failing), my screenshots return a Laravel error page that says this:

The stream or file ".../storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied.

But the "storage" and "logs" directories exist with 777 permissions and are owned by www-data.www-data. What more do I need?

I'm using chilio/laravel-dusk-ci:php-8.0

Thank you!

Permission denied for cache files

Hi,

First, thank you for the great work. Setting up Dusk with this docker container was a breeze.

However, I'm running into some issues with file permissions. The following (last part of) the build shows an error occuring in one of the tests. This error occurs because the webserver is unable to create a cache file.

$ chmod -R 775 storage
$ chmod 775 bootstrap/cache
$ chown -R www-data:www-data ./
$ ls -al storage/framework/cache
total 24
drwxrwxr-x. 2 www-data www-data 4096 Sep 29 20:53 .
drwxrwxr-x. 5 www-data www-data 4096 Sep 29 20:53 ..
-rwxrwxr-x. 1 www-data www-data   14 Sep 29 20:53 .gitignore
$ start-nginx-ci-project
 * Starting nginx nginx
   ...done.
$ php artisan dusk || true
Warning: TTY mode requires /dev/tty to be read/writable.
PHPUnit 7.3.5 by Sebastian Bergmann and contributors.

...............F.......                                           23 / 23 (100%)

Time: 1.8 minutes, Memory: 32.00MB

There was 1 failure:

1) Tests\Browser\MapSettingsTest::test_can_store_regions
Did not see expected text [Regions saved.] within element [body].
Failed asserting that false is true.

/builds/project/vendor/laravel/dusk/src/Concerns/MakesAssertions.php:173
/builds/project/vendor/laravel/dusk/src/Concerns/MakesAssertions.php:144
/builds/project/tests/Browser/MapSettingsTest.php:76
/builds/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:67
/builds/project/tests/Browser/MapSettingsTest.php:77

FAILURES!
Tests: 23, Assertions: 74, Failures: 1.
$ ls -al storage/framework/cache
total 40
drwxrwxr-x. 4 www-data www-data 4096 Sep 29 20:54 .
drwxrwxr-x. 5 www-data www-data 4096 Sep 29 20:53 ..
drwxr-xr-x. 3 root     root     4096 Sep 29 20:54 5a
drwxr-xr-x. 3 www-data www-data 4096 Sep 29 20:54 85
-rwxrwxr-x. 1 www-data www-data   14 Sep 29 20:53 .gitignore

Given the following gitlab yml:

browser test:
  stage: integration_test
  services:
  - mysql:5.7
  image: chilio/laravel-dusk-ci:php-7.2
  artifacts:
    paths:
    - ./storage/logs
    - ./tests/Browser/screenshots
    - ./tests/Browser/console
    expire_in: 1 days
    when: always
  before_script:
  - composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
  - apt-get purge php-xdebug -y
  - cp .env.dusk .env
  - chmod -R 775 storage
  - chmod 775 bootstrap/cache
  - chown -R www-data:www-data ./
  - ls -al storage/framework/cache
  - start-nginx-ci-project
  script:
  - php artisan dusk || true
  - ls -al storage/framework/cache

I'm confused, because the build output shows files created as root. I was under the impression that the php process would be running as www-data.

Any input is appreciated.

Memory limit?

Hi there,

I started encountering :

Allowed memory size of 134217728 bytes exhausted (tried to allocate 33585608 bytes)

In my app and was wondering if/where I could change the memory limit?

THanks

Multiple runners at same time

Hi there,

Would it be easy to setup two or more runners to split tests?

Our CI has lots of tests and it now takes >20mn to run.

Thanks

The process started from chrome location /chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.

Hi,

I'm using your image for my dusk test but it seems chrome driver sucks!

here is my .gitlab-ci.yml file

image: chilio/laravel-dusk-ci
services:
  - mysql:5.7

cache:
  untracked: true
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - node_modules
    - vendor
    - /root/.composer
    - /root/.npm

variables:
  MYSQL_DATABASE: mysql_database
  MYSQL_ROOT_PASSWORD: secret

stages:
  - tests

browser:
  stage: tests
  script:
    - cp .env.gitlab .env
    - composer install
    - npm install
    - npm run production
    - configure-laravel
    - start-nginx-ci-project
    - sleep 3
    - php artisan dusk
  artifacts:
    name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
    paths:
      - tests/Browser/screenshots/
    expire_in: 2 weeks
    when: always

the problem which I've faced with is it seems chromedriver does not run correctly or something!

$ configure-laravel
Application key [base64:D/JwKTvwukrg6cCT5bMt2/hVK3F7G6n2Fj7kmTDKGaQ=] set successfully.
Dropped all tables successfully.
Migration table created successfully.
#### MIGRATIONS ####
#### SEEDINGS  ####
System Chrome version: 69
System Chromedriver version: 2.42
Laravel Chromedriver version: 2.35
Chromedriver shipped with your Laravel installation is NOT compatible with this systems chrome version!
Don't worry, we are fixing this right now, so you will be able, to test your app anyway.
You can always read more about running tests with system inbuilt chromedriver in laravel-dusk-ci docs.
Scheduled start of inbuilt Chromedriver (2.42). Chromedriver will be ready soon...
Starting ChromeDriver 2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac) on port 9515
Only local connections are allowed.
[1538992522.833][SEVERE]: bind() returned an error, errno=99: Cannot assign requested address (99)
$ start-nginx-ci-project
 * Starting nginx nginx
   ...done.
$ sleep 3
$ php artisan dusk
Warning: TTY mode requires /dev/tty to be read/writable.
PHPUnit 7.3.5 by Sebastian Bergmann and contributors.

EE                                                                  2 / 2 (100%)

Time: 1.18 seconds, Memory: 18.00MB

There were 2 errors:

1) Tests\Browser\WhiteDownloadAppTest::testActive
Facebook\WebDriver\Exception\UnknownServerException: unknown error: Chrome failed to start: exited abnormally
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 3.10.0-862.9.1.el7.x86_64 x86_64)

/builds/inpin/landing/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:114
/builds/inpin/landing/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:326
/builds/inpin/landing/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:126
/builds/inpin/landing/tests/DuskTestCase.php:40
/builds/inpin/landing/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:192
/builds/inpin/landing/vendor/laravel/framework/src/Illuminate/Support/helpers.php:750
/builds/inpin/landing/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:193
/builds/inpin/landing/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:93
/builds/inpin/landing/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:64
/builds/inpin/landing/tests/Browser/WhiteDownloadAppTest.php:50

2) Tests\Browser\WhiteDownloadAppTest::testInactive
Facebook\WebDriver\Exception\UnknownServerException: unknown error: Chrome failed to start: exited abnormally
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 3.10.0-862.9.1.el7.x86_64 x86_64)

/builds/inpin/landing/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:114
/builds/inpin/landing/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:326
/builds/inpin/landing/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:126
/builds/inpin/landing/tests/DuskTestCase.php:40
/builds/inpin/landing/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:192
/builds/inpin/landing/vendor/laravel/framework/src/Illuminate/Support/helpers.php:750
/builds/inpin/landing/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:193
/builds/inpin/landing/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:93
/builds/inpin/landing/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:64
/builds/inpin/landing/tests/Browser/WhiteDownloadAppTest.php:73

ERRORS!
Tests: 2, Assertions: 0, Errors: 2.
Uploading artifacts...
tests/Browser/screenshots/: found 2 matching files 
Uploading artifacts to coordinator... ok            id=2302 responseStatus=201 Created token=_YoXGK5K
ERROR: Job failed: exit code 1

but every thing on my local machin runs correctly!

even I've tried to use the chromedriver-linux file from the vendor\laravel\dusk\bin and the other versions of chromedriver (version 2.40, 2.38 and 2.35) which I've downloaded directly form http://chromedriver.chromium.org but with all of them after sometimes (about 1 or 2 minuts) the error of Operation timed out after 30001 milliseconds with 0 bytes received has been shown.

did I do something wrong?

I'm using laravel 5.7 and dusk 4.0 (both the latest version).

port to github actions

wondering if this is in the works?

im able to jam it in my github actions and run some dusk tests. but im pretty sure im not doing it very elegantly. would be nice to have an "official" way

also, i can't figure out how to get the native pwd figured out for mysql8. i saw you asking about it here: docker-library/mysql#454 and not much help offered

Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session/{somehash}/log with params: {"type":"browser"} Operation timed out after 30001 milliseconds with 0 bytes received

I have been using stable image for CI/CD in gitlab.

I always come across this issue with laravel dusk testing:
Error:
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session/{some hash}/log with params: {"type":"browser"}
Operation timed out after 30001 milliseconds with 0 bytes received

Normally, it fails for one or more larave dusk tests.
It happens with random tests.

Note: i did notice the mismatch between chrome version on system and with container but eventually, it switches to built-in chrome driver so, i dont think that's issue.

Any suggestions?

Issue with 7.2

Hi,

I am getting this error, using chilio/laravel-dusk-ci:php-7.2

$ php -v PHP Warning: PHP Startup: Unable to load dynamic library 'lua.so' (tried: /usr/lib/php/20180731/lua.so (/usr/lib/php/20180731/lua.so: undefined symbol: ZEND_HASH_GET_APPLY_COUNT), /usr/lib/php/20180731/lua.so.so (/usr/lib/php/20180731/lua.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'mailparse.so' (tried: /usr/lib/php/20180731/mailparse.so (/usr/lib/php/20180731/mailparse.so: undefined symbol: mbfl_convert_filter_flush), /usr/lib/php/20180731/mailparse.so.so (/usr/lib/php/20180731/mailparse.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP 7.3.3-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Mar 7 2019 20:31:26) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.3, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.3-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies with Xdebug v2.7.0, Copyright (c) 2002-2019, by Derick Rethans

Am I doing something wrong or is there a fault in the docker image?

Dusk result give a false positive

I'm currently working on a full pipe check based of ohdear's config (https://github.com/ohdearapp/gitlab-ci-pipeline-for-laravel)
I added a dusk part using this docker image and if the tests fails I still have Gitlab telling me it succeded.

You can check the dusk job config here :

dusk:
  stage: testing
  image: chilio/laravel-dusk-ci
  services:
    - name: mysql:8.0
      command: ["--default-authentication-plugin=mysql_native_password"]
  dependencies:
    - build-assets
    - composer
    - db-seeding
  script:
    - php -v
    - mysql --host="${DB_HOST}" --user="${MYSQL_USER}" --password="${MYSQL_PASSWORD}" "${MYSQL_DATABASE}" < db.sql
    - google-chrome --version
    # Upgrade Chrome Driver
    - php artisan dusk:chrome-driver 77
    - start-nginx-ci-project
    # Run Dusk Tests
    - php artisan dusk --colors --debug
  artifacts:
    paths:
      - storage/logs # for debugging
      - tests/Browser/screenshots
      - tests/Browser/console
    expire_in: 1 days
    when: always

And here is what I get as an output if I make it fail


ERRORS!
Tests: 41, Assertions: 0, Errors: 41.
Uploading artifacts...
storage/logs: found 2 matching files               
tests/Browser/screenshots: found 2 matching files  
tests/Browser/console: found 2 matching files      
Uploading artifacts to coordinator... ok            id=338202026 responseStatus=201 Created token=6t_BaFoR
Job succeeded

Any idea where it could come from ?

PHP7.4 | php-imagick extension not found or not enabled

Hi,
I've been using laravel-dusk-ci for months without issues.
Today I'm deploying the same project, with insignificant modification, after 15 days, when I deployed for the last time.

I checked and Imagemagick is installed as well php-imagick, but it does not appear among the enabled modules.

I have this log:


Problem 1
    - Root composer.json requires PHP extension ext-imagick * but it is missing from your system. Install or enable PHP's imagick extension.
To enable extensions, verify that they are enabled in your .ini files:
    - /etc/php/7.4/cli/php.ini
    - /etc/php/7.4/cli/conf.d/10-mysqlnd.ini
    - /etc/php/7.4/cli/conf.d/10-opcache.ini
    - /etc/php/7.4/cli/conf.d/10-pdo.ini
    - /etc/php/7.4/cli/conf.d/15-xml.ini
    - /etc/php/7.4/cli/conf.d/20-bcmath.ini
    - /etc/php/7.4/cli/conf.d/20-bz2.ini
    - /etc/php/7.4/cli/conf.d/20-calendar.ini
    - /etc/php/7.4/cli/conf.d/20-ctype.ini
    - /etc/php/7.4/cli/conf.d/20-curl.ini
    - /etc/php/7.4/cli/conf.d/20-dba.ini
    - /etc/php/7.4/cli/conf.d/20-dom.ini
    - /etc/php/7.4/cli/conf.d/20-enchant.ini
    - /etc/php/7.4/cli/conf.d/20-exif.ini
    - /etc/php/7.4/cli/conf.d/20-ffi.ini
    - /etc/php/7.4/cli/conf.d/20-fileinfo.ini
    - /etc/php/7.4/cli/conf.d/20-ftp.ini
    - /etc/php/7.4/cli/conf.d/20-gd.ini
    - /etc/php/7.4/cli/conf.d/20-geoip.ini
    - /etc/php/7.4/cli/conf.d/20-gettext.ini
    - /etc/php/7.4/cli/conf.d/20-gmp.ini
    - /etc/php/7.4/cli/conf.d/20-iconv.ini
    - /etc/php/7.4/cli/conf.d/20-imap.ini
    - /etc/php/7.4/cli/conf.d/20-intl.ini
    - /etc/php/7.4/cli/conf.d/20-json.ini
    - /etc/php/7.4/cli/conf.d/20-ldap.ini
    - /etc/php/7.4/cli/conf.d/20-mbstring.ini
    - /etc/php/7.4/cli/conf.d/20-mysqli.ini
    - /etc/php/7.4/cli/conf.d/20-odbc.ini
    - /etc/php/7.4/cli/conf.d/20-pdo_dblib.ini
    - /etc/php/7.4/cli/conf.d/20-pdo_firebird.ini
    - /etc/php/7.4/cli/conf.d/20-pdo_mysql.ini
    - /etc/php/7.4/cli/conf.d/20-pdo_odbc.ini
    - /etc/php/7.4/cli/conf.d/20-pdo_pgsql.ini
    - /etc/php/7.4/cli/conf.d/20-pdo_sqlite.ini
    - /etc/php/7.4/cli/conf.d/20-pgsql.ini
    - /etc/php/7.4/cli/conf.d/20-phar.ini
    - /etc/php/7.4/cli/conf.d/20-posix.ini
    - /etc/php/7.4/cli/conf.d/20-propro.ini
    - /etc/php/7.4/cli/conf.d/20-pspell.ini
    - /etc/php/7.4/cli/conf.d/20-radius.ini
    - /etc/php/7.4/cli/conf.d/20-raphf.ini
    - /etc/php/7.4/cli/conf.d/20-readline.ini
    - /etc/php/7.4/cli/conf.d/20-shmop.ini
    - /etc/php/7.4/cli/conf.d/20-simplexml.ini
    - /etc/php/7.4/cli/conf.d/20-snmp.ini
    - /etc/php/7.4/cli/conf.d/20-soap.ini
    - /etc/php/7.4/cli/conf.d/20-sockets.ini
    - /etc/php/7.4/cli/conf.d/20-sqlite3.ini
    - /etc/php/7.4/cli/conf.d/20-stomp.ini
    - /etc/php/7.4/cli/conf.d/20-sysvmsg.ini
    - /etc/php/7.4/cli/conf.d/20-sysvsem.ini
    - /etc/php/7.4/cli/conf.d/20-sysvshm.ini
    - /etc/php/7.4/cli/conf.d/20-tideways.ini
    - /etc/php/7.4/cli/conf.d/20-tidy.ini
    - /etc/php/7.4/cli/conf.d/20-tokenizer.ini
    - /etc/php/7.4/cli/conf.d/20-uploadprogress.ini
    - /etc/php/7.4/cli/conf.d/20-xmlreader.ini
    - /etc/php/7.4/cli/conf.d/20-xmlrpc.ini
    - /etc/php/7.4/cli/conf.d/20-xmlwriter.ini
    - /etc/php/7.4/cli/conf.d/20-xsl.ini
    - /etc/php/7.4/cli/conf.d/20-zip.ini
    - /etc/php/7.4/cli/conf.d/25-http.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

Imagick not found

Hi,
I've been using laravel-dusk-ci for months without issues.
Today I'm deploying the same project, with insignificant modification, after 15 days, when I deployed for the last time.
I have this log:

Using docker image sha256:632ebeed8b4da381bec26e66c5416bf06faa59a1f575a65d22ce8cd888ba9f74 for chilio/laravel-dusk-ci:php-7.4 with digest chilio/laravel-dusk-ci@sha256:b438203ef7409ddab8a79976262a7061fda175cc39d3425df334f2673826b322 ...
$ ./vendor/bin/phpunit --version && ./vendor/bin/phpunit -v tests/Feature
PHPUnit 9.5.4 by Sebastian Bergmann and contributors.
PHPUnit 9.5.4 by Sebastian Bergmann and contributors.
Runtime:       PHP 7.4.21
Configuration: /builds/onde-alte/civic-hack/phpunit.xml
.........................EEEE.......................EEEE.......  63 / 288 ( 21%)
........................EEEEEE................................. 126 / 288 ( 43%)
.........................................................F..... 189 / 288 ( 65%)
F.............................................................. 252 / 288 ( 87%)
.................EE...............
Time: 01:39.283, Memory: 151.00 MB
There were 16 errors:
1) Tests\Feature\CaseStudy\CaseStudyImagesUploadTest::it_uploads_a_new_case_study_image
Error: Class 'Imagick' not found
/builds/onde-alte/civic-hack/app/Libs/Utils/ImageProcessors/ImageProcessor.php:22
/builds/onde-alte/civic-hack/app/Http/Controllers/Stubs/StubImageController.php:43
/builds/onde-alte/civic-hack/app/Http/Controllers/Stubs/StubFileController.php:111
/builds/onde-alte/civic-hack/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
/builds/onde-alte/civic-hack/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:45

It's strange. Imagick always was in this image. Did you change smt recently?

not connected to DevTools

Hi @chilio ,
Thanks for your great work,
I am using your image since a month I am setting it up with a gitlab ci yml file.
But I keep getting the error
[WARNING]: Unable to evaluate script: disconnected: not connected to DevTools
after the 3rd or 4th tests
and sometime it comes
Facebook\WebDriver\Exception\UnrecognizedExceptionException: chrome not reachable or
Facebook\WebDriver\Exception\NoSuchDriverException: invalid session id

Any idea what can it cause I am having hard time trying but it does not work

Below is the log

System Chrome version: 70
System Chromedriver version: 2.43
Laravel Chromedriver version: 2.35
Chromedriver shipped with your Laravel installation is NOT compatible with this systems chrome version!
Don't worry, we are fixing this right now, so you will be able, to test your app anyway.
You can always read more about running tests with system inbuilt chromedriver in laravel-dusk-ci docs.
Scheduled start of inbuilt Chromedriver (2.43). Chromedriver will be ready soon...
$ start-nginx-ci-project
Starting ChromeDriver 2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d) on port 9515
Only local connections are allowed.
[1540405389.987][SEVERE]: bind() returned an error, errno=0: Cannot assign requested address (99)
 * Starting nginx nginx
   ...done.
$ php artisan dusk --colors --debug
Warning: TTY mode requires /dev/tty to be read/writable.
PHPUnit 6.5.13 by Sebastian Bergmann and contributors.

Test 'Tests\Browser\AdminLoginTest::testInvalidLogin' started
Test 'Tests\Browser\AdminLoginTest::testInvalidLogin' ended
Test 'Tests\Browser\ProfileComponentTest::test_profile_page_working' started
Test 'Tests\Browser\ProfileComponentTest::test_profile_page_working' ended
Test 'Tests\Browser\ProfileComponentTest::test_profile_page_edit_modal_working' started
[1540405436.988][WARNING]: Unable to evaluate script: disconnected: not connected to DevTools
Test 'Tests\Browser\ProfileComponentTest::test_profile_page_edit_modal_working' ended
Test 'Tests\Browser\ProfileComponentTest::test_profile_page_language_modal_working' started
[1540405437.036][WARNING]: Unable to evaluate script: disconnected: not connected to DevTools
Test 'Tests\Browser\ProfileComponentTest::test_profile_page_language_modal_working' ended
Test 'Tests\Browser\ProfileComponentTest::test_profile_page_health_modal_working' started
[1540405437.080][WARNING]: Unable to evaluate script: disconnected: not connected to DevTools
Test 'Tests\Browser\ProfileComponentTest::test_profile_page_health_modal_working' ended
Test 'Tests\Browser\ProfileComponentTest::test_profile_page_allergy_modal_working' started
[1540405437.128][WARNING]: Unable to evaluate script: disconnected: not connected to DevTools
Test 'Tests\Browser\ProfileComponentTest::test_profile_page_allergy_modal_working' ended
Test 'Tests\Browser\ProfileComponentTest::test_profile_page_medical_history_working' started
[1540405437.175][WARNING]: Unable to evaluate script: disconnected: not connected to DevTools
Test 'Tests\Browser\ProfileComponentTest::test_profile_page_medical_history_working' ended
Test 'Tests\Browser\ProfileComponentTest::test_can_add_medication' started
Test 'Tests\Browser\ProfileComponentTest::test_can_add_medication' ended
Test 'Tests\Browser\UserRegistrationLoginTest::testLoginPage' started
Test 'Tests\Browser\UserRegistrationLoginTest::testLoginPage' ended
Test 'Tests\Browser\UserRegistrationLoginTest::testUserCanRegister' started
Test 'Tests\Browser\UserRegistrationLoginTest::testUserCanRegister' ended


Time: 1.36 minutes, Memory: 32.00MB

There were 6 errors:

1) Tests\Browser\ProfileComponentTest::test_profile_page_edit_modal_working
Facebook\WebDriver\Exception\UnrecognizedExceptionException: chrome not reachable
  (Session info: headless chrome=70.0.3538.67)
  (Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.4.0-1069-aws x86_64)

/builds/titans/project/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:158
/builds/titans/project/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:326
/builds/titans/project/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:547
/builds/titans/project/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:345
/builds/titans/project/vendor/laravel/dusk/src/Browser.php:244
/builds/titans/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:135
/builds/titans/project/vendor/laravel/framework/src/Illuminate/Support/Collection.php:339
/builds/titans/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:136
/builds/titans/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:69
/builds/titans/project/tests/Browser/ProfileComponentTest.php:55

2) Tests\Browser\ProfileComponentTest::test_profile_page_language_modal_working
Facebook\WebDriver\Exception\UnrecognizedExceptionException: chrome not reachable
  (Session info: headless chrome=70.0.3538.67)
  (Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.4.0-1069-aws x86_64)

/builds/titans/project/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:158
/builds/titans/project/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:326
/builds/titans/project/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:547
/builds/titans/project/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:345
/builds/titans/project/vendor/laravel/dusk/src/Browser.php:244
/builds/titans/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:135
/builds/titans/project/vendor/laravel/framework/src/Illuminate/Support/Collection.php:339
/builds/titans/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:136
/builds/titans/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:69
/builds/titans/project/tests/Browser/ProfileComponentTest.php:66

3) Tests\Browser\ProfileComponentTest::test_profile_page_health_modal_working
Facebook\WebDriver\Exception\UnrecognizedExceptionException: chrome not reachable
  (Session info: headless chrome=70.0.3538.67)
  (Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.4.0-1069-aws x86_64)

/builds/titans/project/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:158
/builds/titans/project/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:326
/builds/titans/project/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:547
/builds/titans/project/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:345
/builds/titans/project/vendor/laravel/dusk/src/Browser.php:244
/builds/titans/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:135
/builds/titans/project/vendor/laravel/framework/src/Illuminate/Support/Collection.php:339
/builds/titans/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:136
/builds/titans/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:69
/builds/titans/project/tests/Browser/ProfileComponentTest.php:77

4) Tests\Browser\ProfileComponentTest::test_profile_page_allergy_modal_working
Facebook\WebDriver\Exception\UnrecognizedExceptionException: chrome not reachable
  (Session info: headless chrome=70.0.3538.67)
  (Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.4.0-1069-aws x86_64)

/builds/titans/project/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:158
/builds/titans/project/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:326
/builds/titans/project/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:547
/builds/titans/project/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:345
/builds/titans/project/vendor/laravel/dusk/src/Browser.php:244
/builds/titans/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:135
/builds/titans/project/vendor/laravel/framework/src/Illuminate/Support/Collection.php:339
/builds/titans/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:136
/builds/titans/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:69
/builds/titans/project/tests/Browser/ProfileComponentTest.php:88

5) Tests\Browser\ProfileComponentTest::test_profile_page_medical_history_working
Facebook\WebDriver\Exception\UnrecognizedExceptionException: chrome not reachable
  (Session info: headless chrome=70.0.3538.67)
  (Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.4.0-1069-aws x86_64)

/builds/titans/project/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:158
/builds/titans/project/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:326
/builds/titans/project/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:547
/builds/titans/project/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:345
/builds/titans/project/vendor/laravel/dusk/src/Browser.php:244
/builds/titans/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:135
/builds/titans/project/vendor/laravel/framework/src/Illuminate/Support/Collection.php:339
/builds/titans/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:136
/builds/titans/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:69
/builds/titans/project/tests/Browser/ProfileComponentTest.php:99

6) Tests\Browser\UserRegistrationLoginTest::testUserCanRegister
Facebook\WebDriver\Exception\NoSuchDriverException: invalid session id
  (Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.4.0-1069-aws x86_64)

/builds/titans/project/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:100
/builds/titans/project/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:326
/builds/titans/project/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:547
/builds/titans/project/vendor/facebook/webdriver/lib/Remote/RemoteExecuteMethod.php:40
/builds/titans/project/vendor/facebook/webdriver/lib/WebDriverOptions.php:156
/builds/titans/project/vendor/laravel/dusk/src/Browser.php:259
/builds/titans/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:148
/builds/titans/project/vendor/laravel/framework/src/Illuminate/Support/Collection.php:339
/builds/titans/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:149
/builds/titans/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:77
/builds/titans/project/tests/Browser/UserRegistrationLoginTest.php:69
/builds/titans/project/tests/Browser/UserRegistrationLoginTest.php:57

Caused by
Facebook\WebDriver\Exception\NoSuchDriverException: invalid session id
  (Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.4.0-1069-aws x86_64)

/builds/titans/project/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:100
/builds/titans/project/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:326
/builds/titans/project/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:547
/builds/titans/project/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:345
/builds/titans/project/vendor/laravel/dusk/src/Browser.php:244
/builds/titans/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:135
/builds/titans/project/vendor/laravel/framework/src/Illuminate/Support/Collection.php:339
/builds/titans/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:136
/builds/titans/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:69
/builds/titans/project/tests/Browser/UserRegistrationLoginTest.php:69
/builds/titans/project/tests/Browser/UserRegistrationLoginTest.php:57

--```

ERROR: Job failed: exit code 1 on GitLab CI

I recently upgraded my site to PHP 8.1, and so I upgraded to the your PHP 8.1 image in my .gitlab-ci.yml file but now I get an error when it tries to build.

As you can see below, it seems to fail on the command npm run prod. But that command works locally, so I'm not sure what the problem is, and the error is not helpful. Is it a bug in the PHP 8.1 release of your image, or is it a problem with my configuration?

Here is the build section of .gitlab-ci.yml:

build:
  stage: build
  interruptible: true # When enabled, a running job can be cancelled when a new pipeline starts on the same branch.
  image: chilio/laravel-dusk-ci:php-8.1
  cache:
    - key:
        files:
          - composer.lock
      paths:
        - vendor/
    - key:
        files:
          - package-lock.json
      paths:
        - node_modules/
  script:
    - cp .env.gitlab-testing .env

    - composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts

    - npm ci
    - npm run prod

    - chmod -R 775 storage
    - chmod 775 bootstrap/cache
    - chown -R www-data ./
    - php artisan storage:link
  artifacts:
    name: "$CI_COMMIT_REF_NAME"
    paths:
      - .env
      - storage/
      - bootstrap/cache
      - vendor/
      - node_modules/
      - public/css/
      - public/js/
      - public/fonts/
    expire_in: 1 hour

And here's the output of the runner:

Running with gitlab-runner 14.10.1 (f761588f)
  on liddell2 h8o-Suv2
Preparing the "docker" executor
00:02
Using Docker executor with image chilio/laravel-dusk-ci:php-8.1 ...
Pulling docker image chilio/laravel-dusk-ci:php-8.1 ...
Using docker image sha256:b529d7fdffba447b7acfb6b41c705ce4b7e3257e721597c5ed0fd9bab2c373d1 for chilio/laravel-dusk-ci:php-8.1 with digest chilio/laravel-dusk-ci@sha256:f7e1040cc6bdce42a1b4eb3de71e5ef408bce91473e2099b879895a3b48dc70f ...
Preparing environment
00:00
Running on runner-h8o-suv2-project-23524763-concurrent-0 via 5efb45668828...
Getting source from Git repository
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/my/repository/.git/
Checking out 7d039aa8 as 870-ui-refresh...
Removing .env
Removing node_modules/
Removing vendor/
Skipping Git submodules setup
Restoring cache
00:01
Checking cache for bda3ef736b8aa1a9917283a088cf3f291f22bde0-non_protected...
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. 
Successfully extracted cache
Checking cache for 5c275d47e21fa9db678913b3ccc10f2f2a7a7b1b-non_protected...
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. 
Successfully extracted cache
Executing "step_script" stage of the job script
Using docker image sha256:b529d7fdffba447b7acfb6b41c705ce4b7e3257e721597c5ed0fd9bab2c373d1 for chilio/laravel-dusk-ci:php-8.1 with digest chilio/laravel-dusk-ci@sha256:f7e1040cc6bdce42a1b4eb3de71e5ef408bce91473e2099b879895a3b48dc70f ...
$ cp .env.gitlab-testing .env
$ composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Package operations: 136 installs, 0 updates, 0 removals
  - Downloading aws/aws-crt-php (v1.0.2)
  - Downloading symfony/finder (v6.1.3)
  - Downloading symfony/polyfill-mbstring (v1.26.0)
  - Downloading symfony/var-dumper (v6.1.3)
  ...... [ installing and downloading composer packages ]
  - Installing spatie/flare-client-php (1.2.0): Extracting archive
  - Installing spatie/ignition (1.3.1): Extracting archive
  - Installing spatie/laravel-ignition (1.3.1): Extracting archive
  - Installing vrana/jush (v2.0.2): Extracting archive
Generating optimized autoload files
89 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
$ npm ci
npm WARN deprecated [email protected]: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
npm WARN deprecated [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
added 870 packages, and audited 871 packages in 28s
80 packages are looking for funding
  run `npm fund` for details
found 0 vulnerabilities
$ npm run prod
> prod
> npm run production
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

absurd amounts of "apt-get update"

The Dockerfile is currently running apt-get update no less than 15 times.

apt update is just to rebuild the local cache of the repository.
The build time is 15 minutes on my CI. Do you expect the repository to change significantly in 15 minutes?
Yes -> Keep the apt updates
No -> Reduce it to one call.

Nodejs 10 not supported

I'm using your image to test a Laravel application with a vuejs spa frontend which requires node 10 at least. Can you bumb the node version?

Docker Compose File Example

You have some good examples for providers like github and gitlab. Are you planning on adding any docker compose example files?

Run test with MySQL

I'm trying to run your docker package to launch my Dusk tests. But I have an error related to MySQL, I don't know if it's related to your package or not, so I prefear to ask here before.

(If it's not related, I'll move this quesiton to the docker/mysql)

I'm using the folowing version

  • Gitlab 10.0.3
  • Docker v 18.03.1-ce
  • Gitlab-runner 11.0 (through docker)
  • MySQL 5.7 (through Docker)

When my job is launched I get

Running with gitlab-runner 11.0.0 (5396d320)
  on Gitlab-runner web 694c0a31
Using Docker executor with image chilio/laravel-dusk-ci:stable ...
Starting service mysql:5.7 ...
Pulling docker image mysql:5.7 ...
Using docker image sha256:66bc0f66b7af6ba3ea96582685d3afcd6dff93c2f8999da0ffadd67b280db548 for mysql:5.7 ...
Waiting for services to be up and running...

*** WARNING: Service runner-694c0a31-project-30-concurrent-0-mysql-0 probably didn't start properly.

Health check error:
service "runner-694c0a31-project-30-concurrent-0-mysql-0-wait-for-service" timeout

I don't know why my current mysql container is not used and a "concurrent" version is displayed here

But just after I have this

2018-07-13T09:48:46.166996215Z Initializing database
[...]
2018-07-13T09:49:21.483652451Z Database initialized
2018-07-13T09:49:21.485018618Z Initializing certificates
2018-07-13T09:49:21.509636892Z Generating a 2048 bit RSA private key

So I guess, it's something great ?!

But at the end

Pulling docker image chilio/laravel-dusk-ci:stable ...
Using docker image sha256:e0da075c669a703e615f4cab3d08b2c03e6de138c9d2bc82399e0e9823719b0d for chilio/laravel-dusk-ci:stable ...
Running on runner-694c0a31-project-30-concurrent-0 via d09f531ddeb7...
Fetching changes...
HEAD is now at cf063fe Update .gitlab-ci.yml
Checking out cf063fe3 as master...
Skipping Git submodules setup
Checking cache for master...
Successfully extracted cache
ERROR: Job failed (system failure): Error response from daemon: Cannot link to a non running container: /runner-694c0a31-project-30-concurrent-0-mysql-0 AS /runner-694c0a31-project-30-concurrent-0-build-4/mysql

Through docker I can use docker exec -it some-mysql bash and connect to my mysql and show the databases.

I'm new to docker/testing env so maybe I missed a concept, sorry if this is the case.

Scripts fail ^M on latest image

Since the latest image push all our pipelines that use php8.2 have been failing.

sha256:6cbd54a71bbf0f59c0b92cc89e8d8a4d406620b2db2b9099deb95b40c9933d15 worked fine.
sha256:578787217860f7853166e20eb8a57a30d858da5f83313df299401f8f81b5de76 appears to be causing issues.

The latest update results in the following error when our pipeline tries to run the versions script:

+ versions

bash: /usr/bin/versions: /bin/bash^M: bad interpreter: No such file or directory

The same happens for the other scripts:

+ configure-laravel

bash: /usr/bin/configure-laravel: /bin/bash^M: bad interpreter: No such file or directory

Looks like something went wrong with the latest push? Might be an issue with windows EOL characters being used.
This was specifically failing on Bitbucket pipelines for me. Running old builds that succeeded previously also fail now due to the new image.

latest update messes with composer

using the chilio/laravel-dusk-ci:php-7.4 builds

if i re-run a job that passed from last week (when the latest commit was pushed) it fails now

and on docker hub... i can specifiy the previous build to confirm this. (ie by using chilio/laravel-dusk-ci:1a2bxx...

anyways to speed up the tests

i don't have too many test. but the runner takes up to 2 minutes.

just wondering if anyone has any tips to speed up running the tests

use local phpunit

hi chilio,

i guess it is better to use local phpunit instead of pulling it from server

RUN wget https://phar.phpunit.de/phpunit.phar
RUN chmod +x phpunit.phar
RUN mv phpunit.phar /usr/local/bin/phpunit

because when i try to use this in laravel 5.6 or low where we need to use phpunit 4, i am getting error like

laravel/framework#26874

and i assume, the error is because of using latest version of phpunit.

thanks

Current gitlab-ci.yml example caching leads to failing tests

First off, thanks for this package, it's been a great help :-) However I did run into an issue that I expect others will experience too. Caching of resources is causing the Dusk tests to fail after a blade update.

Steps to recreate:

  • Clean Laravel install
  • Install Dusk
  • Add https://github.com/chilio/laravel-dusk-ci/blob/master/examples/.gitlab-ci.yml
  • Commit to new Gitlab repo

Tests should now be Green

  • Change the Laravel title in welcome.blade.php to Laravel 5
  • Edit Tests\Browser\ExampleTest->testBasicExample() to $browser->visit('/')->assertSee('Laravel 5');
  • Commit and push

The test will now fail, saying they're not seeing "Laravel 5", even though it's definitely there.

When you check the tests/Browser/screenshots image you'll see that it's still showing the old blade version. After a lot of trial and erroring, the issue was because of the job caching.

Pretty simple fix though, just remove these lines from the gitlab-ci.yml example and all is well again :)

        - resources
        - public

I removed the public folder as well as something's bound to end up in there that will cause a similar issue.

[SEVERE]: bind() failed: Cannot assign requested address (99)

I have run into a slight snag when using the latest image with a Gitlab CI pipeline, it can reach the starting ChromeDriver on port 9515, but unfortunately, a binding issue presents itself afterwards.

ChromeDriver binary successfully installed for version 112.0.5615.49.
๏ฟฝ[32m$ configure-laravel๏ฟฝ[39m

   INFO  Application key set successfully.  


   INFO  The [public/storage] link has been connected to [storage/app/public].  


  Dropping all tables ............................................. 213ms DONE

   INFO  Preparing database.  

  Creating migration table ......................................... 38ms DONE

   INFO  Running migrations.  

-- SNIP -- 

   INFO  Seeding database.  

๏ฟฝ[0;32mSystem Chrome version: ๏ฟฝ[0m112
๏ฟฝ[0;32mSystem Chromedriver version: ๏ฟฝ[0m112.0
๏ฟฝ[0;32mLaravel Chromedriver version: ๏ฟฝ[0m112.0
๏ฟฝ[0;32m Laravel Chromedriver check PASSED OK.
๏ฟฝ[1;33mYou can use both Chromedriver shipped with Laravel (112.0) or system Chromeriver (112.0)
๏ฟฝ[1;33mSystem Chromedriver is NOT automatically started in this case. So, before running php artisan DUSK, you have 2 options:
๏ฟฝ[1;33m1. If you want to run tests with Laravel Chromedriver and you have DuskTestCase.php configured with 'static::startChromeDriver();' enabled, then you don't need to change anything.
๏ฟฝ[1;33m2. If you want to run tests with System Chromedriver, remember to issue command 'chromedriver &' in your .gitlab-ci-yml before starting Dusk tests.
๏ฟฝ[0m๏ฟฝ[0m๏ฟฝ[32m$ start-nginx-ci-project๏ฟฝ[39m
 * Starting nginx nginx
   ...done.
๏ฟฝ[32m$ chromedriver &๏ฟฝ[39m
๏ฟฝ[32m$ php artisan pest:dusk --without-tty๏ฟฝ[39m
Starting ChromeDriver 112.0.5615.49 (bd2a7bcb881c11e8cfe3078709382934e3916914-refs/branch-heads/5615@{#936}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
[1696844306.357][SEVERE]: bind() failed: Cannot assign requested address (99)
ChromeDriver was started successfully.

I don't want to burden this issue with logs but here's one of the Dusk test failures as it may come in handy.

   FAILED  Tests\Browser\Tablatures\IndexFilterTest >โ€ฆ  UnknownErrorException   
  unknown error: Chrome failed to start: crashed.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

  at vendor/php-webdriver/webdriver/lib/Exception/WebDriverException.php:146
    142โ–•                     throw new UnexpectedAlertOpenException($message, $results);
    143โ–•                 case 'unknown command':
    144โ–•                     throw new UnknownCommandException($message, $results);
    145โ–•                 case 'unknown error':
  โžœ 146โ–•                     throw new UnknownErrorException($message, $results);
    147โ–•                 case 'unknown method':
    148โ–•                     throw new UnknownMethodException($message, $results);
    149โ–•                 case 'unsupported operation':
    150โ–•                     throw new UnsupportedOperationException($message, $results);

      ๏ฟฝ[2m+3 vendor frames ๏ฟฝ[22m
  4   tests/DuskTestCase.php:40
      ๏ฟฝ[2m+1 vendor frames ๏ฟฝ[22m
  6   tests/Browser/Tablatures/IndexFilterTest.php:11

This is the job from my gitlab-ci.yml file.

end_to_end_tests:
#  extends: .standard-rules
  stage: testing
  image: chilio/laravel-dusk-ci:latest
  script:
    - php artisan dusk:chrome-driver --detect --verbose
    - configure-laravel
    - start-nginx-ci-project
    - chromedriver &
    - php artisan pest:dusk --without-tty
  artifacts:
    paths:
      - ./storage/logs # for debugging
      - ./tests/Browser/screenshots
      - ./tests/Browser/console
    expire_in: 7 days
    when: always

The only adjustment I have made is adding no--sandbox to the driver in DuskTestCase.php. The only outlier is that I use Postgres (the tables migrate successfully) but I couldn't see why that would break dusk testing.

If you happen to know what the culprit could be, I'd appreciate it, if you need any additional information please let me know, I didn't want this to be a wall of logs. (It is being ran locally with gitlab-ci-local)

I have attached my full gitlab ci file as it may reveal the issue with added information. (Had to change the extension!)

gitlab-ci.txt

Build failing

Hi,

I was using your package since nearly 6 months without any trouble. But today things are failing.
I'm still using the stable release. In the changelog I see that you are still under php 7.2 but in the following error I see 7.3

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - laravel/framework v5.6.34 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - laravel/framework v5.6.34 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - Installation request for laravel/framework v5.6.34 -> satisfiable by laravel/framework[v5.6.34].

  To enable extensions, verify that they are enabled in your .ini files:
    - /etc/php/7.3/cli/php.ini
    - /etc/php/7.3/cli/conf.d/10-opcache.ini
    - /etc/php/7.3/cli/conf.d/10-pdo.ini
    - /etc/php/7.3/cli/conf.d/20-calendar.ini
    - /etc/php/7.3/cli/conf.d/20-ctype.ini
    - /etc/php/7.3/cli/conf.d/20-exif.ini
    - /etc/php/7.3/cli/conf.d/20-fileinfo.ini
    - /etc/php/7.3/cli/conf.d/20-ftp.ini
   ...

I didn't changed anything in my tests, package.json or composer.json. So I'm guessing it's coming from your last change.

Permission issue

I'm facing a premission issue.

In my .gitlab-ci.yml file tests are run by php artisan dusk... but it is executed as root.

My dusk test use a Laravel factory which create a file in storage (an image associated to an article), so this relative folder/file is created as root.
So when I try to change this file with dusk (so with www-data), I'm facing a premission issue.

Is it possible to run dusk as www-data ?
Maybe you can add sudo in the container ?

Laravel 11

Hi there,

Are you planning on release a new version for laravel 11?

By the way, thanks for this repo!

Facebook\WebDriver\Exception\NoSuchDriverException: invalid session id

Thanks for accepting my PR earlier on!

I'm running into the issue with my Gitlab runner that my tests are failing due to chrome not booting soon enough. This only happens when I run multiple tests in a row (30+). Usually the first few tests succeed and then the rest fails. This is with a testing setup in which I'm repeating the same simple test 100 times:

$this->browse(function (Browser $browser) {
        $browser->visit('/')->assertSee('Hello world!');
});

This is the error I'm getting.

Facebook\WebDriver\Exception\NoSuchDriverException: invalid session id
  (Driver info: chromedriver=2.45.615279 (12b89733300bd268cff3b78fc76cb8f3a7cc44e5),platform=Linux 4.14.48-coreos-r2 x86_64)

I'm using these chrome options:

'--window-size=1200,1024',
'--disable-gpu',
'--headless',
'--no-sandbox',

I found that adding a sleep(1); at the end of the setUp()in DuskTestCase.php solves the issue, yet this increases the duration of tests significantly... I might have found a better solution, which is mounting the /dev/shm folder, however I'm not sure how to implement: elgalu/docker-selenium#20

Since adding this fix might increase stability for everyone using Laravel Dusk on a Gitlab CI, I posted this here. @chilio Would you know how to implement this fix?

Failed to connect to localhost port 9515: Connection refused

Thanks a lot for the docker image. It helps me to setup the testing stage on the GitLab server.

In the last times I have random failure and I find no reason why. Clear the GitLab Runner Cache helps sometimes.

That is the output of the job for all tests:

1) Tests\Browser\LogsTest::testAdmin
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"binary":"","args":["--disable-gpu","--headless","--no-sandbox"]}}}

Failed to connect to localhost port 9515: Connection refused

/builds/project/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:286
/builds/project/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:126
/builds/project/tests/DuskTestCase.php:40
/builds/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:189
/builds/project/vendor/laravel/framework/src/Illuminate/Support/helpers.php:770
/builds/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:190
/builds/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:92
/builds/project/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:64
/builds/project/tests/Browser/LogsTest.php:27

The relevent part of the .gitlab-ci.yml

cache:
  key: "$CI_COMMIT_REF_SLUG"
  paths:
    #- node_modules/
    - .npm
    - vendor/
    - public/css/
    - public/js/
    - public/fonts/
    - public/mix-manifest.json

variables:
  MYSQL_ROOT_PASSWORD: root
  MYSQL_USER: homestead
  MYSQL_PASSWORD: secret
  MYSQL_DATABASE: homestead
  DB_HOST: mariadb
  DB_CONNECTION: mysql
  SCREEN_RESOLUTION: 1920x1080x24
  
before_script:
  - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
  - mkdir -p ~/.ssh
  - eval $(ssh-agent -s)
  - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'

stages:
  - build_npm
  - build_composer
  - test
  - deploy
  - release

build_npm:
  stage: build_npm
  image: node:8
  script:
    - npm config set cache $(pwd)/.npm --global
    - npm i npm -g
    - npm -v
    - npm ci
    - npm run production

build_composer:
  stage: build_composer
  image: composer
  script:
    - cp .env.testing .env
    - composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts

test:
  stage: test
  image: chilio/laravel-dusk-ci
  services:
      - mariadb
  script:
    - cp .env.testing .env
    - configure-laravel
    - start-nginx-ci-project
    - chown -R www-data storage/framework
    - php artisan dusk --colors --debug
  artifacts:
    paths:
      - ./storage/logs # for debugging
      - ./tests/Browser/screenshots
      - ./tests/Browser/console
    expire_in: 7 days
    when: always

What information do you need to investigate this issue?

Automated Docker build

Hi,

Why isn't the container displayed as an automated docker build in the Docker Hub?

just for information. Thanks

System Chromedriver version

Hi!

First off, thanks a ton for this! It really saves a lot of effort.

I'm having trouble trying to understand where the "System Chromedriver version" is coming from, and why my app's chrome driver version is considered a mismatch.

Here's the output from my build:

121 System Chrome version: 79
122 System Chromedriver version: 78.0
123 Laravel Chromedriver version: 79.0
124 Chromedriver shipped with your Laravel installation is NOT compatible with current system chrome version!
125 Don't worry, we are fixing this right now, and you will be able, to test your app anyway.
126 Read more, about running tests with system inbuilt chromedriver in laravel-dusk-ci docs.
127 Starting inbuilt Chromedriver (78.0).
128 Waiting for inbuilt Chromedriver to launch on port 9515...
129 Starting ChromeDriver 78.0.3904.105 (60e2d8774a8151efa6a00b1f358371b1e0e07ee2-refs/branch-heads/3904@{#877}) on port 9515

So you can see that the System Chrome version is 79, but the System Chromedriver is 78. The Laravel Chromedriver is 79 (which matches installed System Chrome version).

However, even though System Chrome and Laravel Chromedriver versions match, the image thinks they are a mismatch, and then proceeds to use the version 78 chromedriver.

Any tips/help you can suggest?

Can't connect to DB during script in .yml

Hello again,

My build is passing but another error is appearing in the test stage.

I'm using this in .gitlab-ci.yml

variables:
  MYSQL_ROOT_PASSWORD: secret
  MYSQL_DATABASE: testing
  MYSQL_USER: user
  MYSQL_PASSWORD: secret

test:
  stage: test
  services:
    - mysql:5.7
    
  image: chilio/laravel-dusk-ci:stable
  script:
    - cp .env.dusk.local .env
    - cd ${CI_PROJECT_DIR}
    - chmod -R 775 storage
    - chmod 775 bootstrap/cache
    - chown -R www-data ./
    - php artisan key:generate
    - php artisan migrate:fresh
    - php artisan db:seed -n
    - chrome-system-check
    - sleep 10s
    - start-nginx-ci-project
    - php artisan dusk --colors --debug

But during the CI, the php artisan migrate:fresh is faliing with this error

$ php artisan migrate:fresh

In Connection.php line 664:
                                                                               
  SQLSTATE[HY000] [2002] Connection refused (SQL: SHOW FULL TABLES WHERE tabl  
  e_type = 'BASE TABLE')                                                       
                                                                               

In Connector.php line 68:
                                             
  SQLSTATE[HY000] [2002] Connection refused  

But if I connect manually to the docker container. And I run manually the command, everything is working fine concerning the migration & seeding.

Have you any idea why it is not working?

More info

When I connnect to my docker container, I'm also able to run mysql like this

musql -u user -p -h mysql

My database testing exist

Add composer.lock to example .gitlab.yml

For sure, it's very common, that most programmers should know to add composer.lock to cache.
But I was wondering, that my builds ran about 7 till 8 Minutes - now Ive changed that, since Ive copied the example from README.

Maybe you can commit my change to your example.
Just wanted to inform you about what maybe is needed, for reducing the runtime of builds.

Great work! Nice Project!

migrate:fresh breaks laravel 5.4

I have an app with laravel 5.4 e I'm using this ci docker image.

The only thing I had to change to work is, instead of using the command
configure-laravel
was to rewrite its contents changing
php artisan migrate:fresh --seed
to:
php artisan migrate:refresh --seed

A check on the laravel version prior to execute this command would make it retrocompatible too.

MySQL Connection refused

This is a similar issue like #24

I have this yml file:

stages:
- build
- test
- deploy

# Variables
variables:
  DB_HOST: mysql-test
  MYSQL_DATABASE: laravel
  MYSQL_ROOT_PASSWORD: secret
  DB_CONNECTION: mysql

composer:
  image: lorisleiva/laravel-docker:latest
  stage: build
  script:
  - cp .env.gitlab-testing .env
  - composer install --no-progress --no-interaction
  - php artisan key:generate
  artifacts:
    paths:
    - vendor/
    - bootstrap/
    - .env
  cache:
    key: ${CI_BUILD_REF_NAME}
    paths:
    - vendor/
  tags:
  - docker

npm:
  image: lorisleiva/laravel-docker:latest
  stage: build
  script:
  - npm install
  - npm run prod
  artifacts:
    paths:
    - public/mix-manifest.json
  cache:
    key: ${CI_BUILD_REF_NAME}
    paths:
    - node_modules/
  tags:
  - docker  

dusk:
  stage: test
  dependencies:
  - composer
  - npm
  tags:
  - docker
  cache:
    key: ${CI_BUILD_REF_NAME}
    paths:
    - vendor
    - node_modules
    policy: pull

  services:
  - name: mysql:5.7
    alias: mysql-test

  image: chilio/laravel-dusk-ci:latest
  script:
  - cp .env.dusk.gitlab-testing .env
  - cp phpunit.dusk.xml phpunit.xml # if you are using custom config for your phpunit tests in CI
  - configure-laravel
  - start-nginx-ci-project
  - php artisan dusk --colors --debug

  artifacts:
    paths:
    - ./storage/logs # for debugging
    - ./tests/Browser/screenshots
    - ./tests/Browser/console
    expire_in: 7 days
    when: always

And am getting the same connection refused errors when running this. I also tried to add a sleep and investigate this from the inside... From the inside everything looks good, but dusk is failing.
A bit more detailed here: https://stackoverflow.com/questions/53794231/gitlab-ci-dusk-mysql-connection-refused

Folders permissions ?

Hi,

Since few days, I have a problem with folders permissions...

failure-modules_activitylog_tests_resources_views_admin_deletepagetest_testdeletelinkwithpermission-0

I tried every command, permissions, I despair and I hope you can help me !
Even with the command "chmod -R 777" on folder storage not working...

Thank you

My gitlab-ci.yml :

  - build
  - test

variables:
  MYSQL_DATABASE: project_name
  MYSQL_ROOT_PASSWORD: secret

build:
  stage: build
  services:
    - mysql:5.7

  image: chilio/laravel-dusk-ci:stable
  script:
    # Install composer
    - composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts

    # Install Node dependencies.
    - npm install

    # Run npm build
    - npm run dev

  cache:
    key: ${CI_BUILD_REF_NAME}
    paths:
      - vendor
      - node_modules
      - public

test:
  stage: test
  cache:
    key: ${CI_BUILD_REF_NAME}
    paths:
      - vendor
      - node_modules
      - public
    policy: pull

  services:
    - mysql:5.7

  image: chilio/laravel-dusk-ci:stable
  script:
  # Remove php-xdebug
  - apt-get purge php-xdebug -y

  # Install jshint
  - npm install -g jshint

  # Update composer
  - composer update --no-scripts  

  # Copy over testing configuration.
  - cp .env.ci.testing .env

  # Folders permission
  - cd ${CI_PROJECT_DIR}
  - chmod -R 775 storage
  - chmod 775 bootstrap/cache
  - chown -R www-data ./

  # Generate an application key.
  - php artisan config:cache
  - php artisan key:generate

  # Run database migrations.
  - php artisan module:migrate

  # Run database seed
  - php artisan module:seed

  # Command to check chrome lib
  - chrome-system-check
  - sleep 10s

  # Command to start nginx
  - start-nginx-ci-project

  # run laravel tests
  - php vendor/bin/phpunit --no-coverage --colors=never --printer=Codedungeon\\PHPUnitPrettyResultPrinter\\Printer

  # run frontend tests
  - npm test

  # run phpcs
  - ./vendor/bin/phpcs -p --error-severity=1 --warning-severity=8 --extensions=php

  # run jshint
  - jshint --show-non-errors public/js/modules/.

  artifacts:
    paths:
      - ./storage/logs # for debugging
      - ./tests/Browser/console # for debugging
      - ./tests/Browser/screenshots # for debugging
    expire_in: 7 days
    when: always

Timeouts in gitlab ci/cd

Hello, first of all sorry if this is unrelated to this package. I'm trying to use laravel-dusk-ci in conjunction with a Gitlab ci/cd pipeline.

My unit tests work fine using this package, but my browser tests (Dusk) receives multiple timeouts relating to what I think is the ChromeDriver failing.

I'm using the recommended settings for the ChromeDriver my DuskTestCase.php file.

namespace Tests;

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

abstract class DuskTestCase extends BaseTestCase
{
    use CreatesApplication;

    /**
     * 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',
            '--no-sandbox'
        ]);

        return RemoteWebDriver::create(
            'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
                ChromeOptions::CAPABILITY, $options
            )
        );
    }
}

My gitlab-ci.yml looks as follows, I specifically used php version 7.3 for this as suggested as one of the solutions in the documentation:

image: chilio/laravel-dusk-ci:php-7.3

services:
  - mysql:5.7

variables:
  MYSQL_DATABASE: homestead
  MYSQL_ROOT_PASSWORD: secret
  DB_HOST: mysql
  DB_USERNAME: root

stages:
  - test
  - deploy

unit_test:
  stage: test
  script:
    - composer install
    - cp .env.example .env
    - configure-laravel
    - start-nginx-ci-project
    - vendor/bin/phpunit

browser_test:
  stage: test
  script:
    - composer install
    - cp .env.example .env
    - configure-laravel
    - start-nginx-ci-project
    - chromedriver &
    - php artisan dusk

Upon running my browser_test I receive the following output in the gitlab ci/cd job terminal.

System Chrome version: 94
System Chromedriver version: 94.0
Laravel Chromedriver version: 2.45
Chromedriver shipped with your Laravel installation is NOT compatible with current system chrome version!
Don't worry, we are fixing this right now, and you will be able, to test your app anyway.
Read more, about running tests with system inbuilt chromedriver in laravel-dusk-ci docs.
Starting inbuilt Chromedriver (94.0).
Waiting for inbuilt Chromedriver to launch on port 9515...
Starting ChromeDriver 94.0.4606.61 (418b78f5838ed0b1c69bb4e51ea0252171854915-refs/branch-heads/4606@{#1204}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Chromedriver started succesfully.
$ start-nginx-ci-project
 * Starting nginx nginx
   ...done.
$ chromedriver &
$ php artisan dusk
Starting ChromeDriver 94.0.4606.61 (418b78f5838ed0b1c69bb4e51ea0252171854915-refs/branch-heads/4606@{#1204}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
[1634909533.900][SEVERE]: bind() failed: Address already in use (98)
IPv6 port not available. Exiting...
Warning: TTY mode requires /dev/tty to be read/writable.
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
[1634909547.238][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909547.241][WARNING]: screenshot failed, retrying timeout: Timed out receiving message from renderer: 10.000
[1634909557.242][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909567.247][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909567.251][WARNING]: screenshot failed, retrying timeout: Timed out receiving message from renderer: 10.000
[1634909577.251][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909587.256][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909587.260][WARNING]: screenshot failed, retrying timeout: Timed out receiving message from renderer: 10.000
E[1634909597.261][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909615.655][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909615.658][WARNING]: screenshot failed, retrying timeout: Timed out receiving message from renderer: 10.000
[1634909625.658][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909635.664][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909635.667][WARNING]: screenshot failed, retrying timeout: Timed out receiving message from renderer: 10.000
[1634909645.668][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909655.681][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909655.685][WARNING]: screenshot failed, retrying timeout: Timed out receiving message from renderer: 10.000
E                                                                  2 / 2 (100%)[1634909665.685][SEVERE]: Timed out receiving message from renderer: 10.000
Time: 2.19 minutes, Memory: 18.00 MB
There were 2 errors:
1) Tests\Browser\LoginTest::testLoginAndLogout
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session/4adecbcb71732c0e914e63d7886239fe/log with params: {"type":"browser"}
Operation timed out after 30001 milliseconds with 0 bytes received
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:333
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:585
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/RemoteExecuteMethod.php:27
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/WebDriverOptions.php:166
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Browser.php:369
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:161
/builds/mygitlab/myproject/vendor/laravel/framework/src/Illuminate/Support/Collection.php:475
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:162
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:78
/builds/mygitlab/myproject/tests/Browser/LoginTest.php:27
Caused by
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http GET to /session/4adecbcb71732c0e914e63d7886239fe/screenshot
Operation timed out after 30000 milliseconds with 0 bytes received
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:333
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:585
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:367
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Browser.php:355
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:146
/builds/mygitlab/myproject/vendor/laravel/framework/src/Illuminate/Support/Collection.php:475
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:147
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:70
/builds/mygitlab/myproject/tests/Browser/LoginTest.php:27
2) Tests\Browser\RegistrationTest::testRegistrationFlow
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session/72b15fbd659b839b5fa3ba2ab6f920e0/log with params: {"type":"browser"}
Operation timed out after 30001 milliseconds with 0 bytes received
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:333
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:585
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/RemoteExecuteMethod.php:27
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/WebDriverOptions.php:166
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Browser.php:369
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:161
/builds/mygitlab/myproject/vendor/laravel/framework/src/Illuminate/Support/Collection.php:475
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:162
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:78
/builds/mygitlab/myproject/tests/Browser/RegistrationTest.php:78
Caused by
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http GET to /session/72b15fbd659b839b5fa3ba2ab6f920e0/screenshot
Operation timed out after 30001 milliseconds with 0 bytes received
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:333
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:585
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:367
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Browser.php:355
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:146
/builds/mygitlab/myproject/vendor/laravel/framework/src/Illuminate/Support/Collection.php:475
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:147
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:70
/builds/mygitlab/myproject/tests/Browser/RegistrationTest.php:78
ERRORS!
Tests: 2, Assertions: 1, Errors: 2.
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1

Laravel mix uses libpng16 which is not available for xenial

Hi, after adding the command .copy('resources/assets/images', 'public/images') inside my webpack.mix.js file, it's impossible to finish the build since npm cannot find libpng16.so

Doing some research, i've found that this library does not come with ubuntu xenial per default. Could it be easy for you to include this library since other developers using your docker image may face this issue?

Image assumes laravel instance exists in projects root directory

The current image makes the assumption that the repository it's used against has the laravel instance within the root directory. If you have it in a subdirectory, the scripts fails as they assume everything is available from CI_PROJECT_DIR before moving on.

Can you please rebuild all images to get latest ca-certificates

LE root ca cart has expired and older, php7.4 for example, images are using older version of ca-certificates package.

Since you already have apt upgrade in your docker file - simple rebuild will fix LE issues and update ca-certificates to latest version.

Thanks.

Cannot connect to database when run dusk

$ php artisan dusk --colors --debug

In Connection.php line 664:
                                                                               
  SQLSTATE[HY000] [1045] Access denied for user 'forge'@'172.17.0.4' (using p  
  assword: NO) (SQL: select `name`, `value` from `admin_config`)               
                                                                               

In Connector.php line 67:
                                                                               
  SQLSTATE[HY000] [1045] Access denied for user 'forge'@'172.17.0.4' (using p  
  assword: NO)                                                                 

php_network_getaddresses Name or service not know

I've taken the files from the example and it keeps giving me this:

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name o  
  r service not known

Here's the .gitlab-ci

stages:
  - build
  - test

# Variables
variables:
  MYSQL_ROOT_PASSWORD: root
  MYSQL_USER: root
  MYSQL_PASSWORD: secret
  MYSQL_DATABASE: test
  DB_HOST: mysql
  DB_CONNECTION: mysql

build:
  stage: build
  services:
     - mysql:5.7

  image: chilio/laravel-dusk-ci:stable
  script:
    - composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
    # - npm install # if you need to install additional modules from your projects package.json
    # - npm run dev # if you need to run dev scripts for example laravel mix 
  cache:
      key: ${CI_BUILD_REF_NAME}
      paths:
        # these are only examples, you should modify them according to your project, 
        # or remove cache routines entirely, if they are causing any problems on your next builds..
        # below are 2 safe ones if you use composer install and npm install in your stage script
        - vendor
        - node_modules
         # - /resources/assets/vendors  # for example if you put your vendor node-libraries there

test:
  stage: test
  cache:
    key: ${CI_BUILD_REF_NAME}
    paths:
      - vendor
      - node_modules
    policy: pull
    
  services:
    - mysql:5.7

  image: chilio/laravel-dusk-ci:stable
  script:
    - cp .env.example .env
    # - cp phpunit.xml.ci phpunit.xml # if you are using custom config for your phpunit tests in CI
    - configure-laravel
    - start-nginx-ci-project
    - ./vendor/phpunit/phpunit/phpunit -v --coverage-text --colors --stderr
    # - phpunit -v --coverage-text --colors --stderr # if you want to use preinstalled phpunit
    - php artisan dusk --colors --debug

  artifacts:
    paths:
      - ./storage/logs # for debugging
      - ./tests/Browser/screenshots
      - ./tests/Browser/console
    expire_in: 7 days
    when: always

And my .env.example:

APP_NAME="Testing"
APP_ENV=testing
APP_DEBUG=true
APP_URL=http://localhost
APP_KEY=

DB_HOST=mysql
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=secret

CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=sync
MAIL_DRIVER=log

Missing rsync

Looks like rsync was removed from latest relase.
Please re add it if it is possible

The command "rsync -azP -e 'ssh -A -p 22'  failed.                            
Exit Code: 127(Command not found)       

Small manual for self-compiling container

Hi,

I think it would be helpful if we had a manual on how to create your own container from this build. For me, I would like to have the nginx-error logs as I am getting some.

Therefore, I would like to change the error_log path of nginx to the build root, as we cannot add artifacts outside the build directory.

Ability to remove xdebug ?

Hi,

I try to remove xdebug without success.
Because with xdebug, my tests run very slow

Before your docker: ~20 minutes
With your docker: ~1 hour and 10 minutes

But nothing working...

Thank you in advance for your help

My .gitlab-ci.yml

stages:
  - build
  - test

variables:
  MYSQL_DATABASE: project_name
  MYSQL_ROOT_PASSWORD: secret

build:
  stage: build
  services:
    - mysql:5.7

  image: chilio/laravel-dusk-ci:stable
  script:
    - composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts

    # Install Node dependencies.
    - npm install

    # Install jshint
    - npm install -g jshint

    # Run npm build
    - npm run dev

    # Remove php-xdebug
    - phpdismod -s cli xdebug
    - phpdismod xdebug

  cache:
    key: ${CI_BUILD_REF_NAME}
    paths:
      - vendor
      - node_modules
      - public

test:
  stage: test
  cache:
    key: ${CI_BUILD_REF_NAME}
    paths:
      - vendor
      - node_modules
      - public
    policy: pull

  services:
    - mysql:5.7

  image: chilio/laravel-dusk-ci:stable
  script:
  - composer update --no-scripts  

  # Copy over testing configuration.
  - cp .env.ci.testing .env

  # Generate an application key. Re-cache.
  - php artisan config:cache
  - chmod -R 775 storage
  - chmod 775 bootstrap/cache
  - chown -R www-data ./
  - php artisan key:generate

  # Command to check chrome lib
  - chrome-system-check
  - sleep 10s

  # Command to start nginx
  - start-nginx-ci-project

  # Run database migrations.
  - php artisan module:migrate

  # Run database seed
  - php artisan module:seed

  # run laravel tests
  - php vendor/bin/phpunit --no-coverage --colors=never --printer=Codedungeon\\PHPUnitPrettyResultPrinter\\Printer

  # run frontend tests
  - npm test

  # run phpcs
  - ./vendor/bin/phpcs -p --error-severity=1 --warning-severity=8 --extensions=php

  # run jshint
  - jshint --show-non-errors public/js/modules/.

  artifacts:
    paths:
      - ./storage/logs # for debugging
      - ./tests/Browser/console # for debugging
      - ./tests/Browser/screenshots # for debugging
    expire_in: 7 days
    when: always

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.