robots-from-jupyter / robotframework-jupyterlibrary

A Robot Framework library for testing Jupyter end-user applications and extensions
https://robotframework-jupyterlibrary.rtfd.io
BSD 3-Clause "New" or "Revised" License
22 stars 9 forks source link

Possible bug in `Maybe Accept a JupyterLab Prompt` keyword #44

Open lugi0 opened 2 years ago

lugi0 commented 2 years ago

This keyword checks for a jupyterlab modal using a css selector, and, if found, tries clicking a button (the first one).

The problem seems to be that the selector returns an element every time, even when there's no modal open in the JL UI. In fact, using the dev console, I get two hits with that selector all the time.

The keyword does work when there's a modal/prompt open, but it will also fail whenever it is called and no prompt is available.

I believe that changing the selector from the css based one to an xpath one would solve this issue. Specifically, reworking the keyword like this is currently working fine for me:

[Documentation]    Click the save button in a JupyterLab dialog (if one is open).
    ${accept} =    Get WebElements    xpath://div[contains(concat(' ',normalize-space(@class),' '),' jp-Dialog-footer ')]
    Run Keyword If    ${accept}    Click Element    ${accept[-1]}

Note that I also changed from accept[0] to accept[-1], since the last button is usually the confirmation one (e.g. saving a file when closing it has three buttons, Dismiss, Cancel and Save in that order).

If you agree that the behaviour of the keyword is currently not working as expected I can open a PR to merge my changes.

lugi0 commented 2 years ago

I've modified the keyword further in my own workflow, let me know if this is something that you'd be interested in merging in the library itself:

*** Variables ***
${JL_TABBAR_CONTENT_XPATH} =  //div[contains(@class,"lm-DockPanel-tabBar")]/ul[@class="lm-TabBar-content p-TabBar-content"]
${JL_TABBAR_SELECTED_XPATH} =  ${JL_TABBAR_CONTENT_XPATH}/li[contains(@class,"lm-mod-current p-mod-current")]
${JL_TABBAR_NOT_SELECTED_XPATH} =  ${JL_TABBAR_CONTENT_XPATH}/li[not(contains(@class,"lm-mod-current p-mod-current"))]

Maybe Close Popup
    [Documentation]    Click the last button in a JupyterLab dialog (if one is open).
    ### TODO ###
    # Check if the last button is always the confirmation one
    # Server unavailable or unreachable modal has "Dismiss" as last button

    # Sometimes there are multiple tabs already open when logging into the server and each one might
    # Open a pop-up. Closing all tabs at once also might create a pop-up for each tab. Let's get the
    # Number of open tabs and try closing popups for each one.

    ${jl_tabs} =  Get WebElements  xpath:${JL_TABBAR_NOT_SELECTED_XPATH}
    ${len} =  Get Length  ${jl_tabs}
    FOR  ${index}  IN RANGE  0  2+${len}
      # Check if a popup exists
      ${accept} =    Get WebElements    xpath://div[contains(concat(' ',normalize-space(@class),' '),' jp-Dialog-footer ')]
      # Click the right most button of the popup
      Run Keyword If    ${accept}    Click Element    xpath://div[contains(concat(' ',normalize-space(@class),' '),' jp-Dialog-footer ')]/button[last()]
      Capture Page Screenshot
    END