Laravel Dusk test for remote site not work

旧巷老猫 提交于 2019-12-13 03:43:27

问题


...
$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. 😫
  • I pause the dusk longer. With the dusk browser open, i try type the username & password and submit it. Still not work. 😫

Reported on laravel dusk github as well


回答1:


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)


来源:https://stackoverflow.com/questions/48809695/laravel-dusk-test-for-remote-site-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!