robotframework-browser icon indicating copy to clipboard operation
robotframework-browser copied to clipboard

Har is not saved when Browser Server is closed

Open Pawci3oo opened this issue 1 year ago • 4 comments

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.

Pawci3oo avatar Jul 11 '24 07:07 Pawci3oo

@allcontributors please add @Pawci3oo for bugs.

aaltat avatar Jul 12 '24 07:07 aaltat

@aaltat

I've put up a pull request to add @Pawci3oo! :tada:

allcontributors[bot] avatar Jul 12 '24 07:07 allcontributors[bot]

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.

aaltat avatar Aug 04 '24 10:08 aaltat

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

Pawci3oo avatar Aug 25 '24 13:08 Pawci3oo