Hello everyone again 🙂
I will describe to you how we can use some data and variables in ours features of cucumber. For this I will use the same last example of feature, the search. To use this data, we will have to change somethings. Look:
Scenario Outline: Search > Don’t forget to write Scenario Outline when you use Examples.
And look for: “<keyword>”
The keyword is the variable, that I will use to substitute the data in the table of Examples. This table Examples should be this name “Examples:”. I already tried others name and the cucumber don’t recognise others names of BD. So this table with data should be this format too:
|variable1|variable2|variable3|… >This is the title of each field, variables
|Data 1| Data 2| Data 3|… > This is the data of each column that will be used in the first interaction
|Data 4| Data 5| Data 6|… > This is the data of each column that will be used in the second interaction
|Data 7| Data 8| Data 9|… > This is the data of each column that will be used in the third interaction
… and this is the way ahead.
Don’t forget the |, these are the lines of each column, and they separate the datas. In my example, the cucumber will execute the first search with the keyword = Nike and the second search with keyword = Paris and after the execution will be stopped. Because I don’t have more data to use in the table.
You can just run the command: cucumber, and the calabash will show you in yellow of your terminal, what is the step missed. So you need copy this step and put in the file of ruby.
Given(/^look for: “(.*?)”$/) do |arg1|
After this you can implement the code in ruby that this step will do. Look that this step that calabash showed to you has a regex in the local of your variable. This is normal, and you have to have a regex in the local of the variables.
After this, you can just change the name of this variable. In the final of sentence this variable is showed like: |arg1| and I changedfor the title of the field in the feature’s table . Look, everything that between | is a variable that you can use in the code. And my code was:
Given(/^look for: “(.*?)”$/) do |keyword|
tap ‘icon openmenu’
Just this, now it is only run the command cucumber and wait for results !
I hope that I have helped you guys 🙂
I will post many examples, with more fields after. Just an observation: Cucumber have a limit of this fields and you can’t have many tables inside of Examples. If you have many scenarios inside this feature you can have another table of Examples, but each table should be after each scenario.