Cucumber (Groovy Script) throws Argument Mismatch Error For Numbered Valued Variables(While Executing SOAP API REQUESTS)

Here is my example feature :
Feature: Calculating Couple Of Numbers.

Scenario Outline: ADD, DIVIDE, MULTIPLY, SUBTRACT

 Given There Are Two Numbers
When("Namely <first_number> And <second_number>") 
Then Lets Print Requests Results

Examples: 
  | first_number | second_number | Result  |
  |            5 |             7 | success |
  |            7 |             9 | Fail    | 

Part Of Groovy Script Where It shows Argument Mismatch Error is :

@When("Namely (.) And (.) ")
def chekingNumbers(int a, int b) {

	println (a, b);
}

For String valued Variables All these variables runs Just fine but for numbered valued variables it throws argument mismatch error…

fyi - I am working with a SOAP API Service For Calculator Service “http://www.dneonline.com/calculator.asmx?wsdl

What is it that I am doing otherwise here causing this argument mismatch error?? Any help @Chris_Trevarthen ??!!

Hi @asifuzzamanbappy,

I’m not seeing what Namely is - is that a function in your test or a built-in BDD syntax? When I try you example, Katalon gives me a “lexing error” - is that what you see? If so, here’s some info on what that error might mean:

Here’s an overview BDD in Katalon:

And here’s a sample repo with some code that might help:

Hope this helps,

Chris

I don’t think it’s a Lexington Error, I used Namely just as a typo for viz / such as. Here I am enclosing my feature file again along with groovy script it requires. See if it works with / without When Statement.

Feature: Calculating Couple Of Numbers.

  Scenario Outline: ADD, DEVIDE, MULTIPLY, SUBTRACT
    Given There Are Two Numbers
    #When Namely <first_number> And <second_number>
    Then Lets Print Requests Results

    Examples: 
      | first_number | second_number | Result  |
      |            5 |             7 | success |
      |            7 |             9 | Fail    |

class calculatingNumbers {
	/**
	 * The step definitions below match with Katalon sample Gherkin steps
	 */
	@Given("There Are Two Numbers")
	def I_check_for_the_value_in_step() {
		println ("Within Given");
		//String addResponse = WS.sendRequest(findTestObject('Calculator API/Add Numbers'));

	}

	@Then("Lets Print Requests Results")
	def printingResults() {

		String addResponse = WS.sendRequest(findTestObject('Calculator API/Add Numbers'));

		println (addResponse);

		String devideResponse = WS.sendRequest(findTestObject('Calculator API/Devide Numbers'));

		println (devideResponse);

		String multiplyResponse = WS.sendRequest(findTestObject('Calculator API/Multiply Numbers'));

		println (multiplyResponse);

		String subtractResponse = WS.sendRequest(findTestObject('Calculator API/Subtract Numbers'));

		println (subtractResponse);
	}

	@When("Namely (.*) And (.*)")
	def chekingNumbers(int a, int b) {

		println (a, b);
	}
}

When you run this from test case using cucumber keywords for feature file or feature folder for example

( 
CucumberKW.runFeatureFile('Include/features/Calculator API/Calculating.feature')

CucumberKW.runFeatureFolder('Include/features/Calculator API')
)

You would be able to see that it runs well without When Statement, but in other case it throws Argument mismatch error.

Best regards.

Hi @asifuzzamanbappy,

I think I understand how the step definitions work a bit better, thanks to this page: https://cucumber.io/docs/cucumber/step-definitions/

The @When statement takes a regular expression or a Cucumber expression. In your case, you have it as a regular expression, reads .* as “any string of characters”. This means that those parameters are being parsed from your feature file as strings. That’s why you’re getting a type mismatch error when trying to use def checkingNumbers(int a, int b) - you’re actually passing in strings for a and b.

If you want it to parse the @When line parameters as integers, you can do it like this in a Cucumber expression:

@When("Namely {int} And {int}")

or as a regular expression:

@When("Namely (\\d+) And (\\d+)")

In regular expressions \d is a digit.

Hope this helps,

Chris

1 Like

This Basically Solves Current Problem. Thanks a lot once again , as always your shared link’s are resourceful as it can possibly get.

Best Regards.

1 Like