1

我正在尝试学习如何为 frank 编写测试脚本(黄瓜测试脚本)。

这是我写的

When I navigate to "aaa"
Then I should be on the aaa screen
Then I navigate to "bob"
Then I should be on the bob screen 

When /^I navigate to "(.*?)"$/ do |aaa|
  touch "view:'UITabBarButton' marked:'aaa'"
END

Then /^I should be on the aaa screen$/ do
  check_element_exists "view:'UIImageView' marked:'xxx'"
END

Then /^navigating to "(.*?)"$/ do |bbb|
  touch "view:'UITabBarButton' marked:'bbb'"
end

Then /^I SHould be on the bbb screen$/ do
   check_element_exists "view:'UIImageView' marked:'zzz'"
end

写字母而不是视图/图片名称的位置

这是我在运行脚本时得到的

/Users/janogrodowczyk/SMHI/ios/ios/Frank/features/step_definitions/test_steps.rb:14:语法错误,意外$end,期待kEND(SyntaxError)

而且我不知道自前两行以来我做错了什么

When I navigate to "aaa"
Then I should be on the aaa screen

只有在没有其余部分的情况下运行它们时,它们才能正常工作。

此致

4

2 回答 2

4

END并且end是不同的红宝石关键字。

END表示要在程序结束之前执行的代码。

end指定类、方法、控制结构等的结束。

于 2012-12-07T17:51:45.530 回答
3

导航到“aaa”和“bbb”实际上是两种情况。在一种情况下,您无法再次“导航”。

所以,首先重构你的步骤

When I navigate to "aaa"
Then I should be on the aaa screen
Then I navigate to "bob"
Then I should be on the bob screen

至:

Given blah blah
When I navigate to "aaa"
Then I should be on the aaa screen

Given blah blah
When I navigate to "bbb"
Then I should be on the bbb screen

可是等等。为什么要复制?`Scenario Outline" 可以帮助您测试类似的案例。

Scenario Outline: Visit UI
Given blah blah
When I navigate to <link>
Then I should see <screen_name> screen

Examples:
  | link | screen_name |
  | aaa  | aaa screen  |
  | bbb  | bbb screen  |
  | ccc  | ccc screen  |
于 2012-12-09T18:14:24.487 回答