Robotframework 如何在Robot框架中通过条件测试

Robotframework 如何在Robot框架中通过条件测试,robotframework,Robotframework,我无法在Robot框架中编写if条件。 我需要知道进程是否失败\成功\仍在进行中。 我有一个超时的循环,它会一直等到进程失败\成功(完成) 我不知道如何: -从案例制动并失败测试-仅当过程失败时。 -从案例中制动并通过测试-仅当过程“成功”\完成时 以下是python代码: for i in range(timeout): if wait_for_failed_proccess is True: result = False break

我无法在Robot框架中编写if条件。 我需要知道进程是否失败\成功\仍在进行中。 我有一个超时的循环,它会一直等到进程失败\成功(完成)

我不知道如何: -从案例制动并失败测试-仅当过程失败时。
-从案例中制动并通过测试-仅当过程“成功”\完成时

以下是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

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

for i in range(timeout):
    if wait_for_failed_proccess is True:
       raise Exception("Process timed out")
    ...
...
有了上述功能,您不必在测试中执行任何操作——如果此关键字引发异常,测试将自动失败

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

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