我们在工作中使用机器人框架进行一些自动化测试,我需要添加一些测试。这种格式已经在回购中,我无法彻底改变任何内容。
我使用的关键字文件如下所示:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from robot.api.deco import keyword
class testkeywords(object):
"""
"""
def __init__(self):
pass
@keyword('I compare ${first_number} with ${second_number}')
def compare(self, first_number, second_number):
if (int(first_number) != int(second_number)):
raise ValueError('Numbers are not the same.')
.robot文件有两个测试,一个通过,另一个失败:
*** Settings ***
Library testkeywords.py
*** Variables ***
${num_a} 5
${num_b} 6
*** Test Cases ***
Compare same numbers
I compare ${num_a} with ${num_a}
Compare different numbers
I compare ${num_a} with ${num_b}
Compare different numbers
测试按预期失败,但仍然失败。如何将其设置为期望失败并因此传递关键字?
答案 0 :(得分:0)
我明白了。您可以修改测试以预期错误,如下所示:
Compare different numbers
Run Keyword And Expect Error * I compare ${num_a} with ${num_b}
或者查找特定错误(而不是通配符):
Compare different numbers
Run Keyword And Expect Error ValueError: Numbers are not the same. I compare ${num_a} with ${num_b}
请注意命令,错误和关键字之间的双重空格。