i'm trying to create a Page that extends "DuskTestCase" to avoid having to write login logic in every tests. However, when I run the tests, it fails to assert that after a login, the browser is at the home page. Here is one of the things that I tried. Note that Auth::check() returns false, and the problem surely comes from here and I can't figure why it does not authenticate the user as described in the docs: https://laravel.com/docs/5.6/dusk The ICOUser model also is implementing Illuminate\Contracts\Auth\Authenticatable contract.
LoginPage.php
namespace Tests\Browser\Pages;
use ARM\Tcollect\ICO\ICOUser;
use Laravel\Dusk\Browser;
use Illuminate\Support\Facades\Auth;
class LoginPage extends Page
{
const SUDOER_ID = 499;
/**
* Get the URL for the page.
*
* @return string
*/
public function url()
{
return '/';
}
/**
* Abstract the Login functionality
*
* @param \Laravel\Dusk\Browser $browser
* @param string $name
* @return void
*/
public function loginSudoer(Browser $browser)
{
$browser->loginAs(ICOUser::find(static::SUDOER_ID))- >visit('/home');
}
}
The failing method on my LoginTest.php is the following:
public function testLoginSudoer()
{
$this->browse(function (Browser $browser){
$browser->on(new LoginPage)
->loginSudoer()
->waitForLocation('/home', 10)
->assertPathIs('/home')
->visit('/logout');
});
}
Aucun commentaire:
Enregistrer un commentaire