Issue
This Content is from Stack Overflow. Question asked by Wilson
I was trying to do the JSON schema validation in Rest Assured using the below code by reading the filename loginschema.json from src/test/resources/data folder and was getting CucumberException. Can someone provide their inputs on how to resolve this issue?
**UtilFile:**
public void verifyResponseBody(File fileName) {
String pathName = "src/test/resources/data/"+ fileName +".json";
response.then().assertThat().body(JsonSchemaValidator.matchesJsonSchemaInClasspath(pathName));
}
**Cucumber file:**
And I see response matches for fields
| success | true |
Then I see response matches file loginschema
**Common Stepdefintion File:**
@Then("I see response matches file {}")
public void i_see_response_matches_file(File fileName) {
apiUtil.verifyResponseBody(fileName);
}
**Error:**
And I see response matches file loginschema #
test.java.com.stepdefinitions.Common_StepDefintions.i_see_response_matches_file(java.io.File)
io.cucumber.core.exception.CucumberException: Could not convert arguments for step [I see response matches file {}] defined at 'test.java.com.stepdefinitions.Common_StepDefintions.i_see_response_matches_file(java.io.File)'.
Solution
You get this error because you cannot just take an arbitrary sequence of chars from your steps (like you do with {}
) and treat it as a File
(argument type that your step takes).
You should change this public void i_see_response_matches_file(File fileName)
to this public void i_see_response_matches_file(String fileName)
and create File
instance from that path internally within a step.
P.S. – Or you can create custom parameter type and describer conversion there.
This Question was asked in StackOverflow by Wilson and Answered by Alexey R. It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.