robotframework-browser
robotframework-browser copied to clipboard
Har is not saved when Browser Server is closed
Describe the bug Har file is not saved when Browser Server is closed using Close Browser Server keyword.
To Reproduce Steps to reproduce the behavior:
${options_chrome}= Create List
Append to List ${options_chrome} --remote-debugging-port=10000
${ws_endpoint} Launch Browser Server browser=chromium headless=False handleSIGHUP=False handleSIGINT=False handleSIGTERM=False args=${options_chrome} reuse_existing=True
${har} Create Dictionary path=${REPO_DIR}${/}browser${/}har.file
Connect To Browser http://localhost:10000/ use_cdp=True
New Context recordHar=${har}
New Page URL
Close Browser Server wsEndpoint=${ws_endpoint}
Expected behavior Context and browser are closed. The HAR file is saved in the provided path
Desktop (please complete the following information):
- OS: Windows 11
- Browser chrome
- Version 126.0.6478.127
Additional context
- Python: 3.9.7
- Robotframework: 6.0.2
- Robotframework-browser: 18.6.3
I see that Browser and context for provided ws_endpoint are closed but the har file is not saved.
@allcontributors please add @Pawci3oo for bugs.
Most likely this forcefully closes browser/context/pages and in this case Playwright does not have time to create har file. As a workaround you could first run Close Browser keyword and then run Close Browser Server keyword.
Basically, Close Browser and Close Context keywords do not work for me either but not in the described reproduction. Before test execution I create Browser Servers and log in to the application using user credentials with specific permissions, then Suite is attached to a specific server, based on the needed user with permissions. At the end of each suite, the browser server is not closed, but "passed" to the next suite to skip logging to the application. I would like to close contexts and browser servers at the end of all suites. As far as I know, Connect to Browser keyword with CDP connects to the server with CURRENT context and page, but I think I don't fully understand this implementation.
Below scenario to reproduce, where browser is not closed and har is not saved:
suite1_testSuite.robot
Test1
${options_chrome}= Create List
Append to List ${options_chrome} --remote-debugging-port=10000
${ws_endpoint} Launch Browser Server browser=chromium headless=False handleSIGHUP=False
handleSIGINT=False handleSIGTERM=False args=${options_chrome}
${har} Create Dictionary path=${REPO_DIR}${/}browser${/}har.file
${id} Connect To Browser http://localhost:10000/ use_cdp=True
${ctx} New Context recordHar=${har}
${browser_ids} Get Browser Ids <- browser with id X
${context_ids} Get Context Ids <- context with ids x and y
New Page URL
[Tags] reproduceIssue
suite2_testSuite.robot
Test2
Connect To Browser http://localhost:10000/ use_cdp=True
${browser_ids} Get Browser Ids<- browser with id Y
${context_ids} Get Context Ids <- context with id z
Close Context - it doesn't work, context and browser are still open, har is not saved
Close Browser - it doesn't work, context and browser are still open, har is not saved
[Tags] reproduceIssue
Pabot command:
pabot --processes 1 --pabotlib --verbose --include reproduceIssue *\*testSuite.robot