简体   繁体   中英

Laravel Dusk Sessions on

I have a laravel 5.4 project set up on a vagrant machine and I'm trying to create Laravel Dusk tests on it. It was a bit tricky and I followed the tutorial here : http://www.jesusamieiro.com/using-laravel-dusk-with-vagrant-homestead/

It runs fine, but the session variables don't seem to be saving. I have this code in a post route

if (!session('user_name')) {
        $request->session()->flash("message", "Your session expired. Click "Please Confirm" to approve your monthly donation.");
        return redirect()->back();
    }

and it is set on the get request when the page is first fetched. I have this test in dusk:

$browser->visit("http://support.welcome.dev/?layout_id={$layout}&purl={$supporter->purl}&user_name={$supporter->name_first}&amount=10&ct={$hash}")
                ->press("Please Confirm")
                ->assertPathIs("/confirm");

This test fails and is redirected with the message session has expired. However, it works just fine when when the code in the post route checking for the user_name variable is commented out. The original code works when I test it manually on a browser.

Any help is appreciated.

$user = factory(User::class)->create([
            'email' => 'taylor@laravel.com',
        ]);

        $this->browse(function ($browser) use ($user) {
            $browser->visit('/login')
                    ->type('email', $user->email)
                    ->type('password', 'secret')
                    ->press('Login')
                    ->assertPathIs('/home');
        });

This code is write on https://laravel.com/docs/5.4/dusk . i think this can help you. =)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM