Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lara15053's avatar

Has any got Dusk to work with Bitbucket Pipelines?

I've been trying to get Laravel Dusk working correctly with Bitbucket pipelines. Here's what my current configuration files looks like:

image: mightycode/docker-laravel-dusk

pipelines:
  default:
    - step:
        caches:
          - composer
        script:
          - /usr/bin/chromium --version
          - cp .env.dusk.local .env
          - composer install --no-interaction
          - npm install
          - npm run production
          - Xvfb :0 -screen 0 1280x960x24 &
          - export DISPLAY=:0
          - touch database/testing.sqlite
          - php artisan serve &
          - php artisan dusk
          - vendor/bin/phpunit

Once it reaches the /usr/bin/chromium command I see the following error and the system hangs:

[419:435:0922/195622.191318:ERROR:bus.cc(427)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
Xlib:  extension "RANDR" missing on display ":0".
[419:448:0922/195622.299121:ERROR:zygote_host_impl_linux.cc(277)] Failed to adjust OOM score of renderer with pid 472: Permission denied
(chromium:419): LIBDBUSMENU-GLIB-WARNING **: Unable to get session bus: Failed to execute child process "dbus-launch" (No such file or directory)
[419:448:0922/195622.383154:ERROR:zygote_host_impl_linux.cc(277)] Failed to adjust OOM score of renderer with pid 478: Permission denied
[419:448:0922/195622.451447:ERROR:zygote_host_impl_linux.cc(277)] Failed to adjust OOM score of renderer with pid 502: Permission denied
[419:448:0922/195622.678652:ERROR:zygote_host_impl_linux.cc(277)] Failed to adjust OOM score of renderer with pid 520: Permission denied

I think the above error is causing the next error I see since Dusk cannot connect to chromium (since it failed to start):

1) Tests\Browser\PickupFormTest::testExample
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"binary":"\/usr\/bin\/chromium","args":["--window-size=1280x960","--disable-gpu"]}}}
Failed to connect to localhost port 9515: Connection refused

When I run the config file locally using Convey everything works fine. It's just once I push it up to bitbucket it fails.

Also heres the slightly modified contents of my DuskTestCase.php file:

<?php

namespace Tests;

use Laravel\Dusk\TestCase as BaseTestCase;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Symfony\Component\Process\ProcessBuilder;

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()
    {
        $desiredCapabilities = DesiredCapabilities::chrome();

        $options = new ChromeOptions();

        $options->setBinary('/usr/bin/chromium');

        $options->addArguments([
            '--no-sandbox',
            '--window-size=1280x960',
            '--disable-gpu',
        ]);

        $desiredCapabilities->setCapability(ChromeOptions::CAPABILITY, $options);

        return RemoteWebDriver::create(
            'http://localhost:9515', $desiredCapabilities
        );
    }
}

Anyone have any ideas on how to get Dusk working with Bitbucket Pipelines?

0 likes
3 replies
kortby's avatar

(new ChromeOptions)->addArguments([ '--disable-gpu', '--headless', '--no-sandbox', '--disable-dev-shm-usage', '--window-size=1920,1080', ]);

1 like
garycocs's avatar

Really struggling to get bitbucket pipelines working with laravel dusk.

A lot of legacy versions out there with older versions of php not working.

Has anyone this working correctly at the moment?

Orclyx's avatar

I was looking for advice on this topic this week and was able to put enough together to get this functioning, kortby's reply included. The pipeline config I'm going to share here might do more than you need, but I don't want to edit it too much in case I add a mistake!

# bitbucket-pipelines.yml

pipelines:
  default:
    - step:
        name: Laravel Mix
        image: node:lts
        caches:
          - node
        script:
          - npm ci
          - npm run production
        artifacts:
          - public/**
    - step:
        name: Tests
        image: php:8.1
        caches:
          - composer
        script:
          - apt-get update && apt-get install -y libzip-dev unzip
          - docker-php-ext-install -j$(nproc) pdo_mysql zip

          - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
          - composer config http-basic.nova.laravel.com "$NOVA_USERNAME" "$NOVA_PASSWORD"
          - composer install

          - cp .env.example .env
          - php artisan key:generate
          - php artisan storage:link
          - sed -i 's|APP_URL=http://localhost|APP_URL=http://127.0.0.1:8000|g' .env
          - sed -i 's|DB_PASSWORD=|DB_PASSWORD=root|g' .env

          - php artisan test --without-tty --parallel

          - php artisan dusk:chrome-driver
          - php artisan serve --no-reload &
          - php artisan dusk --without-tty
        services:
          - chrome
          - database
        artifacts:
          - tests/Browser/screenshots/**
definitions:
  services:
    chrome:
      image: drupalci/chromedriver:dev
    database:
      image: mariadb:latest
      variables:
        MARIADB_DATABASE: laravel
        MARIADB_ROOT_PASSWORD: root
# tests/DuskTestCase.php (extra options when $ENV['CI'])

protected function driver()
{
    $options = (new ChromeOptions)->addArguments(collect([
        '--window-size=1920,1080',
    ])->when($_ENV['CI'] ?? false, function ($items) {
        return $items->merge([
            '--no-sandbox',
            '--disable-dev-shm-usage',
        ]);
    })->unless($this->hasHeadlessDisabled(), function ($items) {
        return $items->merge([
            '--disable-gpu',
            '--headless',
        ]);
    })->all());

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

Please or to participate in this conversation.