【问题标题】:Download a file in Selenium Grid through Robot Framework Test通过 Robot Framework Test 在 Selenium Grid 中下载文件
【发布时间】:2018-02-19 18:53:29
【问题描述】:
${options}=     Call Method     ${chrome_options}    to_capabilities 
Create Webdriver    Remote   command_executor=${REMOTE_URL}   desired_capabilities=${options}
Go To    ${url}

获取测试的节点 IP 和 SCP 文件的可能解决方案之一。 有没有办法我可以在 Robot Framework 中获取节点详细信息。

【问题讨论】:

    标签: robotframework selenium-grid


    【解决方案1】:

    我为此使用了一个有趣的解决方法。在我的套件设置中:

    Set Global Variable    ${global_downloadDir}    ${CURDIR}\\Downloads\\${suiteName}
    ${prefs} =    Create Dictionary    download.default_directory=${global_downloadDir}
    Call Method    ${chromeOptions}    add_experimental_option    prefs    ${prefs}
    Create Webdriver    Chrome    chrome_options=${chromeOptions}
    

    在我的测试拆解中,我需要清空 mi 下载目录:

    Run Keyword And Ignore Error    Empty Directory    ${global_downloadDir}
    

    然后我设置了两个关键字:

    Download Should Be Done
        [Arguments]    ${directory}=${global_downloadDir}
        [Documentation]    Verifies that the directory has only one folder and it is not a temp file and returns path to the file
        ${files} =    List Files In Directory    ${directory}
        Length Should Be    ${files}    1
        Should Not Match Regexp    ${files[0]}    (?i).*\\.tmp
        Should Not Match Regexp    ${files[0]}    (?i).*\\.crdownload
        ${file}    Join Path    ${directory}    ${files[0]}
        Log    File was successfully downloaded to ${file}
        [Return]    ${file}
    
    Wait Until File Download is Finished
        [Arguments]    ${directory}=${global_downloadDir}    ${timeout}=${global_timeout}    ${retry}=2s
        ${fileName} =    Wait Until Keyword Succeeds    ${timeout}    ${retry}    Download should be done    ${directory}
        [Return]    ${fileName}
    

    所以现在,使用等待文件下载完成关键字应该返回您的文件名:

    Click Button    id=downloadFile
    ${filename} =    Wait Until File Download is Finished
    ${content} =    Get File    ${fileName}
    

    【讨论】:

      【解决方案2】:

      如果文件是您所追求的,那么我会将共享驱动器/文件夹映射到执行节点,然后让 Chrome 将文件存储在那里。如果文件具有唯一的文件名,并且不会与将文件存储在同一位置的其他测试冲突,这将很好地工作。

      另一种方法是使用主机名或 IP 作为唯一节点标识符。此StackOverflow answer 中描述了获取主机名的问题:How to display/log which node ran Selenium test session?。这段代码背后的原理在StackOverflow answer 中得到了最好的解释。

      如果您还在网格上运行无头 Chrome 并希望将文件下载到特定目录,那么 StackOverflow answer 将为您提供必要的 Python 和机器人代码来实现它,因为这不受支持本机。

      【讨论】:

        猜你喜欢
        • 2017-11-18
        • 2016-07-20
        • 1970-01-01
        • 2017-11-04
        • 1970-01-01
        • 2021-10-18
        • 2012-05-29
        • 2017-07-18
        • 1970-01-01
        相关资源
        最近更新 更多