How do I compare xml output in a Cucumber step using a multiline string example?
You can use Hash.from_xml and then compare with Hash.diff. Comparing as hashes eliminates insignificant whitespace from messing up comparisons.
How can I prevent Cucumber to run @before in all glue files?
@Before
hook purpose is to execute set of steps before each scenario. Here you can achieve in this way.
Scenario:
@Regression
Scenario: Test the login functionality
Given launch url
And enter credentials
Then click on login
Before Hook: Now you can put a condition in @Before
method to control what you want to execute.@Before
public void setup(Scenario scenario) {
if(scenario.getSourceTagNames().contains("@Regression")) {
//perform steps what you need.
}
}
In case, you want to put multiple conditions then it should be this way.@Before
public void setup(Scenario scenario) {
Collection<String> scenarioTags = scenario.getSourceTagNames();
if(scenarioTags.contains("@Regression") || scenarioTags.contains("@Smoke")) {
//perform steps what you need.
}
}
Is there any better way to ignore \n?
I would not compare strings, it just sucks.
Instead I would compare the object representations.
Try to use: Hash#from_xml and compare the hashes.
Is there any better way to ignore \n?
I would not compare strings, it just sucks.
Instead I would compare the object representations.
Try to use: Hash#from_xml and compare the hashes.
Escaping characters in cucumber step definition
You need to change
@Then("^warning \"([^\"]*)\" should be given to user
to
@Then("^warning \"(.*?)\" should be given to user$"
[^"]*
is matching everything except quotes
.*?
will match everything (including quotes )
For more information See here
You can also use multiline string to do that as explained in above link
Also see this video tutorial for including strings in your arguments
Cucumber: Unable to find step definition
It looks like Cucumber isn't finding your step defintion class. In your unit test class you say:
glue = {"com.macro.definition"}
However the step definition classes are in com.test.definition
Try changing that line to:
glue = {"com.test.definition"}
You may have to rebuild your project to pick up the change.
Related Topics
Using a Self-Signed Certificate
Reading Files in a Zip Archive, Without Unzipping The Archive
Filtering Sensitive Data with Vcr
Waiting for Ruby Child Pid to Exit
Does The Rails Orm Limit The Ability to Perform Aggregations
How to Get Records Created at The Current Month
Sql Like Operator in Ruby on Rails
How to Remove Ruby on Rails 4 Beta
Error Installing Ruby in Yosemite
Ruby Fails on Osx Lion with Rbenv
Running "Bundle Install" Fails and Asks Me to Run "Bundle Install"
How to Open File in Default Application. Ruby
Rvm Finding System Gems' Executables
Sidekiq to Execute at Specific Time in Every Timezones
Getting a "Connection Reset by Peer" Error When Hitting Google Contacts API