I am building a rest assured test FW with picocontainer DI using cucumber java. I need to share the request and response using the DI, but REST assured provides RequestSpecification and Response which are Interfaces and Interfaces cannot be shared. What is the REST assured non interface class that will allow me to build a request and response, issue a HTTP request and read the request and response data in other classes. Basically I need a way to create rest assured request and response java object.
Asked
Active
Viewed 435 times
0
-
just curious if are you aware of https://github.com/intuit/karate - it can save you a lot of work – Peter Thomas Jan 27 '19 at 04:01
1 Answers
0
The dependency injection context in cucumber-jvm
spans the execution of a scenario. So it can only contain objects which can be created without any information from the scenario.
So rather then trying to share the RequestSpecification
and Response
you can share a helper class that has references to these objects. For example (constructors ommited):
class MyStepDefs {
SomeService service;
@Given("a request")
void given_a_request(){
service.createRequest();
}
}
class OtherStepDefs {
SomeService service;
@When("a thing")
void a_thing(){
service.doThing();
}
}
class YetOtherStepDefs {
SomeService service;
@Then("it happens")
void a_thing(){
service.asserItHappend();
}
}

M.P. Korstanje
- 10,426
- 3
- 36
- 58
-
I am already using something like BuildRequest.buildRequest() where in I use RequestSpecBuilder to build the request and am sharing BuildRequest using DI, but I am unable to print anything from the request as it has no getHeaders() or getBaseURI() etc. RequestSpecification bring a Interface, I was not able to DI the RequestSpecificationImpl for some reason. I am also not selectively able to print the Request contents. – HudBud108 Jan 28 '19 at 22:57
-
"am sharing BuildRequest using DI" you can't. You can only share an object with a reference to the BuildRequest. – M.P. Korstanje Jan 29 '19 at 07:44
-
Class IssuePost(){ private BuildRequest request; public IssuePost(BuildRequest request){ this.request=request; } BuildRequest.doSomething(); Thats the way I am sharing data using pico container DI. – HudBud108 Jan 29 '19 at 14:22
-
Also things that Rest assured puts things like Authentication etc (I tried adding it as a header but then there would be two authentications set for some reason), cannot be shared because there is no way of getting that from RequestSpecification as there are no getters in request specification (there are only setters, why did the designers not think that I may want to get something from the Request!!!!) – HudBud108 Feb 14 '19 at 15:51