Skip to content

[Bug]: AwaitableWebpage::click times out when the next page is slow to load #1511

@mattford

Description

@mattford

What Happened

When using ->click() or ->press() within a browser test, if the element clicked causes a navigation and the next page takes >5s to load, the action fails (even though the element was successfully clicked)

This is possibly an issue with Playwright but I'm starting here as I'm not as familiar with that side of things.

In my example the test fails at the click line:

   FAILED  Tests\Browser\WelcomePageTest > clicking on button
  Execution context was destroyed, most likely because of a navigation A screenshot of the page has been saved to [Tests/Browser/Screenshots/clicking_on_button].

  at tests/Browser/WelcomePageTest.php:4
      1▕ <?php
      2▕ test('clicking on button', function (): void {
      3▕    visit('/')
  ➜   4▕      ->click('Click here!')
      5▕      ->assertSee('Hello, World!');
      6▕ });

However the screenshot produced shows the loaded "Hello, World!" page, so it appears that the test should be successful.
I put a dump in the sendMessage method and saw that it was repeatedly sending the click command to Playwright, given the navigation already occurred these later calls likely didn't find the element to click on.

PHPUnit\Framework\ExpectationFailedException^ {#4035
  #message: "Timeout 1000ms exceeded."
  #code: 0
  #file: "/var/www/html/vendor/pestphp/pest-plugin-browser/src/Playwright/Client.php"
  #line: 101
  #serializableTrace: array:30 [
    0 => array:3 [
      "function" => "execute"
      "class" => "Pest\Browser\Playwright\Client"
      "type" => "->"
    ]
    1 => array:3 [
      "file" => "/var/www/html/vendor/pestphp/pest-plugin-browser/src/Playwright/Concerns/InteractsWithPlaywright.php"
      "line" => 105
      "function" => "iterator_to_array"
    ]
    2 => array:5 [
      "file" => "/var/www/html/vendor/pestphp/pest-plugin-browser/src/Playwright/Locator.php"
      "line" => 137
      "function" => "processVoidResponse"
      "class" => "Pest\Browser\Playwright\Locator"
      "type" => "->"
    ]
    3 => array:5 [
      "file" => "/var/www/html/vendor/pestphp/pest-plugin-browser/src/Api/Concerns/InteractsWithElements.php"
      "line" => 169
      "function" => "click"
      "class" => "Pest\Browser\Playwright\Locator"
      "type" => "->"
    ]
    4 => array:5 [
      "file" => "/var/www/html/vendor/pestphp/pest-plugin-browser/src/Api/AwaitableWebpage.php"
      "line" => 55
      "function" => "press"
      "class" => "Pest\Browser\Api\Webpage"
      "type" => "->"
    ]
    5 => array:5 [
      "file" => "/var/www/html/vendor/pestphp/pest-plugin-browser/src/Playwright/Playwright.php"
      "line" => 196
      "function" => "Pest\Browser\Api\{closure}"
      "class" => "Pest\Browser\Api\AwaitableWebpage"
      "type" => "->"
    ]
    6 => array:5 [
      "file" => "/var/www/html/vendor/pestphp/pest-plugin-browser/src/Execution.php"
      "line" => 149
      "function" => "usingTimeout"
      "class" => "Pest\Browser\Playwright\Playwright"
      "type" => "::"
    ]
    7 => array:5 [
      "file" => "/var/www/html/vendor/pestphp/pest-plugin-browser/src/Api/AwaitableWebpage.php"
      "line" => 53
      "function" => "waitForExpectation"
      "class" => "Pest\Browser\Execution"
      "type" => "->"
    ]
    8 => array:5 [
      "file" => "/var/www/html/tests/Browser/AdminDashboardBulkActionsTest.php"
      "line" => 71
      "function" => "__call"
      "class" => "Pest\Browser\Api\AwaitableWebpage"
      "type" => "->"
    ]
    9 => array:5 [
      "file" => "/var/www/html/vendor/pestphp/pest/src/Factories/TestCaseMethodFactory.php"
      "line" => 168
      "function" => "{closure}"
      "class" => "P\Tests\Browser\AdminDashboardBulkActionsTest"
      "type" => "->"
    ]
    10 => array:3 [
      "function" => "Pest\Factories\{closure}"
      "class" => "P\Tests\Browser\AdminDashboardBulkActionsTest"
      "type" => "->"
    ]
    11 => array:3 [
      "file" => "/var/www/html/vendor/pestphp/pest/src/Concerns/Testable.php"
      "line" => 429
      "function" => "call_user_func_array"
    ]
    12 => array:5 [
      "file" => "/var/www/html/vendor/pestphp/pest/src/Support/ExceptionTrace.php"
      "line" => 26
      "function" => "Pest\Concerns\{closure}"
      "class" => "P\Tests\Browser\AdminDashboardBulkActionsTest"
      "type" => "->"
    ]
    13 => array:5 [
      "file" => "/var/www/html/vendor/pestphp/pest/src/Concerns/Testable.php"
      "line" => 429
      "function" => "ensure"
      "class" => "Pest\Support\ExceptionTrace"
      "type" => "::"
    ]
    14 => array:5 [
      "file" => "/var/www/html/vendor/pestphp/pest/src/Concerns/Testable.php"
      "line" => 331
      "function" => "__callClosure"
      "class" => "P\Tests\Browser\AdminDashboardBulkActionsTest"
      "type" => "->"
    ]
    15 => array:5 [
      "file" => "/var/www/html/vendor/pestphp/pest/src/Factories/TestCaseFactory.php(169) : eval()'d code"
      "line" => 20
      "function" => "__runTest"
      "class" => "P\Tests\Browser\AdminDashboardBulkActionsTest"
      "type" => "->"
    ]
    16 => array:5 [
      "file" => "/var/www/html/vendor/phpunit/phpunit/src/Framework/TestCase.php"
      "line" => 1316
      "function" => "__pest_evaluable__admin_dashboard_bulk_actions__→_apply_an_action_to_an_application"
      "class" => "P\Tests\Browser\AdminDashboardBulkActionsTest"
      "type" => "->"
    ]
    17 => array:5 [
      "file" => "/var/www/html/vendor/phpunit/phpunit/src/Framework/TestCase.php"
      "line" => 516
      "function" => "runTest"
      "class" => "PHPUnit\Framework\TestCase"
      "type" => "->"
    ]
    18 => array:5 [
      "file" => "/var/www/html/vendor/phpunit/phpunit/src/Framework/TestRunner/TestRunner.php"
      "line" => 99
      "function" => "runBare"
      "class" => "PHPUnit\Framework\TestCase"
      "type" => "->"
    ]
    19 => array:5 [
      "file" => "/var/www/html/vendor/phpunit/phpunit/src/Framework/TestCase.php"
      "line" => 357
      "function" => "run"
      "class" => "PHPUnit\Framework\TestRunner"
      "type" => "->"
    ]
    20 => array:5 [
      "file" => "/var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php"
      "line" => 374
      "function" => "run"
      "class" => "PHPUnit\Framework\TestCase"
      "type" => "->"
    ]
    21 => array:5 [
      "file" => "/var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php"
      "line" => 374
      "function" => "run"
      "class" => "PHPUnit\Framework\TestSuite"
      "type" => "->"
    ]
    22 => array:5 [
      "file" => "/var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php"
      "line" => 374
      "function" => "run"
      "class" => "PHPUnit\Framework\TestSuite"
      "type" => "->"
    ]
    23 => array:5 [
      "file" => "/var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php"
      "line" => 374
      "function" => "run"
      "class" => "PHPUnit\Framework\TestSuite"
      "type" => "->"
    ]
    24 => array:5 [
      "file" => "/var/www/html/vendor/phpunit/phpunit/src/TextUI/TestRunner.php"
      "line" => 64
      "function" => "run"
      "class" => "PHPUnit\Framework\TestSuite"
      "type" => "->"
    ]
    25 => array:5 [
      "file" => "/var/www/html/vendor/phpunit/phpunit/src/TextUI/Application.php"
      "line" => 229
      "function" => "run"
      "class" => "PHPUnit\TextUI\TestRunner"
      "type" => "->"
    ]
    26 => array:5 [
      "file" => "/var/www/html/vendor/pestphp/pest/src/Kernel.php"
      "line" => 103
      "function" => "run"
      "class" => "PHPUnit\TextUI\Application"
      "type" => "->"
    ]
    27 => array:5 [
      "file" => "/var/www/html/vendor/pestphp/pest/bin/pest"
      "line" => 184
      "function" => "handle"
      "class" => "Pest\Kernel"
      "type" => "->"
    ]
    28 => array:3 [
      "file" => "/var/www/html/vendor/pestphp/pest/bin/pest"
      "line" => 192
      "function" => "{closure}"
    ]
    29 => array:3 [
      "file" => "/var/www/html/vendor/bin/pest"
      "line" => 119
      "function" => "include"
    ]
  ]
  #comparisonFailure: null
  trace: {
    /var/www/html/vendor/pestphp/pest-plugin-browser/src/Playwright/Client.php:101 { …}
    Pest\Browser\Playwright\Client->execute() {}
    /var/www/html/vendor/pestphp/pest-plugin-browser/src/Playwright/Concerns/InteractsWithPlaywright.php:105 { …}
    /var/www/html/vendor/pestphp/pest-plugin-browser/src/Playwright/Locator.php:137 { …}
    /var/www/html/vendor/pestphp/pest-plugin-browser/src/Api/Concerns/InteractsWithElements.php:169 { …}
    /var/www/html/vendor/pestphp/pest-plugin-browser/src/Api/AwaitableWebpage.php:55 { …}
    /var/www/html/vendor/pestphp/pest-plugin-browser/src/Playwright/Playwright.php:196 { …}
    /var/www/html/vendor/pestphp/pest-plugin-browser/src/Execution.php:149 { …}
    /var/www/html/vendor/pestphp/pest-plugin-browser/src/Api/AwaitableWebpage.php:53 { …}
    /var/www/html/tests/Browser/AdminDashboardBulkActionsTest.php:71 {
      P\Tests\Browser\AdminDashboardBulkActionsTest->{closure}^
      › ->click('Current stage')\r
      › ->press('.action.reinstate')\r
      › ->assertSeeIn('.tab-pane h2', 'Application Review');\r
      arguments: {
        $name: "press"
        $arguments: array:1 [ …1]
      }
    }
    /var/www/html/vendor/pestphp/pest/src/Factories/TestCaseMethodFactory.php:168 { …}
    P\Tests\Browser\AdminDashboardBulkActionsTest->Pest\Factories\{closure}() {}
    /var/www/html/vendor/pestphp/pest/src/Concerns/Testable.php:429 { …}
    /var/www/html/vendor/pestphp/pest/src/Support/ExceptionTrace.php:26 { …}
    /var/www/html/vendor/pestphp/pest/src/Concerns/Testable.php:429 { …}
    /var/www/html/vendor/pestphp/pest/src/Concerns/Testable.php:331 { …}
    /var/www/html/vendor/pestphp/pest/src/Factories/TestCaseFactory.php:169 { …}
    /var/www/html/vendor/phpunit/phpunit/src/Framework/TestCase.php:1316 { …}
    /var/www/html/vendor/phpunit/phpunit/src/Framework/TestCase.php:516 { …}
    /var/www/html/vendor/phpunit/phpunit/src/Framework/TestRunner/TestRunner.php:99 { …}
    /var/www/html/vendor/phpunit/phpunit/src/Framework/TestCase.php:357 { …}
    /var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php:374 { …}
    /var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php:374 { …}
    /var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php:374 { …}
    /var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php:374 { …}
    /var/www/html/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:64 { …}
    /var/www/html/vendor/phpunit/phpunit/src/TextUI/Application.php:229 { …}
    /var/www/html/vendor/pestphp/pest/src/Kernel.php:103 { …}
    /var/www/html/vendor/pestphp/pest/bin/pest:184 { …}
    /var/www/html/vendor/pestphp/pest/bin/pest:192 { …}
    /var/www/html/vendor/bin/pest:119 { …}
  }
} // vendor/pestphp/pest-plugin-browser/src/Execution.php:152

How to Reproduce

Checkout https://github.com/mattford/pest-repro
composer/npm install
Run vendor/bin/pest

Sample Repository

No response

Pest Version

4.1.0

PHP Version

8.4.12

Operation System

Linux

Notes

I am using WSL2 to execute Pest, same occurs within the php8.4-cli docker image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions