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

Aperta
#2,020 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 5 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
57/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
php, playwright
Ambito
testing

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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).

Lingua principale
PHP
Stelle
11.8k
Fork
559
Merge medio
5g 23h
PR unite (30g)
24

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pestphp/pest

Tutte le issue di pestphp/pest

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.