Get "Error: Tried to do playwright action, but no open page." when doing two tests

I am getting this error unless I comment out the second test’s title (source code follows):

==============================================================================
Go To Main Site                                                       | PASS |
------------------------------------------------------------------------------
[ WARN ] Keyword 'Take Screenshot' could not be run on failure:
Error: Tried to take screenshot, but no page was open.
Click Into Books                                                      | FAIL |
Error: Tried to do playwright action, but no open page.
------------------------------------------------------------------------------
Site Check                                                            | FAIL |
2 critical tests, 1 passed, 1 failed
2 tests total, 1 passed, 1 failed
==============================================================================

I looked through the documentation but did not see anything that spoke about new test stanzas causing issues. Can anyone help explain?

Thanks, Jeff

gives error:

*** Settings ***
Suite Teardown      Close Browser
Library             Browser

*** Variables ***
${URL}            http://toscrape.com/
${MAIN_TITLE}     Scraping Sandbox
${BOOKS_TITLE}    All products | Books to Scrape - Sandbox

*** Test Cases ***
Go To Main Site
    New Browser    chromium    headless=false
    New Page       ${URL}
    Get Title      ==    ${MAIN_TITLE}

Click Into Books
    Click          body > div > div:nth-child(2) > div.col-md-10 > p > a:nth-child(1)
    Get Title      ==    ${BOOKS_TITLE}

runs without error:

*** Settings ***
Suite Teardown      Close Browser
Library             Browser

*** Variables ***
${URL}            http://toscrape.com/
${MAIN_TITLE}     Scraping Sandbox
${BOOKS_TITLE}    All products | Books to Scrape - Sandbox

*** Test Cases ***
Go To Main Site
    New Browser    chromium    headless=false
    New Page       ${URL}
    Get Title      ==    ${MAIN_TITLE}
    
#Click Into Books
    Click          body > div > div:nth-child(2) > div.col-md-10 > p > a:nth-child(1)
    Get Title      ==    ${BOOKS_TITLE}

Yes that is clear.

Because Browser library auto closes contexts and pages by default.

Please read the following doc sections:
https://marketsquare.github.io/robotframework-browser/Browser.html#Browser%2C%20Context%20and%20Page

And specially:
https://marketsquare.github.io/robotframework-browser/Browser.html#Automatic%20page%20and%20context%20closing

Thanks very much! I had read that first link but missed the part about closing. It makes sense.

I’ve now refactored my code as follows, and it works (although, now it runs headless, because I cannot pass in “headless=false” to Suite Setup, since “New Page” only takes 0 or 1 params; I will figure out a way around this later).

*** Settings ***
Suite Setup       New Page    ${URL}
Library           Browser

*** Variables ***
${URL}            http://toscrape.com/
${MAIN_TITLE}     Scraping Sandbox
${BOOKS_TITLE}    All products | Books to Scrape - Sandbox

*** Test Cases ***
Go To Main Site
    Get Title      ==    ${MAIN_TITLE}
    
Click Into Books
    Click          body > div > div:nth-child(2) > div.col-md-10 > p > a:nth-child(1)
    Get Title      ==    ${BOOKS_TITLE}

In the Import - Library Browser auto_closing_level=SUITE
I use the attribute auto_closing_level=SUITE instead of the default TEST so the Suite sequence can use the same page all the way to the end of the page.

Then, in the Suite Setup I use the New Persistent Context keyword that does: New Browser + New Context + New Page (just like New Page alone does)
But it gives you access to all the attributes for each of the tree actions
So you can control all of that if you need to:
New Persistent Context
… browser=${gBrowser}
… headless=${gHeadless}
… viewport={‘width’: 1900, ‘height’: 900}
… ignoreHTTPSErrors=${True}
… userDataDir=${EMPTY}
… url=${application_url}
… slowMo=500ms