简体   繁体   中英

Writing cucumber test cases

I am trying to lear how to write test scripts for frank ( cucumber test scripts).

This is what I have written

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

where the letters are written instead of the view/picture names

This is what i get while running the script

/Users/janogrodowczyk/SMHI/ios/ios/Frank/features/step_definitions/test_steps.rb:14: syntax error, unexpected $end, expecting kEND (SyntaxError)

And i have no idea what i am doing wrong since the first 2 rows

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

are working fine when only they are run without the rest.

Best Regards

END and end are different ruby keywords.

END represents code to be executed before the end of a program.

end designates the end of a class, method, control structure, etc.

Navigating to "aaa" and "bbb" is actually two scenarios. You can't "navigate" again in one scenario.

So, firstly refactor your steps from

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

To:

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

But, wait. Why duplicate? `Scenario Outline" could help you to test similar cases.

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  |

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM