Then I click the category Age
Then /^Click the category ([^"]*)$/ do |x|
$driver.get "https://www.example.com"
element = $driver.find_element :xpath => "//a[@class='mainNavLink' and text() = '#{x}']"
element.click
end
So this way if I want to click any other category, I don't need to write another step definition for that category. I just write new step
Then I click the category HeightThe problem here is the following. Driver is taking "Age" string from step in feature file and looking for element with that text. But what if the text changes later? Let's say it will become "How old". Then I will have to rewrite all steps that click that category.
So I want to make Age a constant. I define it in a separate file (elements.rb) as:
AgeCategory = "Age"
And I now write my feature file as this
Then I click the category AgeCategoryThis way if text "Age" changes, I will only have to change the definition of my constant in elements.rb file.
But if I try to execute this now, the code pick up the string value "AgeCategory" and not the value "Age" of the Constant "AgeCategory".
Any solutions for that?Thx!I recommend using the site prism gem for this: https://github.com/natritmeyer/site_prism
Site prism will allow you to create a class for your page, and element mappings reside in the class. You reference or anywhere in your step definitions you need, and have a single place to update it if anything changes, without having to come up with all sorts of constants as you proposed.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I don't want to start any sort of flame war here, but do want to point out that that using page-objects is not a 'requirement' for writing simple elegant features. IMO the concept of pages is the wrong one for testing web applications, the things we should be thinking about are resources.All best
Anyhow different strokes for different folks and all that
Andrew
Then /^Click the category ([^"]*)$/ do |x|
element = $driver.find_element :xpath => "//a[@class='mainNavLink' and text() = '#{x}']"
element.click
end