【问题标题】:Executing Python Script from Robot Framework : FAILS从机器人框架执行 Python 脚本:失败
【发布时间】:2020-12-12 18:07:01
【问题描述】:

我有一个机器人框架代码,如果单个测试用例失败,它应该重新执行整个测试套件。因此,为了实现这一点,我在 Robot Framework 代码中运行了一个 python 脚本,该脚本将再次重新执行该代码。但我不能那样做 在下面发布我的代码:

***Settings***
Variables  DailyRun

*** Variables ***
${InstanceName}   abvsu

*** Test Cases ***
CookieTest
    sleep  10 sec
    ${CookieValue}   Get Cookie    tmsprd103842
    Log To Console  ${CookieValue.value}
    ${b}=    Get Regexp Matches    ${CookieValue.value}   abc
    Set Global Variable  ${b}
    Run Keyword if   ${b} != '[abc]'   Loginafterfail

*** Keywords ***
Loginafterfail
#    Close Browser
    ${result}=  run process       python       DailyRun.py
    Log to Console   ${result.stdout}

Python 脚本如下所示:

def Callingfunction(IntsanceName):

    date_time = datetime.now().strftime("%m%d%Y-%H%M%S")
    log_time = "TestResult-" + date_time
    for i in range(0, 1):
        os.system(
            'cmd /c "robot '+IntsanceName+'.robot "'
        )
def main():
    Callingfunction()

if __name__ == "__main__":
    main()

但是这里在 CookieTest 失败后重新执行代码是行不通的

【问题讨论】:

    标签: python robotframework


    【解决方案1】:

    请查看您上一个问题的答案。 https://stackoverflow.com/a/65247970/13713938 使用选项 --output original.xml 运行机器人将为您提供所需的一切。

    robot --output original.xml tests
    

    你的情况,这是你跑步者的一步

    os.system(
        'cmd /c "robot --output original.xml '+IntsanceName+'.robot "'
    )
    

    然后您运行 add next step to your runner 此步骤将重新运行所有失败的套件,而不仅仅是测试。

    robot --rerunfailedsuites original.xml --output rerun.xml tests
    

    对你来说,这会被解释为这样的想法。

    os.system(
        'cmd /c "robot --rerunfailedsuites original.xml --output rerun.xml '+IntsanceName+'.robot "'
    )
    

    最后你只是合并两个 xml 文件

    rebot --merge original.xml rerun.xml
    
    os.system(
        'cmd /c "rebot --merge original.xml rerun.xml "'
    )
    

    您可以在手册https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#merging-re-executed-tests中阅读有关此主题的更多信息

    【讨论】:

      猜你喜欢
      • 2016-07-29
      • 1970-01-01
      • 2016-08-09
      • 2017-11-22
      • 1970-01-01
      • 2017-05-26
      • 2019-01-14
      • 2015-02-18
      • 2017-08-06
      相关资源
      最近更新 更多