Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assertGuest causes NoSuchElementException in the next call #911

Closed
lanort opened this issue Jul 23, 2021 · 5 comments · Fixed by #912
Closed

assertGuest causes NoSuchElementException in the next call #911

lanort opened this issue Jul 23, 2021 · 5 comments · Fixed by #912

Comments

@lanort
Copy link

lanort commented Jul 23, 2021

If I use the assertGuest function, the next call to type (into eg the email field) causes a Facebook\WebDriver\Exception\NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"body email"}.

If I remove the call to assertGuest() , it works again.

Used System

  • Windows 10 Version 20H2 (Build 19042.1110)
  • WSL2 for using sail with Ubuntu 20.04.2 LTS
  • Current laravel/laravel 8.5.22
  • Current laravel/sail 1.8.6
  • Current laravel/dusk 6.15.1

Steps to reproduce:

1) Install laravel

C:\Users\alexa\Desktop>laravel new guesttest

 _                               _
| |                             | |
| |     __ _ _ __ __ ___   _____| |
| |    / _` | '__/ _` \ \ / / _ \ |
| |___| (_| | | | (_| |\ V /  __/ |
|______\__,_|_|  \__,_| \_/ \___|_|

    Creating a "laravel/laravel" project at "./guesttest"
    Installing laravel/laravel (v8.5.22)
  - Installing laravel/laravel (v8.5.22): Extracting archive
    Created project in C:\Users\alexa\Desktop/guesttest
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
    Loading composer repositories with package information
    Updating dependencies
    Lock file operations: 105 installs, 0 updates, 0 removals
  - Locking asm89/stack-cors (v2.0.3)
  - Locking brick/math (0.9.2)
  - Locking doctrine/inflector (2.0.3)
  - Locking doctrine/instantiator (1.4.0)
  - Locking doctrine/lexer (1.2.1)
  - Locking dragonmantank/cron-expression (v3.1.0)
  - Locking egulias/email-validator (2.1.25)
  - Locking facade/flare-client-php (1.8.1)
  - Locking facade/ignition (2.11.2)
  - Locking facade/ignition-contracts (1.0.2)
  - Locking fakerphp/faker (v1.15.0)
  - Locking fideloper/proxy (4.4.1)
  - Locking filp/whoops (2.14.0)
  - Locking fruitcake/laravel-cors (v2.0.4)
  - Locking graham-campbell/result-type (v1.0.1)
  - Locking guzzlehttp/guzzle (7.3.0)
  - Locking guzzlehttp/promises (1.4.1)
  - Locking guzzlehttp/psr7 (2.0.0)
  - Locking hamcrest/hamcrest-php (v2.0.1)
  - Locking laravel/framework (v8.51.0)
  - Locking laravel/sail (v1.8.6)
  - Locking laravel/tinker (v2.6.1)
  - Locking league/commonmark (1.6.6)
  - Locking league/flysystem (1.1.4)
  - Locking league/mime-type-detection (1.7.0)
  - Locking mockery/mockery (1.4.3)
  - Locking monolog/monolog (2.3.1)
  - Locking myclabs/deep-copy (1.10.2)
  - Locking nesbot/carbon (2.50.0)
  - Locking nikic/php-parser (v4.12.0)
  - Locking nunomaduro/collision (v5.5.0)
  - Locking opis/closure (3.6.2)
  - Locking phar-io/manifest (2.0.3)
  - Locking phar-io/version (3.1.0)
  - Locking phpdocumentor/reflection-common (2.2.0)
  - Locking phpdocumentor/reflection-docblock (5.2.2)
  - Locking phpdocumentor/type-resolver (1.4.0)
  - Locking phpoption/phpoption (1.7.5)
  - Locking phpspec/prophecy (1.13.0)
  - Locking phpunit/php-code-coverage (9.2.6)
  - Locking phpunit/php-file-iterator (3.0.5)
  - Locking phpunit/php-invoker (3.1.1)
  - Locking phpunit/php-text-template (2.0.4)
  - Locking phpunit/php-timer (5.0.3)
  - Locking phpunit/phpunit (9.5.7)
  - Locking psr/container (1.1.1)
  - Locking psr/event-dispatcher (1.0.0)
  - Locking psr/http-client (1.0.1)
  - Locking psr/http-factory (1.0.1)
  - Locking psr/http-message (1.0.1)
  - Locking psr/log (1.1.4)
  - Locking psr/simple-cache (1.0.1)
  - Locking psy/psysh (v0.10.8)
  - Locking ralouphie/getallheaders (3.0.3)
  - Locking ramsey/collection (1.1.3)
  - Locking ramsey/uuid (4.1.1)
  - Locking sebastian/cli-parser (1.0.1)
  - Locking sebastian/code-unit (1.0.8)
  - Locking sebastian/code-unit-reverse-lookup (2.0.3)
  - Locking sebastian/comparator (4.0.6)
  - Locking sebastian/complexity (2.0.2)
  - Locking sebastian/diff (4.0.4)
  - Locking sebastian/environment (5.1.3)
  - Locking sebastian/exporter (4.0.3)
  - Locking sebastian/global-state (5.0.3)
  - Locking sebastian/lines-of-code (1.0.3)
  - Locking sebastian/object-enumerator (4.0.4)
  - Locking sebastian/object-reflector (2.0.4)
  - Locking sebastian/recursion-context (4.0.4)
  - Locking sebastian/resource-operations (3.0.3)
  - Locking sebastian/type (2.3.4)
  - Locking sebastian/version (3.0.2)
  - Locking swiftmailer/swiftmailer (v6.2.7)
  - Locking symfony/console (v5.3.2)
  - Locking symfony/css-selector (v5.3.0)
  - Locking symfony/deprecation-contracts (v2.4.0)
  - Locking symfony/error-handler (v5.3.3)
  - Locking symfony/event-dispatcher (v5.3.0)
  - Locking symfony/event-dispatcher-contracts (v2.4.0)
  - Locking symfony/finder (v5.3.0)
  - Locking symfony/http-client-contracts (v2.4.0)
  - Locking symfony/http-foundation (v5.3.3)
  - Locking symfony/http-kernel (v5.3.3)
  - Locking symfony/mime (v5.3.2)
  - Locking symfony/polyfill-ctype (v1.23.0)
  - Locking symfony/polyfill-iconv (v1.23.0)
  - Locking symfony/polyfill-intl-grapheme (v1.23.0)
  - Locking symfony/polyfill-intl-idn (v1.23.0)
  - Locking symfony/polyfill-intl-normalizer (v1.23.0)
  - Locking symfony/polyfill-mbstring (v1.23.0)
  - Locking symfony/polyfill-php72 (v1.23.0)
  - Locking symfony/polyfill-php73 (v1.23.0)
  - Locking symfony/polyfill-php80 (v1.23.0)
  - Locking symfony/process (v5.3.2)
  - Locking symfony/routing (v5.3.0)
  - Locking symfony/service-contracts (v2.4.0)
  - Locking symfony/string (v5.3.3)
  - Locking symfony/translation (v5.3.3)
  - Locking symfony/translation-contracts (v2.4.0)
  - Locking symfony/var-dumper (v5.3.3)
  - Locking theseer/tokenizer (1.2.0)
  - Locking tijsverkoyen/css-to-inline-styles (2.2.3)
  - Locking vlucas/phpdotenv (v5.3.0)
  - Locking voku/portable-ascii (1.5.6)
  - Locking webmozart/assert (1.10.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
    Package operations: 105 installs, 0 updates, 0 removals
      - Downloading league/commonmark (1.6.6)
  - Downloading laravel/framework (v8.51.0)
  - Downloading facade/ignition (2.11.2)
      - Downloading nikic/php-parser (v4.12.0)
      - Downloading phar-io/manifest (2.0.3)
  - Downloading phpunit/phpunit (9.5.7)
 0/6 [>---------------------------]   0%
 1/6 [====>-----------------------]  16%
 2/6 [=========>------------------]  33%
 3/6 [==============>-------------]  50%
 4/6 [==================>---------]  66%
 5/6 [=======================>----]  83%
 6/6 [============================] 100%  - Installing doctrine/inflector (2.0.3): Extracting archive
      - Installing doctrine/lexer (1.2.1): Extracting archive
      - Installing symfony/polyfill-ctype (v1.23.0): Extracting archive
      - Installing webmozart/assert (1.10.0): Extracting archive
      - Installing dragonmantank/cron-expression (v3.1.0): Extracting archive
      - Installing symfony/polyfill-php80 (v1.23.0): Extracting archive
      - Installing symfony/polyfill-mbstring (v1.23.0): Extracting archive
      - Installing symfony/var-dumper (v5.3.3): Extracting archive
      - Installing symfony/polyfill-intl-normalizer (v1.23.0): Extracting archive
      - Installing symfony/polyfill-intl-grapheme (v1.23.0): Extracting archive
      - Installing symfony/string (v5.3.3): Extracting archive
      - Installing psr/container (1.1.1): Extracting archive
      - Installing symfony/service-contracts (v2.4.0): Extracting archive
      - Installing symfony/polyfill-php73 (v1.23.0): Extracting archive
      - Installing symfony/deprecation-contracts (v2.4.0): Extracting archive
      - Installing symfony/console (v5.3.2): Extracting archive
      - Installing psr/log (1.1.4): Extracting archive
      - Installing monolog/monolog (2.3.1): Extracting archive
      - Installing voku/portable-ascii (1.5.6): Extracting archive
      - Installing phpoption/phpoption (1.7.5): Extracting archive
      - Installing graham-campbell/result-type (v1.0.1): Extracting archive
      - Installing vlucas/phpdotenv (v5.3.0): Extracting archive
      - Installing symfony/css-selector (v5.3.0): Extracting archive
      - Installing tijsverkoyen/css-to-inline-styles (2.2.3): Extracting archive
      - Installing symfony/routing (v5.3.0): Extracting archive
      - Installing symfony/process (v5.3.2): Extracting archive
      - Installing symfony/polyfill-php72 (v1.23.0): Extracting archive
      - Installing symfony/polyfill-intl-idn (v1.23.0): Extracting archive
      - Installing symfony/mime (v5.3.2): Extracting archive
      - Installing symfony/http-foundation (v5.3.3): Extracting archive
      - Installing symfony/http-client-contracts (v2.4.0): Extracting archive
      - Installing psr/event-dispatcher (1.0.0): Extracting archive
      - Installing symfony/event-dispatcher-contracts (v2.4.0): Extracting archive
      - Installing symfony/event-dispatcher (v5.3.0): Extracting archive
      - Installing symfony/error-handler (v5.3.3): Extracting archive
      - Installing symfony/http-kernel (v5.3.3): Extracting archive
      - Installing symfony/finder (v5.3.0): Extracting archive
      - Installing symfony/polyfill-iconv (v1.23.0): Extracting archive
      - Installing egulias/email-validator (2.1.25): Extracting archive
      - Installing swiftmailer/swiftmailer (v6.2.7): Extracting archive
      - Installing ramsey/collection (1.1.3): Extracting archive
      - Installing brick/math (0.9.2): Extracting archive
      - Installing ramsey/uuid (4.1.1): Extracting archive
      - Installing psr/simple-cache (1.0.1): Extracting archive
      - Installing opis/closure (3.6.2): Extracting archive
      - Installing symfony/translation-contracts (v2.4.0): Extracting archive
      - Installing symfony/translation (v5.3.3): Extracting archive
      - Installing nesbot/carbon (2.50.0): Extracting archive
      - Installing league/mime-type-detection (1.7.0): Extracting archive
      - Installing league/flysystem (1.1.4): Extracting archive
      - Installing league/commonmark (1.6.6): Extracting archive
      - Installing laravel/framework (v8.51.0): Extracting archive
      - Installing facade/ignition-contracts (1.0.2): Extracting archive
      - Installing facade/flare-client-php (1.8.1): Extracting archive
      - Installing facade/ignition (2.11.2): Extracting archive
      - Installing fakerphp/faker (v1.15.0): Extracting archive
      - Installing fideloper/proxy (4.4.1): Extracting archive
      - Installing asm89/stack-cors (v2.0.3): Extracting archive
      - Installing fruitcake/laravel-cors (v2.0.4): Extracting archive
      - Installing psr/http-message (1.0.1): Extracting archive
      - Installing psr/http-client (1.0.1): Extracting archive
      - Installing ralouphie/getallheaders (3.0.3): Extracting archive
      - Installing psr/http-factory (1.0.1): Extracting archive
      - Installing guzzlehttp/psr7 (2.0.0): Extracting archive
      - Installing guzzlehttp/promises (1.4.1): Extracting archive
      - Installing guzzlehttp/guzzle (7.3.0): Extracting archive
      - Installing laravel/sail (v1.8.6): Extracting archive
      - Installing nikic/php-parser (v4.12.0): Extracting archive
      - Installing psy/psysh (v0.10.8): Extracting archive
      - Installing laravel/tinker (v2.6.1): Extracting archive
      - Installing hamcrest/hamcrest-php (v2.0.1): Extracting archive
      - Installing mockery/mockery (1.4.3): Extracting archive
      - Installing filp/whoops (2.14.0): Extracting archive
      - Installing nunomaduro/collision (v5.5.0): Extracting archive
      - Installing phpdocumentor/reflection-common (2.2.0): Extracting archive
      - Installing phpdocumentor/type-resolver (1.4.0): Extracting archive
      - Installing phpdocumentor/reflection-docblock (5.2.2): Extracting archive
      - Installing sebastian/version (3.0.2): Extracting archive
      - Installing sebastian/type (2.3.4): Extracting archive
      - Installing sebastian/resource-operations (3.0.3): Extracting archive
      - Installing sebastian/recursion-context (4.0.4): Extracting archive
      - Installing sebastian/object-reflector (2.0.4): Extracting archive
      - Installing sebastian/object-enumerator (4.0.4): Extracting archive
      - Installing sebastian/global-state (5.0.3): Extracting archive
      - Installing sebastian/exporter (4.0.3): Extracting archive
      - Installing sebastian/environment (5.1.3): Extracting archive
      - Installing sebastian/diff (4.0.4): Extracting archive
      - Installing sebastian/comparator (4.0.6): Extracting archive
      - Installing sebastian/code-unit (1.0.8): Extracting archive
      - Installing sebastian/cli-parser (1.0.1): Extracting archive
      - Installing phpunit/php-timer (5.0.3): Extracting archive
      - Installing phpunit/php-text-template (2.0.4): Extracting archive
      - Installing phpunit/php-invoker (3.1.1): Extracting archive
      - Installing phpunit/php-file-iterator (3.0.5): Extracting archive
      - Installing theseer/tokenizer (1.2.0): Extracting archive
      - Installing sebastian/lines-of-code (1.0.3): Extracting archive
      - Installing sebastian/complexity (2.0.2): Extracting archive
      - Installing sebastian/code-unit-reverse-lookup (2.0.3): Extracting archive
      - Installing phpunit/php-code-coverage (9.2.6): Extracting archive
      - Installing doctrine/instantiator (1.4.0): Extracting archive
      - Installing phpspec/prophecy (1.13.0): Extracting archive
      - Installing phar-io/version (3.1.0): Extracting archive
      - Installing phar-io/manifest (2.0.3): Extracting archive
      - Installing myclabs/deep-copy (1.10.2): Extracting archive
      - Installing phpunit/phpunit (9.5.7): Extracting archive
        0 [>---------------------------]    0 [>---------------------------]    70 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package sebastian/resource-operations is abandoned, you should avoid using it. No replacement was suggested.
Generating optimized autoload files
    > Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
    Discovered Package: facade/ignition
Discovered Package: fideloper/proxy
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/sail
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
    74 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
    > @php artisan key:generate --ansi
    Application key set successfully.

Application ready! Build something amazing.

Install Breeze, Sail, Dusk

C:\Users\alexa\Desktop>cd guesttest

C:\Users\alexa\Desktop\guesttest>composer require laravel/breeze --dev

Using version ^1.3 for laravel/breeze
./composer.json has been updated
Running composer update laravel/breeze
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
  - Locking laravel/breeze (v1.3.1)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Downloading laravel/breeze (v1.3.1)
  - Installing laravel/breeze (v1.3.1): Extracting archive
Package sebastian/resource-operations is abandoned, you should avoid using it. No replacement was suggested.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fideloper/proxy
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/breeze
Discovered Package: laravel/sail
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
74 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

C:\Users\alexa\Desktop\guesttest>php artisan breeze:install

Breeze scaffolding installed successfully.
Please execute the "npm install && npm run dev" command to build your assets.

C:\Users\alexa\Desktop\guesttest>npm install

npm notice
npm notice New minor version of npm available! 7.0.10 -> 7.20.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v7.20.1
npm notice Run npm install -g [email protected] to update!
npm notice
npm WARN deprecated [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.

added 816 packages, and audited 816 packages in 27s

85 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

C:\Users\alexa\Desktop\guesttest>npm run dev

> dev
> npm run development
> development
> mix

* Mix █████████████████████████ emitting (95%)
 emit

* Mix █████████████████████████ done (99%) plugins
 WebpackBar:done

√ Mix
  Compiled successfully in 5.94s

   Laravel Mix v6.0.25

✔ Compiled Successfully in 5904ms
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────┬──────────┐
│                                                                                                      File │ Size     │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────────┤
│                                                                                                /js/app.js │ 673 KiB  │
│                                                                                               css/app.css │ 3.83 MiB │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────┴──────────┘
webpack compiled successfully
Notifications are disabled
Reason: DisabledForApplication Please make sure that the app id is set correctly.
Command Line: C:\Users\alexa\Desktop\guesttest\node_modules\node-notifier\vendor\snoreToast\snoretoast-x64.exe -appID "Laravel Mix" -pipeName \\.\pipe\notifierPipe-ab800537-0d23-4023-ab83-af58afa89464 -p C:\Users\alexa\Desktop\guesttest\node_modules\laravel-mix\icons\laravel.png -m "Build successful" -t "Laravel Mix"

C:\Users\alexa\Desktop\guesttest>php artisan sail:install

Which services would you like to install? [mysql]:
 [0] mysql
 [1] pgsql
 [2] mariadb
 [3] redis
 [4] memcached
 [5] meilisearch
 [6] minio
 [7] mailhog
 [8] selenium
> 0,8

Sail scaffolding installed successfully.

C:\Users\alexa\Desktop\guesttest>composer require --dev laravel/dusk

Using version ^6.15 for laravel/dusk
./composer.json has been updated
Running composer update laravel/dusk
Loading composer repositories with package information
Updating dependencies
Lock file operations: 2 installs, 0 updates, 0 removals
  - Locking laravel/dusk (v6.15.1)
  - Locking php-webdriver/webdriver (1.11.1)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
  - Installing php-webdriver/webdriver (1.11.1): Extracting archive
  - Installing laravel/dusk (v6.15.1): Extracting archive
2 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package sebastian/resource-operations is abandoned, you should avoid using it. No replacement was suggested.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fideloper/proxy
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/breeze
Discovered Package: laravel/dusk
Discovered Package: laravel/sail
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
74 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

C:\Users\alexa\Desktop\guesttest>php artisan dusk:install

Dusk scaffolding installed successfully.
Downloading ChromeDriver binaries...
ChromeDriver binaries successfully installed for version 91.0.4472.101.

Files

.env (not changed by me)

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:ROILS50E3++Qog4vuqULwLo4SU4hFDLv1PvE1dNF+eo=
APP_DEBUG=true
APP_URL=http://guesttest.test

LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=guesttest
DB_USERNAME=sail
DB_PASSWORD=password

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=memcached

REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

tests\Browser\LoginTest.php

C:\Users\alexa\Desktop\guesttest>php artisan dusk:make LoginTest
Test created successfully.

This testclass contains two functions with the same code, except, that one uses assertGuest , while the other does not.

<?php

namespace Tests\Browser;

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

class LoginTest extends DuskTestCase
{
    use DatabaseMigrations;
    
    /**
     * This example works (without assertGuest)
     *
     * @return void
     */
    public function testLoginErrorMessageWorking()
    {
        $this->browse(function (Browser $browser) {
            $browser->visit('/login')
                //->assertGuest()
                ->type('email', '[email protected]')
                ->type('password', 'password')
                ->press('LOG IN')
                ->assertRouteIs('login')
                ->assertSee('These credentials do not match our records.');
        });
    }
    
    /**
     * This example fails (with assertGuest)
     *
     * @return void
     */
    public function testLoginErrorMessageFail()
    {
        $this->browse(function (Browser $browser) {
            $browser->visit('/login')
                ->assertGuest()
                ->type('email', '[email protected]')
                ->type('password', 'password')
                ->press('LOG IN')
                ->assertRouteIs('login')
                ->assertSee('These credentials do not match our records.');
        });
    }
}

Setting up sail (in Windows Terminal -> Ubuntu)

alex@DESKTOP-2DSRHN6:/mnt/c/Users/alexa/Desktop/guesttest$ vendor/bin/sail up -d

guesttest_laravel.test_1   start-container               Exit 137
Shutting down old Sail processes...
Creating network "guesttest_sail" with driver "bridge"
Creating guesttest_mysql_1    ... done
Creating guesttest_selenium_1 ... done
Creating guesttest_laravel.test_1 ... done

Run the tests

alex@DESKTOP-2DSRHN6:/mnt/c/Users/alexa/Desktop/guesttest$ sail dusk tests/Browser/LoginTest.php

PHPUnit 9.5.7 by Sebastian Bergmann and contributors.

.E                                                                  2 / 2 (100%)

Time: 00:14.377, Memory: 26.00 MB

There was 1 error:

1) Tests\Browser\LoginTest::testLoginErrorMessageFail
Facebook\WebDriver\Exception\NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"body email"}
  (Session info: headless chrome=91.0.4472.114)

/var/www/html/vendor/php-webdriver/webdriver/lib/Exception/WebDriverException.php:117
/var/www/html/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:371
/var/www/html/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:591
/var/www/html/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:212
/var/www/html/vendor/laravel/dusk/src/ElementResolver.php:373
/var/www/html/vendor/laravel/dusk/src/ElementResolver.php:351
/var/www/html/vendor/laravel/dusk/src/ElementResolver.php:90
/var/www/html/vendor/laravel/dusk/src/Concerns/InteractsWithElements.php:144
/var/www/html/tests/Browser/LoginTest.php:41
/var/www/html/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:68
/var/www/html/tests/Browser/LoginTest.php:46

ERRORS!
Tests: 2, Assertions: 3, Errors: 1.

As you can see, the first test works, the second does not. I have absolutely no clue why 🤷‍♂️

@crynobone
Copy link
Member

Are you sure that the browser doesn't has any session based on previous tests/assertion?

@lanort
Copy link
Author

lanort commented Jul 23, 2021

Are you sure that the browser doesn't has any session based on previous tests/assertion?

@crynobone I think so. Why should this else happen on a new installation? I also dropped my previous docker app with sail down -v. So I think there should be nothing persistent, should it?

The issue is not, that the assertGuest fails (which would sound like the session you mentioned), but that the type command failed. So if it would a redirect and there is no input email field, both tests would fail. Right?

@crynobone
Copy link
Member

So if it would a redirect and there is no input email field, both tests would fail. Right?

Looking at the code against and I think I know the reason why.

assertGuest() actually require dusk to visit _dusk/user page and it doesn't do any redirect from there.

You should change the code from:

$browser->visit('/login')->assertGuest();

// to

$browser->assertGuest()->visit('/login');

@lanort
Copy link
Author

lanort commented Jul 23, 2021

@crynobone Oh wow. Respect. That solved it. Wow 👍

I just saw there are two different assertGuest functions for dusk and normal HTTP testing.

Normal Laravel HTTP testing seems to not has this side effect of changing the URL:
vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithAuthentication.php

    /**
     * Assert that the user is not authenticated.
     *
     * @param  string|null  $guard
     * @return $this
     */
    public function assertGuest($guard = null)
    {
        $this->assertFalse($this->isAuthenticated($guard), 'The user is authenticated');

        return $this;
    }

and the dusk version which changes the current URL:

vendor/laravel/dusk/src/Concerns/InteractsWithAuthentication.php

    /**
     * Assert that the user is not authenticated.
     *
     * @param  string|null  $guard
     * @return $this
     */
    public function assertGuest($guard = null)
    {
        PHPUnit::assertEmpty(
            $this->currentUserInfo($guard), 'The user is unexpectedly authenticated.'
        );

        return $this;
    }

So I don't know if it makes sense to adapt those? Probably there is a reason for the difference. Or maybe we could document it, that the dusk assertGuests changes the URL.

Thanks anyway for the quick resolution. You are free to close this or take my thoughts into consideration.

@crynobone
Copy link
Member

crynobone commented Jul 23, 2021

Submitted a PR #912 to redirect after assertion.


This doesn't affect normal HTTP tests because that only mimic a Request, while Dusk tests require an actual browser to hit an actual request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants