简体   繁体   English

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

[英]Executing Python Script from Robot Framework : FAILS

I have a robot framework code that should re-execute entire test suite if a single test case fails.我有一个机器人框架代码,如果单个测试用例失败,它应该重新执行整个测试套件。 So for achieving that, i ran a python script inside Robot Framework code that will re execute the code once again.因此,为了实现这一点,我在 Robot Framework 代码中运行了 python 脚本,该脚本将再次重新执行代码。 But i am not able to do that Posting my code below:但我无法做到这一点在下面发布我的代码:

***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}

and Python Script looks like this:和 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()

But Here this re-execution of the code after CookieTest fails, is not working但是在这里,在 CookieTest 失败后重新执行代码是行不通的

please have a look at the answer of your previous question.请看一下您上一个问题的答案。 https://stackoverflow.com/a/65247970/13713938 running the robot with option --output original.xml will give you all you need. https://stackoverflow.com/a/65247970/13713938使用选项运行机器人--output original.xml将为您提供所需的一切。

robot --output original.xml tests

Your case this is the step in your runner你的情况,这是你跑步者的一步

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

You then run add next step to your runner this step reruns all failed suites, not just the test.然后,您运行 add next step to your runner 此步骤重新运行所有失败的套件,而不仅仅是测试。

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

for you this would interpret as somethink like this.对你来说,这会被解释为这样的想法。

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

Finaly you just merge the two xml files最后,您只需合并两个 xml 文件

rebot --merge original.xml rerun.xml

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

You can read more about this topic in the manual https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#merging-re-executed-tests您可以在手册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