[serenity-rest-assured] Reporting request on assertions

1,476 views
Skip to first unread message

Erik

unread,
Jun 24, 2015, 5:55:57 AM6/24/15
to thucydid...@googlegroups.com
Hi,

I've just implemented the first steps in our cucumber + serenity framework with the rest-assured module. We're already satisfied with the Webdriver implementation for the GUI part of the application. For the rest services I now have a first major question. The reports (also as shown in the bdd-microservices presentation) contain the steps, request and response are also logged. My major issue is the validations on that request that pass the step or fail it are not logged at this time. 

For example I use this very simple test step:

sessionResponse.then().statusCode(200)
.and().body("message", equalTo("API key is not valid."));

Now I would want to have logged that the statuscode and the body assertions completed correctly. If they fail I want to know which of the validations failed on the request. 

Am I doing something wrong? Should I implement these validations using a different framework?

Thanx,

E. 

John Smart

unread,
Jun 24, 2015, 6:02:06 AM6/24/15
to Erik, thucydid...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Serenity BDD Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thucydides-use...@googlegroups.com.
To post to this group, send email to thucydid...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
___________________________________________________
John Smart | Wakaleo Consulting  |  +61 407 247 642
Optimizing your software development process
http://www.wakaleo.com  |  john....@wakaleo.com
___________________________________________________

We love breaking down silos and helping smart teams collaborate better! Ask about our tailored on-site workshops in Agile Requirements Discovery, Behaviour Driven Development, Agile Development Practices, and Test Automation!
___________________________________________________

Erik

unread,
Jun 30, 2015, 2:37:24 AM6/30/15
to thucydid...@googlegroups.com, eri...@gmail.com
John, maybe I can clarify since the assertions are working correctly and the requests are all sent and processed through RESTAssured.

I use Cucumber with Serenity.

<!-- The runner -->

package app.features.webservice;

import cucumber.api.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;

import org.junit.runner.RunWith;

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(features="src/test/resources/features/", tags = {"@Webservice"})
public class SimpleWebserviceIntake {

}



<!-- The step definition -->

//

import ;

@ContextConfiguration(loader = SpringApplicationContextLoader.class)
public class StepDefinitions { 

// 

@Given("^the request has an empty body$")
public void the_request_has_an_empty_body() throws Throwable {

/*
* Setting of the baseURI, empty envelope etc. 
*/

   rest().given().request().headers(authhdrs)
     .contentType("application/soap+xml; charset=UTF-8;").body( myEnvelope )
     .when().post( baseURI ).then().statusCode(200);
 
 /*
 * The actual error from the server is a HTTP 500 internal server error. Since I expect 200, assertion error in the logs.
 */
 
 
 
<!-- The console log -->  

java.lang.AssertionError: Expected status code <200> doesn't match actual status code <500>.

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190)
at com.jayway.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure.validate(ResponseSpecificationImpl.groovy:572)
at com.jayway.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure$validate$1.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at com.jayway.restassured.internal.ResponseSpecificationImpl.validateResponseIfRequired(ResponseSpecificationImpl.groovy:731)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:207)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:56)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
at com.jayway.restassured.internal.ResponseSpecificationImpl.statusCode(ResponseSpecificationImpl.groovy:106)
at com.jayway.restassured.specification.ResponseSpecification$statusCode$0.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
at com.jayway.restassured.internal.ResponseSpecificationImpl.statusCode(ResponseSpecificationImpl.groovy:114)
at com.jayway.restassured.internal.ValidatableResponseOptionsImpl.statusCode(ValidatableResponseOptionsImpl.java:114)
at app.features.webservice.steps.StepDefinitions.the_request_has_an_empty_body(StepDefinitions.java:79)
at .And the request has an empty body(webservice/errortest.feature:9)
 
  <!-- Attached is the report I see --> 

Now I would expect to see in the serenity report the Failed (Which is there) and the assertion text of what was wrong (Which is missing).

I would expect to see the text " Expected status code <200> doesn't match actual status code <500>." In the report as shown on the attached screenshot.

This does work when working through WebDriver. What am I doing wrong here? 
Serenity Report.png
Reply all
Reply to author
Forward
0 new messages