Laravel Dusk v7.x and Github Actions Issues from Error to Success [Linux]
Laravel Dusk is a testing tool for Laravel web applications that allows you to perform browser-driven testing. Dusk v7.x is the latest version of Laravel Dusk, and it provides several improvements and new features over its previous versions. In this answer, we will discuss how to resolve common issues when using Laravel Dusk v7.x with Github Actions on Linux.
Prerequisites
Before we dive into the issues and solutions, let's make sure that you have the following prerequisites in place:
- Laravel application with Dusk testing installed.
- Github repository with a
.github/workflows
directory containing a.yml
file for your workflow. - A Github account with access to the repository and necessary permissions to create and run workflows.
Issue 1: PHP and Composer Installation
The first issue that you might encounter is related to the PHP and Composer installation. Github Actions use a container to run your workflow, and you need to make sure that the container has PHP and Composer installed.
To resolve this issue, you can use an official PHP Docker image with Composer pre-installed. Here's an example of a .yml
file that uses the php:8.0-fpm
image:
name: Laravel Dusk Testing
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Composer
uses: actions/setup-composer@v1
with:
php: 8.0
- name: Install dependencies
run: composer install --no-autoload
- name: Run tests
uses: laravel/dusk:v7.x
with:
key: ${{ secrets.laravel_key }}
browser: chrome
test: php artisan dusk:test
Issue 2: ChromeDriver Installation
The second issue that you might encounter is related to the ChromeDriver installation. Laravel Dusk uses ChromeDriver to interact with the Chrome browser during testing.
To resolve this issue, you can use a Docker image that includes ChromeDriver. Here's an example of a .yml
file that uses the selenium/standalone-chrome:latest
image:
name: Laravel Dusk Testing
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Composer
uses: actions/setup-composer@v1
with:
php: 8.0
- name: Install dependencies
run: composer install --no-autoload
- name: Download ChromeDriver
uses: actions/download@v2
with:
url: https://chromedriver.storage.googleapis.com/latest/chromedriver_linux64.zip
dest: chromedriver.zip
- name: Extract ChromeDriver
run: unzip chromedriver.zip
- name: Set up ChromeDriver
uses: actions/setup-selenium@v1
with:
selenium_version: latest
driver_path: ./chromedriver
- name: Run tests
uses: laravel/dusk:v7.x
with:
key: ${{ secrets.laravel_key }}
browser: chrome
test: php artisan dusk:test
Issue 3: Selenium WebDriver and Laravel Dusk Configuration
The third issue that you might encounter is related to the Selenium WebDriver and Laravel Dusk configuration. Laravel Dusk uses Selenium WebDriver to interact with the browser during testing, and you need to make sure that the configuration is correct.
To resolve this issue, you need to set the --webdriver
flag when running the Laravel Dusk command. Here's an example of how to do it:
name: Laravel Dusk Testing
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Composer
uses: actions/setup-composer@v1
with:
php: 8.0
- name: Install dependencies
run: composer install --no-autoload
- name: Download ChromeDriver
uses: actions/download@v2
with:
url: https://chromedriver.storage.googleapis.com/latest/chromedriver_linux64.zip
dest: chromedriver.zip
- name: Extract ChromeDriver
run: unzip chromedriver.zip
- name: Set up ChromeDriver
uses: actions/setup-selenium@v1
with:
selenium_version: latest
driver_path: ./chromedriver
- name: Run tests
run: |
export DISPLAY=:0
php artisan dusk:test --webdriver=selenium --driver-path=./chromedriver
Issue 4: Laravel Key and Environment Variables
The fourth issue that you might encounter is related to the Laravel key and environment variables. Laravel uses an application key to encrypt and decrypt sensitive data, and you need to make sure that the key is set correctly during testing.
To resolve this issue, you can set the Laravel key as an environment variable in your .yml
file. Here's an example of how to do it:
name: Laravel Dusk Testing
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Composer
uses: actions/setup-composer@v1
with:
php: 8.0
- name: Install dependencies
run: composer install --no-autoload
- name: Set up Laravel key
uses: actions/setup-env@v2
with:
keys: APP_KEY=base64:<your_app_key_here>
- name: Download ChromeDriver
uses: actions/download@v2
with:
url: https://chromedriver.storage.googleapis.com/latest/chromedriver_linux64.zip
dest: chromedriver.zip
- name: Extract ChromeDriver
run: unzip chromedriver.zip
- name: Set up ChromeDriver
uses: actions/setup-selenium@v1
with:
selenium_version: latest
driver_path: ./chromedriver
- name: Run tests
run: |
export DISPLAY=:0
php artisan dusk:test --webdriver=selenium --driver-path=./chromedriver
Replace <your_app_key_here>
with your actual Laravel application key.
Issue 5: Test Timeout
The fifth issue that you might encounter is related to the test timeout. Laravel Dusk tests can take a long time to run, especially if they involve complex interactions or slow websites.
To resolve this issue, you can increase the test timeout by setting the --timeout
flag when running the Laravel Dusk command. Here's an example of how to do it:
name: Laravel Dusk Testing
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Composer
uses: actions/setup-composer@v1
with:
php: 8.0
- name: Install dependencies
run: composer install --no-autoload
- name: Set up Laravel key
uses: actions/setup-env@v2
with:
keys: APP_KEY=base64:<your_app