问题
...
$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:
- You should never use dusk in production or public site, even if it's configured as dev (security concerns).
- 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.
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
- your
Final thoughts.
A good workflow for this would be:
- Test your app locally
- Commit changes to VCS (Version Control System) with CI (Continuous Integration) - for example gitlab - and run dusk test there.
- 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