MarketSquare / robotframework-browser

Robot Framework Browser library powered by Playwright.
Apache License 2.0
514 stars 104 forks source link

Support starting and stopping trace by a keyword #3427

Open aaltat opened 7 months ago

aaltat commented 7 months ago

Is your feature request related to a problem? Please describe. Currently it is only possible to start trace when context is opened. Also trace is stopped when context is closed. There has been several discussions in Slack that user would like to control trace better. This is possible with Playwright Trace

Describe the solution you'd like Create keyword which allows to stop and and start trace. In simplest form there could be two keywords this:

Test
    Start Trace    trace.zip
    New Page    ${URL}
    Stop Trace

The downside seems to be, based on docs, that one can start and stop trace only one time.

Also we could expose other options from Trace, like chunks and options from trace. This allows to create multiple traces files inside of the same context. I think this would be even better.

Test 0
    New Context

Test 1
    Start Trace    screenshots=True    snapshots=False    sources=True    title=Some name
    Start Trace Chunk    trace1.zip
    New Page    ${URL}
    Close Page
    Stop Trace Chunk

Test 2
    Start Trace Chunk    trace2.zip
    New Page    ${URL}
    Close Page
    Stop Trace Chunk

I am leaning towards the later way and exposing startChunk and stopChunk functionality from PW side. I am not sure without testing do we need in later case also the Stop Trace keyword, perhaps not. The later way gives better control for users and allows, for example, give trace a name based on the test. This allows finding the correct trace easier.

Snooz82 commented 7 months ago

This requires to update the js_keyword_interface, so that context (opt browser) is also available in the js keyword.

if trace is startet after page, many resources are missing, I.e. css .

Therefore it would be good to start it before opening page.

idea: enable tracing for new_page.

aaltat commented 7 months ago

I have not thought about New Page keyword, I need to think about it. But sounds like possible idea. And fixed bug in the second example in above, one cannot call Start Trace twice in the same context.