Search code examples
laravel-5laravel-dusk

Laravel Dusk loginAs returns a blank page at http://localhost:8000/_dusk/login/1


Have trying out basic tests on laravel-dusk, and so far I am unable to automate login using the loginAs function.

namespace Tests\Browser;

use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use App\User;

class ModuleTest extends DuskTestCase
{
    /**
     * @test
     * @group plots
     */

    public function loginAsRoot()
    {
        $this->browse(function (Browser $browser) {
            $browser->loginAs(User::find(1))
                ->assertSee('some text');
        });
    }
}

Solution

  • I found that the original question-asker answered his own question here:

    wamae • Feb 23, 2018 BEST ANSWER Fixed it: Thought the loginAs would hit my default controller "plots" by default, turns out I have to specify it in visit function.

    use Tests\DuskTestCase;
    use Laravel\Dusk\Browser;
    use Illuminate\Foundation\Testing\DatabaseMigrations;
    use App\User;
    
    class PlotsTest extends DuskTestCase
    {
        /**
         * @test
         * @group plots
         */
    
        public function loginAsRoot()
        {
            $this->browse(function (Browser $browser) {
                $user = User::find(1);
                $browser->loginAs($user)
                        ->visit('/plots')
                    ->assertSee('Deed Plan No');
            });
        }
    }
    

    (Unfortunately this doesn't help me because my test already is using visit().)