Jump to content
Sign in to follow this  
mstdmstdd

Dusk loginAs methods opens Login page

Recommended Posts

  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
{
/**
* A Dusk test example.
*
* @return void
*/
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,
],

To check that I connected to the db I need I read user by $logged_user_id, like:
 
                $loggedUser= User::find($logged_user_id);
                echo '$loggedUser->name::'.print_r($loggedUser->name,true);
                $browser->loginAs(User::find($logged_user_id))
and in the console name of the user with id == $logged_user_id, so I suppose, that:
 
my testing script works under db I work with
I have user with id == $logged_user_id
 

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

Thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.