elgabo.msn@gmail.com's avatar

[5.4][dusk]: Login example test fails

Hi guys.

I can't make the example login test works, here's my code:

/home/vagrant/Code/proyectoFinal/tests/Browser/authTest.php
use Illuminate\Support\Facades\DB;
use Tests\DuskTestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use App\User;
use Laravel\Dusk\Chrome;

class Auth extends DuskTestCase
{
    /** @test */
    public function autenticar_usuario()
    {
        $unUsuario = factory(User::class)->create();
        $this->browse(function ($browser) use ($unUsuario) {
            $browser->visit('/')
                ->type('email', $unUsuario->email)
                ->type('password', 'secret')
                ->press('Login')
                ->AssertSee('Bienvenido');
        });
    }
}

My routes are these:

Route::get('/', 'HomeController@index')->name('login');
Auth::routes();
Route::get('/home', 'HomeController@index');

I've red that may be it has something to do with sessions, so here's my .env.dusk.local

APP_ENV=testing
APP_KEY=someLettersAndNumbers
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://proyecto.app

DB_CONNECTION=testing_db

DB_HOST=localhost
DB_DATABASE=testing

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

I am running Homestead 1.0.1 and Laravel 5.4.

This feature works fine when I run it from .env, which is using a mysql driver, but I don't think it's related to db because I've did others tests to try it and runs without any issues. When I do

art dusk

screenshot shows I'm still stuck in login page.

Any help would be appreciated.

Thanks in advance.

0 likes
2 replies
elgabo.msn@gmail.com's avatar
Level 4

Eureka! I've found out what was wrong. It seems there was some dirty magic -at least for newbies like me- with this code in DuskTestCase:

abstract class DuskTestCase extends BaseTestCase
{
    use CreatesApplication;
    use DatabaseMigrations;
    //use DatabaseTransactions;

If DatabaseTransactions is removed, then it works flawlessly.

1 like
bognix's avatar

Worked for me as well. Could anyone explain me why use DatabaseTransactions is causing the problem?

Please or to participate in this conversation.