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

Assertion failure can lead to timeout if using multiple browsers #1058

Closed
stefanvdlugt opened this issue Sep 14, 2023 · 5 comments
Closed

Assertion failure can lead to timeout if using multiple browsers #1058

stefanvdlugt opened this issue Sep 14, 2023 · 5 comments

Comments

@stefanvdlugt
Copy link

Dusk Version

7.9.3

Laravel Version

10.13.5

PHP Version

8.1.22

PHPUnit Version

10.2.2

Database Driver & Version

MySQL 8.0.32 Docker container

Description

Hello, we may have found a bug with assertion failure handling when multiple browsers are being used. If you open multiple browsers, and an assertion fails before all browsers have been instructed to visit a page, the captureFailuresFor method throws a TimeoutException.

We have implemented a crude workaround by overriding the Browser class so that it sets a boolean to true when the method visit is called and only takes screenshots if that boolean is true, but perhaps there is a better solution.

We are using Laravel Sail with Selenium in Docker containers.

Steps To Reproduce

  1. (Not sure if necessary) Use Selenium containers
  2. Write a test that uses multiple browsers;
  3. Using the first browser, navigate to a webpage, and make an assertion that will fail.
    public function test_this_is_going_to_timeout(): void
    {
        $this->browse(function (Browser $browser1, Browser $browser2) {
            $browser1->visit('https://github.com/laravel/dusk/')
                ->assertSee('THIS_STRING_DOES_NOT_OCCUR');
        });
    }
@crynobone
Copy link
Member

Hey there, thanks for reporting this issue.

We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here?

Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.

laravel new bug-report --github="--public"

Do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.

Thanks!

@driesvints
Copy link
Member

Feel free to reopen when you have the repo. Thanks

@mavenik
Copy link

mavenik commented Nov 22, 2023

Hi @crynobone @driesvints

I have been experiencing this issue today. I have created a fresh repository and been able to reproduce the problem consistently. However, I do not use any native installs of PHP, Composer, or Laravel.

Could you help me with relevant instructions to issue a bug report using a docker image or any alternative method please?

Here's the repository for your reference:

  1. Repo link - https://github.com/mavenik/dusk_timeouts
  2. Commit ref - mavenik/dusk_timeouts@aac7546
  3. Note that I am able to reproduce this issue with one browser itself
  /**
   * Test if the page has a header
   */
  public function testDuskTimeoutPageHasHeader(): void
  {
    $this->browse(function (Browser $browser) {
      $browser->visit('/dusk_timeout_test')
              ->assertPresent('header');
    });
  }
  1. Terminal output
$ sail dusk --filter TimeoutTest

   FAIL  Tests\Browser\TimeoutTest
  ✓ dusk timeout page has accurate title                                                                                                                                                                    0.60s  
  ⨯ dusk timeout page has header                                                                                                                                                                           60.22s  
  ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────  
   FAILED  Tests\Browser\TimeoutTest > dusk timeout page has header                                                                                                                             TimeoutException   
  timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=119.0.6045.123)

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

      +8 vendor frames 
  9   tests/Browser/TimeoutTest.php:28


  Tests:    1 failed, 1 passed (2 assertions)
  Duration: 60.94s
  1. Screenshot of failure
    Screenshot from 2023-11-22 17-18-33

I'm running a sail setup. Here are my setup steps if it helps

  1. Setup a fresh Laravel Sail application
curl -s https://laravel.build/dusk-timeouts | bash`
cd dusk-timeouts
./vendor/bin/sail up
  1. Install Dusk
./vendor/bin/sail composer require --dev laravel/dusk
./vendor/bin/sail artisan dusk:install
  1. Test Dusk scaffolding (was successful)
./vendor/bin/sail dusk
  1. Create a new browser test
./vendor/bin/sail artisan dusk:make TimeoutTest
  1. Execute TimeoutTest
./vendor/bin/sail dusk --filter TimeoutTest

@Rubrasum
Copy link

My issue seemed to be the method I was using with this retry(). I was successful with other tests not using visit like this.

@TonisfelTr
Copy link

TonisfelTr commented Apr 20, 2024

Are there persons who get this error for now?

PHP: v8.3.6
Laravel: v10.48.8
Laravel Sail: v1.29.1
Laravel Dusk: v8.2.0

My code of DuskTestCase implemented class

    public function test_icd_page_read_correctly() {
        $this->browse(function (Browser $browser){
            $mainPage = $browser->visit(self::mainLink)->setChromeOptions("--headless");
            // Tests if page has been got correctly.
            $mainPage->assertSeeLink('https://mkb-10.com/index.php?pid=4002');
        });
    }

Error:

FAIL  Tests\Browser\ExampleTest
  ⨯ basic example                                                                                                                                                                                                                                                        60.68s  
  ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────  
   FAILED  Tests\Browser\ExampleTest > basic example                                                                                                                                                                                                          TimeoutException   
  timeout: Timed out receiving message from renderer: 10.000
  (Session info: chrome=123.0.6312.86)

  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/ExampleTest.php:16


  Tests:    1 failed (1 assertions)
  Duration: 60.80s

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

No branches or pull requests

6 participants