写黄瓜测试用例

时间:2012-12-07 15:58:17

标签: ruby testing cucumber automated-tests frank

我正在尝试学习如何为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

只有在没有剩下的情况下才能正常运行。

最好的问候

2 个答案:

答案 0 :(得分:4)

ENDend是不同的ruby关键字。

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

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

答案 1 :(得分: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: 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  |