I have a framework that I am building from the ground up using webdriver-IO cucumber and javascript. I have a drop down control to select from and I can only select the option based on 'text()='
I am trying to include a function call in my Scenario Outline and include this in the inline table
Please let me know if this is possible?
Scenario Outline: Generate a standard quote
Given I am a potential client
When I enter <age> <income> <smoker> <education> <gender> AND I perform the action Calculate
Then I am presented with a quote
Examples:
| age | income| smoker | education | gender |
| 22 | 30000 | ddlText.NoSmoker | ddlText.edu3YearDip | ddlText.genderMale |
| 22 | 30000 | ddlText.YesSmoker| ddlText.edu4YearDip | ddlText.genderFemale|
I have a getter class and the reason for this approach is because controls do not have ids, its not a k/v pair and I can only find the text when selecting from a drop down list. So note above in the inline table I am trying to call ddlText.NoSmoker and my implementation will then make the selection based on the value from the inline table
class ddlText{
get NoSmoker(){
return $("//*[text()='No']")
}
Trying to program in gherkin is a really bad idea. Gherkin is not a programming language its a limited natural language designed to express intention. So trying to put things like function calls in Gherkin is only going to cause you pain.
Secondly avoid scenario outlines. Its much better to write a few simple scenarios than one complex scenario outline. The art of using Cucumber is to keep your features as simple as possible. Push your complexity down to the step definitions or better still helper methods or your application code.
So instead of doing one scenario outline for generating quotes. Do several scenarios, one for each type of quote.
Scenario: Smoker quote
Given I am a smoker
When I enter my details
Then I should get a quote
Scenario: Non smoker quote
Given I am a non smoker
When I enter my details
Then I should get a quote
Then use the step definitions to determine how to use your select control.
When "I enter my details" do
...
@i.smoker? ? select smoker : select non_smoker
...
end
Because your step definitions are in a programming language you can do clever things like
@i is a person.object created in the Given who has a method smoker?
Now your features are simple, and your complexity is all in the code where you have the power to do whatever you want.