Laravel Dusk test for remote site not work

2019-08-26 23:55发布

...
$this->browse(function (Browser $browser) {
 $browser->visit(url()->route('login'))
  ->type('email', 'user.one@email.com')
  ->type('password', 'something')
  ->press('Login')
  ->pause(60*60*1000)
  ->assertRouteIs('dashboard')
...

It works on local which is use APP_URL something like 'https://project.dev' but not work for remote 'https://project.com' and 'http://123.123.12.12'.

Errors or Problems

  • login test on remote site not work

Different between local and remote

  • dusk installed in local
  • dusk not installed in remote

What i did to try solve it

  • I read that Chrome need HTTPS. I given https to it. Still not work.

1条回答
2楼-- · 2019-08-27 00:35

Without exact errors, it is difficult, to answer your question, but from what you described I can provide some hints:

  1. You should never use dusk in production or public site, even if it's configured as dev (security concerns).
  2. I assume, that you are trying to run dusk on your dev, with remote APP_URL. This is wrong concept, cause your tests can manipulate data on db. In case your local and remote uses the same database it might work, but as said, bringing further problems.
  3. Considering above, some of your tests could pass, if you make sure the following requirements are satisfied:

    • your .env APP_URL matches in both locations
    • you don't use migrations,factories etc in your dusk tests
    • you don't write any data to db (via testing register page for example) cause it would be a nightmare to handle these changes, when using the same db and running tests for local and remote
    • you modify DuskTestCase.php to add --no-sandbox option. This speeds tests up - so you shouldn't need to use pause

Final thoughts.

A good workflow for this would be:

  1. Test your app locally
  2. Commit changes to VCS (Version Control System) with CI (Continuous Integration) - for example gitlab - and run dusk test there.
  3. Deploy to production, if tests are passing, either manually, or via deploy scripts - CD (Continuous Delivery)
查看更多
登录 后发表回答