laravel / dusk

Laravel Dusk provides simple end-to-end testing and browser automation.
https://laravel.com/docs/dusk
MIT License
1.87k stars 320 forks source link

Throwing an exception in a dusk test inside the browser callback results in timeouts #1078

Closed yamut closed 4 months ago

yamut commented 7 months ago

Dusk Version

7.12.1

Laravel Version

10.41.0

PHP Version

8.3.1

PHPUnit Version

10.5.8

Database Driver & Version

No response

Description

When using the recommended setup for dusk in sail, throwing an exception within the browse method results in a chrome driver timeout. This is true for situations not involving docker as well, steps to repro just involve cutting out sail and setting up everything locally or equivalent.

Steps To Reproduce

To reproduce

  1. Create a new laravel project by following the documentation at https://laravel.com/docs/10.x/installation#creating-a-laravel-project
  2. Add sail to your project by following the steps listed at https://laravel.com/docs/10.x/sail#installation
  3. Add dusk to your project by following the steps listed at https://laravel.com/docs/10.x/dusk
  4. Add the selenium image to your docker-compose.yml as defined at https://laravel.com/docs/10.x/sail#laravel-dusk
  5. Create a new test as defined at https://laravel.com/docs/10.x/dusk#generating-tests
  6. Modify the test to throw an exception
  7. Bring up your docker containers by running sail up
  8. Run sail dusk

Test code should look like the following

    public function testExample(): void
    {
        $this->browse(function (Browser $browser) {
            throw new \RuntimeException('foo');
            $browser->visit('/')
                    ->assertSee('Laravel');
        });
    }

Output:

% sail dusk                    

   FAIL  Tests\Browser\IndexTest
  ⨯ example                                                                                                                                                                                                       62.19s  
  ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────  
   FAILED  Tests\Browser\IndexTest > example                                                                                                                                                           TimeoutException   
  timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=120.0.6099.109)

  at vendor/php-webdriver/webdriver/lib/Exception/WebDriverException.php:136
    132▕                     throw new StaleElementReferenceException($message, $results);
    133▕                 case 'detached shadow root':
    134▕                     throw new DetachedShadowRootException($message, $results);
    135▕                 case 'timeout':
  ➜ 136▕                     throw new TimeoutException($message, $results);
    137▕                 case 'unable to set cookie':
    138▕                     throw new UnableToSetCookieException($message, $results);
    139▕                 case 'unable to capture screen':
    140▕                     throw new UnableToCaptureScreenException($message, $results);

      +8 vendor frames 
  9   tests/Browser/IndexTest.php:16

  Tests:    1 failed (0 assertions)
  Duration: 62.50s

Remove the exception from your code to ensure dusk is actually working

Test code:

    public function testExample(): void
    {
        $this->browse(function (Browser $browser) {
            $browser->visit('/')
                    ->assertSee('Laravel');
        });
    }

Run sail dusk

Output:

% sail dusk

   PASS  Tests\Browser\IndexTest
  ✓ example                                                                                                                                                                                                        1.42s  

  Tests:    1 passed (1 assertions)
  Duration: 1.71s
github-actions[bot] commented 7 months ago

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

driesvints commented 4 months ago

Closing this issue because it's inactive, already solved, old or not relevant anymore. Feel to open up a new issue if you're still experiencing this.