如何在Robot Framework中使用条件使测试失败

时间:2019-04-04 14:44:24

标签: robotframework

如果在Robot Framework中出现条件,我很难写。 我需要知道某个过程是否失败\成功\仍在进行中。 我有一个超时循环,一直等待到该过程失败\成功(完成)

我不确定如何: -失败并失败测试-仅在处理失败的情况下。
-从案例中制动并通过测试-仅在过程“成功” \完成时。

这是python代码:

   for i in range(timeout):
       if wait_for_failed_proccess is True:
          result = False
          break 
       if wait_for_success_process is True:
          result = True
          break 
       time.sleep(1000)
   return result

机器人框架代码:

${result} =    Test process waiter
Run keyword if| ${result}==False---> need to fail test. the process has failed  
Run keyword if| ${result}==True---> test passed. continue to the next test 

Test process waiter
 [documentation]          wait until process is done
 [timeout]                25 min 

 For      ${index}     IN RANGE     [TIMEOUT]
  run keyword if|Validate failed process==Ture|${result}=False|Exist From loop 
  run keyword if|Validate success process==Ture|${result}=True|Exist From loop
  Sleep      10
 END
 [return] result 


Validate failed process
 [documentation]        confirmed process failed 
 Element should contain     ${message}     Failed 

Validate success process 
[documentation]        confirmed process is done 
Element should contain     ${message}     Completed successfully

1 个答案:

答案 0 :(得分:3)

最常见的方法是让您的python代码引发异常,而不是返回TrueFalse

for i in range(timeout):
    if wait_for_failed_proccess is True:
       raise Exception("Process timed out")
    ...
...

使用上述方法,您无需在测试中做任何事情-如果此关键字引发异常,则测试将自动失败。

如果您希望返回true或false值,则可以使用内置的fail关键字:

Run keyword if | ${result}==False | fail | Process timed out