我正在写一些使用黄瓜数据表的测试。它迭代了11个场景,如果第1行出现故障,则忽略以下内容(如我们所知)。他们希望我在其中添加一些异常处理,这样整个表都会被检查。下面是我的表格:
| Row | add_line_1 | add_line_2 | add_line_3 | post_town | post_code | error |
| 1 | 123 | Over There | And down a bit | Swansea | SA9 2NG | Building/number and street must contain between 4 and 30 farts |
| 2 | 1234 | Over There | And down a bit | Swansea | SA9 2NG | Must have at least 3 alpha characters |
| 3 | **** | Over There | And down a bit | Swansea | SA9 2BG | The first character of the address must be alphanumeric. Other characters must be valid (a-z, A-Z, 0-9, &, -, (), /, ' and , or .) |
| 4 | *** | Over There | And down a bit | Swansea | SA9 2BG | Building/number and street must contain between 4 and 30 characters |
| 5 | 1 High Street | *** | And down a bit | Swansea | SA9 2BG | The first character of the address must be alphanumeric. Other characters must be valid (a-z, A-Z, 0-9, &, -, (), /, ' and , or .) |
| 6 | 1 High Street | Over There | *** | Swansea | SA9 2BG | The first character of the address must be alphanumeric. Other characters must be valid (a-z, A-Z, 0-9, &, -, (), /, ' and , or .) |
| 7 | 1 High Street | Over There | And down a bit | **** | SA9 2BG | Post town contains invalid characters |
| 8 | 1 High Street | Over There | And down a bit | *** | SA9 2BG | Post town contains invalid characters |
| 9 | 1 High Street | Over There | And down a bit | A | SA9 2BG | Post town requires a minimum length of three characters |
| 10 | 1 High Street | Over There | And down a bit | Swansea | *** | Must be between five and eight characters and in a valid format, e.g. AB1 2BA or AB12BA 测试通常在第一行失败,因为预期的错误文本不正确。
因此,我将这段代码写入我的代码中:
begin
expect(all_text).to have_text @error
rescue Exception => e
puts "#{scenario.name} >>"
puts "Table row #{@row}: #{e}"
end就其本身而言,如果您考虑到整个测试包中都有40+表,那么异常处理并不能告诉您故障发生在哪里。
我想要捕获场景名称并将其包含在异常处理中,但我得到了一个错误,指出未定义场景的方法。
有没有办法将它添加到代码块中?
谢谢
发布于 2016-12-09 20:48:56
我读得越多,就越意识到这不可能是我想要的方式。因此,我做了以下工作:
Before do |scenario|
@feature_name = scenario.feature.name
@scenario_name = scenario.name
end
begin
expect(all_text).to have_text @error
rescue Exception => e
puts @feature_name + ' : ' + @scenario_name
puts "Table row #{@row}: #{e}"
endhttps://stackoverflow.com/questions/41060612
复制相似问题