How to Compare Xml Output in a Cucumber Step Using a Multiline String Example

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



Leave a reply



Submit