Dusk loginAs methods opens Login page

Posted 6 months ago by mstdmstd

Hello , In my laravel 5.6.20 application I created new testing file

tests/Browser/documentCategoriesCRUD.php:

<?php

namespace Tests\Browser;

use Auth;
use DB;

use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use PhpUnit\Framework; // vendor/phpunit/phpunit/src/Framework/Assert.php
use Tests\TestCase;
use App\User;
use App\Settings;

use App\DocumentCategory;


class documentCategoriesCRUDTest_prior extends DuskTestCase
{
    public function testExample()   // php artisan dusk  tests/Browser/documentCategoriesCRUD.php
    {
        $logged_user_id = 5;   // There is user in userrs table in db
        $site_name = Settings::getValue('site_name', '');

        try {


            $document_category_id= '';
            $this->browse(function (Browser $browser) use ($site_name, $document_category_id, $logged_user_id) {
                $browser->resize(1920, 1080); // Width and Height

                $new_document_category_name = 'new document category created  at ' . time();
                $browser->loginAs(User::find($logged_user_id))
                        ->visit('/admin/dashboard#/admin/document_categories/edit/new')
                        ->assertTitle('Document Categories of ' . $site_name)
                ;

            });

            echo ' New document category id::'.print_r($document_category_id,true);

        } catch (Exception $e) {

            throw $e;
        }

        return;

    }
}

But I got error that page if not found and in printscreen I see login(auth model) page.

I have default config/auth.php and in config/database.php:

<?php

return [

    'default' => env('DB_CONNECTION', 'mysql'),

    'connections' => [

        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),  // THAT IS MY WORKING DB
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => 'tsk_',
            'strict' => true,
            'engine' => null,
        ],

        'testing' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DUSK_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => 'tsk_',
            'strict' => true,
            'engine' => null,
        ],

As that are first steps with dusk I do not need any special envirement here... What did I miss in dusk config ?

Thanks!

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.