Jump to content

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!

Link to comment
https://forums.phpfreaks.com/topic/307270-dusk-loginas-methods-opens-login-page/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.