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

lih*_*_h3 3 robotframework

我在 Robot Framework 中编写 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
Run Code Online (Sandbox Code Playgroud)

机器人框架代码:

${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
Run Code Online (Sandbox Code Playgroud)

Bry*_*ley 6

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

for i in range(timeout):
    if wait_for_failed_proccess is True:
       raise Exception("Process timed out")
    ...
...
Run Code Online (Sandbox Code Playgroud)

有了上面的内容,您不必在测试中做任何事情——如果此关键字引发异常,则测试将自动失败。

如果您更喜欢返回 true 或 false 值,可以使用内置的fail关键字:

Run keyword if | ${result}==False | fail | Process timed out
Run Code Online (Sandbox Code Playgroud)