繁体   English   中英

从机器人框架执行 Python 脚本:失败

[英]Executing Python Script from Robot Framework : FAILS

我有一个机器人框架代码,如果单个测试用例失败,它应该重新执行整个测试套件。 因此,为了实现这一点,我在 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 失败后重新执行代码是行不通的

请看一下您上一个问题的答案。 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中阅读有关此主题的更多信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM