Summer Sale! All accounts are 50% off this week.

brainbox's avatar

Github Actions + Dusk

For some reason I cannot get Dusk tests to successfully run with Github Actions. This is a fresh install of Laravel with only the example tests.

See my example repo here: https://github.com/brokerbridge/github-actions

Dusk is installed and both PHPUnit and Dusk tests run successfully locally.

The Dusk action is from the Laravel docs here: https://laravel.com/docs/7.x/dusk#running-tests-on-github-actions

Any help here would be really appreciated!

Thanks!

0 likes
7 replies
andersb's avatar

Can you start by posting the errors from Github Actions?

I suggest that you then have a look at your environment variables and perhaps dump these during debugging to ensure that you are using the correct ones during testing.

You are defining the DB_CONNECTION=sqlite and DB_DATABASE=:memory: in your phpunit.xml file: https://github.com/brokerbridge/github-actions/blob/master/phpunit.xml#L30 but you also create a MySQL database with a root user during setup. Note that you have not set a DB_PASSWORD in .env.example (which is copied to .env during setup) nor in .env.testing.

Note that you can pass certain variables directly to dusk using like done for phpunit here

brainbox's avatar

Hey @andersb,

You can see the error I'm getting below, it's a standard PHPUnit/Dusk error so I believe it's just an issue with the configuration.

F                                                                   1 / 1 (100%)

Time: 14.03 seconds, Memory: 18.00 MB

There was 1 failure:

1) Tests\Browser\ExampleTest::testBasicExample
Did not see expected text [Laravel] within element [body].
Failed asserting that false is true.

The issue I have though is that my environment variables are the defaults. Eg. sqlite for db_connection and :memory for db_database. Should the Laravel provided Action not work with the defaults for Laravel?

Perhaps I need to run the Dusk tests via sqlite, to match the PHPUnit config that is default by Laravel?

andersb's avatar
andersb
Best Answer
Level 3

@brainbox I just confirmed the issue, and maybe this would be a good opportunity to add this to the Laravel documentation, but the problem is simply that Github uses 127.0.0.1:8000 as host, so it is important that your .env file has set APP_URL=http://127.0.0.1:8000.

You can force this by setting the variable in your workflow like so:

...
- name: Run Dusk Tests
  run: php artisan dusk
  env:
    APP_URL="http://127.0.0.1:8000"

Does this solve your issue?

brainbox's avatar

Hey @andersb,

Thank you, I saw the PR got merged this morning.

This is the code that worked for me, got here cause of you so thanks so much.

- name: Run Dusk Tests
        env:
          APP_URL: "http://127.0.0.1:8000"
        run: php artisan dusk
andersb's avatar

Nice to hear that it worked for you @brainbox , and yes now the documentation includes this. Happy to help. Please mark this as solved.

jonathan-voxie's avatar

I have the same configuration, but github actions throws me the exception.

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')
Adgower's avatar

When I run this it fails:

php artisan serve —host=api.example.test

Please or to participate in this conversation.