結論
Laravel8.x対応
- Chrome Driver は browser-actions/setup-chrome@v1 の最新版を使いました。
- Chrome Browser は github actions の ubuntsuの最新版を使う形で対応しました。
- ChromeDriver起動時にポート指定
--port=9515
を追加しました。 - (現在2024/12/27時点のバージョン)
- Google Chrome 131.0.6778.139
- ChromeDriver 131.0.6778.204
- name: Set env CHROME_VERSION
run: |
echo CHROME_VERSION=`/opt/google/chrome/chrome --version | cut -d " " -f3 | cut -d "." -f1` >> $GITHUB_ENV
# https://github.com/browser-actions/setup-chrome (community)
- name: Download Chrome and Chrome Driver(use Chrome Driver Only)
uses: browser-actions/setup-chrome@v1
id: setup-chrome
with:
chrome-version: ${{ env.CHROME_VERSION }}
install-chromedriver: true
- name: Chrome Driver Copy
run: sudo \cp -f ${{ steps.setup-chrome.outputs.chromedriver-path }} ./vendor/laravel/dusk/bin/chromedriver-linux
- name: Chrome Driver Permission Denied 対応
run: |
sudo chmod +x ./vendor/laravel/dusk/bin/chromedriver-linux
- name: Start Chrome Driver
run: ./vendor/laravel/dusk/bin/chromedriver-linux --port=9515 &
- name: Run Laravel Server
run: php artisan serve &
Laravel8.x github actionエラー内容
Facebook\WebDriver\Exception\UnknownErrorException: unknown error: Chrome failed to start: crashed.
Run php artisan dusk tests/Browser/Manage/LogManageTest.php no_manual
Warning: TTY mode requires /dev/tty to be read/writable.
PHPUnit [9](https://github.com/opensource-workshop/connect-cms/actions/runs/12483864336/job/34840363665#step:23:10).6.21 by Sebastian Bergmann and contributors.
E 1 / 1 ([10](https://github.com/opensource-workshop/connect-cms/actions/runs/12483864336/job/34840363665#step:23:11)0%)
Time: 00:03.198, Memory: 28.00 MB
There was 1 error:
1) Tests\Browser\Manage\LogManageTest::testInvoke
Facebook\WebDriver\Exception\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.)
/home/runner/work/connect-cms/connect-cms/vendor/php-webdriver/webdriver/lib/Exception/WebDriverException.php:146
/home/runner/work/connect-cms/connect-cms/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:359
/home/runner/work/connect-cms/connect-cms/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:129
/home/runner/work/connect-cms/connect-cms/tests/DuskTestCase.php:92
/home/runner/work/connect-cms/connect-cms/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:219
/home/runner/work/connect-cms/connect-cms/vendor/laravel/framework/src/Illuminate/Support/helpers.php:234
/home/runner/work/connect-cms/connect-cms/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:220
/home/runner/work/connect-cms/connect-cms/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:98
/home/runner/work/connect-cms/connect-cms/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:66
/home/runner/work/connect-cms/connect-cms/tests/DuskTestCase.php:[11](https://github.com/opensource-workshop/connect-cms/actions/runs/12483864336/job/34840363665#step:23:12)2
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
Error: Process completed with exit code 2.
Laravel9.x対応
- ChromeDriverのダウンロードパスが変わったため対応しました。
- ChromeDriverとChromeBrowserの末尾バージョンまで合わせるよう対応しました。
- ChromeDriver起動時にポート指定
--port=9515
を追加しました。 - (現在2024/12/27時点のバージョン)
- Google Chrome 131.0.6778.139
- ChromeDriver 131.0.6778.139
# https://readouble.com/laravel/9.x/ja/dusk.html#managing-chromedriver-installations
# https://readouble.com/laravel/9.x/ja/dusk.html#running-tests-on-github-actions
# Chrome Version と Chrome Driverを同じにする
- name: Upgrade Chrome Driver
run: php artisan dusk:chrome-driver `/opt/google/chrome/chrome --version | cut -d " " -f3`
- name: Chrome Driver Copy
run: sudo \cp -f ./vendor/laravel/dusk/bin/chromedriver-linux64/chromedriver ./vendor/laravel/dusk/bin/chromedriver-linux
- name: Chrome Driver Permission Denied 対応
run: |
sudo chmod +x ./vendor/laravel/dusk/bin/chromedriver-linux64/chromedriver
sudo chmod +x ./vendor/laravel/dusk/bin/chromedriver-linux
- name: Start Chrome Driver
run: ./vendor/laravel/dusk/bin/chromedriver-linux --port=9515 &
- name: Run Laravel Server
run: php artisan serve &
Laravel9.x github actionエラー内容
RuntimeException: Invalid path to Chromedriver
Run php artisan dusk tests/Browser/Manage/LogManageTest.php no_manual
Warning: TTY mode requires /dev/tty to be read/writable.
PHPUnit 9.6.21 by Sebastian Bergmann and contributors.
E 1 / 1 (100%)
Time: 00:00.002, Memory: 10.00 MB
There was 1 error:
1) Tests\Browser\Manage\LogManageTest::testInvoke
RuntimeException: Invalid path to Chromedriver [/home/runner/work/connect-cms/connect-cms/vendor/laravel/dusk/src/Chrome/../../bin/chromedriver-linux]. Make sure to install the Chromedriver first by running the dusk:chrome-driver command. in /home/runner/work/connect-cms/connect-cms/vendor/laravel/dusk/src/Chrome/ChromeProcess.php:56
Stack trace:
#0 /home/runner/work/connect-cms/connect-cms/vendor/laravel/dusk/src/Chrome/SupportsChrome.php(62): Laravel\Dusk\Chrome\ChromeProcess->toProcess()
#1 /home/runner/work/connect-cms/connect-cms/vendor/laravel/dusk/src/Chrome/SupportsChrome.php(31): Laravel\Dusk\TestCase::buildChromeProcess()
#2 /home/runner/work/connect-cms/connect-cms/tests/DuskTestCase.php(72): Laravel\Dusk\TestCase::startChromeDriver()
#3 /home/runner/work/connect-cms/connect-cms/vendor/phpunit/phpunit/src/Framework/TestSuite.php(629): Tests\DuskTestCase::prepare()
#4 /home/runner/work/connect-cms/connect-cms/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(651): PHPUnit\Framework\TestSuite->run()
#5 /home/runner/work/connect-cms/connect-cms/vendor/phpunit/phpunit/src/TextUI/Command.php([14](https://github.com/opensource-workshop/connect-cms/actions/runs/12459278909/job/34775914873#step:21:15)6): PHPUnit\TextUI\TestRunner->run()
#6 /home/runner/work/connect-cms/connect-cms/vendor/phpunit/phpunit/src/TextUI/Command.php(99): PHPUnit\TextUI\Command->run()
#7 /home/runner/work/connect-cms/connect-cms/vendor/phpunit/phpunit/phpunit(107): PHPUnit\TextUI\Command::main()
#8 {main}
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
Error: Process completed with exit code 2.
参考
- php - "Invalid path to Chromedriver" when running Laravel Dusk - Stack Overflow
https://stackoverflow.com/questions/78827506/invalid-path-to-chromedriver-when-running-laravel-dusk- Laravel9はEOLで、対象バージョンのDuskは修正されないようです。
- ChromeDriver(EdgeDriver)のVer.128からデフォルトポート9515がランダムに変更されました。 #Excel - Qiita
https://qiita.com/yaju/items/3c4e516746c8db830c9c
所感
- サポート期限切れであっても、どうしても動かさないといけない人向けです。Laravelをアップデートできるのであれば、アップデートして公式の方法で動作させるのが良いと思います。
- Laravel8.x、Laravel9.xはサポート期間切れです。