[pest-plugin-browser] Give page navigation its own timeout, separate from the assertion timeout

オープン
#2,020 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 5 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
57/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
php, playwright
領域
testing

調査の方向性

The issue names PendingAwaitablePage::buildAwaitablePage() and InteractsWithToolbar as the navigation entry points. Read how timeout() is applied to goto and the toolbar navigation methods, then check the related tests for navigation timeouts. Done means a separate navigation timeout applies to all listed navigation methods, defaults to the existing timeout, and the failure message identifies a timed out navigation.

索引モデルが issue の本文から書いたものです。

説明

enhancement

Filing here because pestphp/pest-plugin-browser has issues disabled.

Problem

pest()->browser()->timeout() sets one timeout for both assertions and page navigation. visit() is lazy: the first call chained on it opens a new context and page and calls goto with waitUntil: 'load', all within that timeout (PendingAwaitablePage::buildAwaitablePage()). navigate(), refresh(), back() and forward() use it as well.

So when a page's load event is slow, its first assertion fails with a bare timeout, even though the assertion never ran and the text it looks for was in the HTML at once:

use Illuminate\Support\Facades\Route;

it('sees the text', function (): void {
    Route::get('/repro/slow.js', function () {
        usleep(6_000_000);

        return response('', 200, ['Content-Type' => 'text/javascript']);
    });
    Route::get('/repro/page', fn () => '<html><body><p>Hello</p><script src="/repro/slow.js"></script></body></html>');

    visit('/repro/page')->assertSee('Hello');
});

With the default timeout of 5000 ms, this fails on the ->assertSee('Hello') line with nothing but:

Timeout 5000ms exceeded.

There is no screenshot either, because the timeout is hit before the page is handed to the test.

In a real app the load event is slow more often than you would expect. It waits for every script, stylesheet, font and image, and each test starts with an empty browser cache, while every parallel worker loads its first page at the same moment. Our app loads about 60 files from public CDNs. With 16 parallel workers, the first call after visit() regularly took more than 5 seconds, and one run failed 11 of 69 tests with Timeout 5000ms exceeded. on that call.

Raising timeout() avoids that, but makes every genuinely failing assertion take that much longer to report.

Workaround

visit() and navigate() pass their options on to goto, so this works:

visit('/repro/page', ['timeout' => 30_000])->assertSee('Hello');

But it has to be repeated in every call, and refresh(), back() and forward() take no options.

Proposal

A separate navigation timeout, like Playwright's setDefaultNavigationTimeout() next to setDefaultTimeout():

pest()->browser()
    ->timeout(5_000)              // assertions and other actions
    ->navigationTimeout(30_000);  // visit(), navigate(), refresh(), back(), forward()

It would apply to goto in PendingAwaitablePage::buildAwaitablePage() and to the navigation methods in InteractsWithToolbar. Defaulting it to timeout() keeps the current behaviour for everyone who does not set it.

Related, and smaller: name the step that timed out, e.g. Timeout 5000ms exceeded while loading [http://127.0.0.1:61284/repro/page]., so the failure does not read as a failed assertion.

The browser launch already has its own timeout: it happens during initialize, which uses LAUNCH_TIMEOUT since pestphp/pest-plugin-browser#275.

Happy to open a PR if this direction works for you.

Versions: pest-plugin-browser 5.2.0 (the code is the same on 5.x today), Playwright 1.64.1, PHP 8.5, macOS and Ubuntu (GitHub Actions).

主要言語
PHP
スター
11.8k
フォーク
559
平均マージ
5日 23時間
マージ済み PR(30日)
24

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pestphp/pest のほかの issue

pestphp/pest の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。