【问题标题】:How to fail a test with conditions in Robot Framework如何使用 Robot Framework 中的条件使测试失败
【发布时间】:2019-08-26 09:08:02
【问题描述】:

我无法在 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

机器人框架代码:

${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

【问题讨论】:

    标签: robotframework


    【解决方案1】:

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

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2018-10-10
      • 2015-07-19
      • 2023-03-17
      • 2016-06-14
      • 2018-04-12
      • 2021-04-19
      • 2016-01-24
      • 1970-01-01
      • 2017-11-17
      相关资源
      最近更新 更多