Unable to find a way to create extra children with restQuery in the final report
See original GitHub issueI’ve had the pleasure of working with Cucumber-JVM combined with Serenity in the past and am now using the cucumber.js and serenity-js it in a TypeScript project. I’m still figuring out the differences a bit obviously, but one of the things I haven’t been able to figure out is how to get extra ‘children’ - specifically with restQuery to end up in the reports.
Now matter what I try with World#attach() or World#log(), it doesn’t seem to end up in the report.
Basically I only get one ‘level’ of steps in the resulting JSON like this:
...
"testSteps": [
{
"number": 1,
"description": "Given a carrier Xxxx with valid OAuth credentials",
"startTime": 1657348150985,
"children": [],
"reportData": [],
"screenshots": [],
"duration": 385,
"result": "SUCCESS"
},
{
"number": 2,
...
This will give me something like this:

But if I manually insert a child with a restQuery field:
...
"testSteps": [
{
"number": 1,
"description": "Given a carrier Xxxx with valid OAuth credentials",
"startTime": 1657348150985,
"children": [
{
"number": 2,
"description": "POST https://test-auth.example.com/oauth/token/",
"duration": 0,
"startTime": "2021-12-23T15:37:26.511641+01:00[Europe/Amsterdam]",
"result": "SUCCESS",
"restQuery": {
"method": "POST",
"path": "https://test-auth.example.com/oauth/token/",
"content": "{\n \"audience\": \"https://api.example.com/something/\",\n \"scope\": \"openid profile email\",\n <truncated>}",
"contentType": "application/json",
"requestHeaders": "Accept=*/*\n\t\t\t\tContent-Type=application/json; charset=UTF-8",
"requestCookies": "",
"responseHeaders": "Date: Thu, 23 Dec 2021 14:37:26 GMT\nContent-Type: application/json\nTransfer-Encoding: chunked\nConnection: keep-alive",
"responseCookies": "...",
"responseBody": "{\n \"access_token\": \"some-token\",\n \"scope\": \"openid profile email\",\n \"expires_in\": 86400,\n \"token_type\": \"Bearer\"\n}",
"statusCode": 200
},
"precondition": false,
"level": 1
}
],
"reportData": [],
"screenshots": [],
"duration": 385,
"result": "SUCCESS"
},
{
"number": 3,
I can expand the first step all the way up until the REST query even:

(The dates etc don’t match up, because I copied the example over from some time ago (from a JVM based report))
So the question is: if this is supported currently. Thanks in advance.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (4 by maintainers)

Top Related StackOverflow Question
Thank you for your elaborate comment. I will have a look into the solution above. Unfortunately for the short term I’m really not able to rewrite what I already had. I wanted to use something like
pactum(actually coming from Java I’m missing RestAssured a bit) but I didn’t see how I could fit that into the screenplay model the way you just showed. I need to have a good look at it, also in relation to how the state is managed¹.For this issues specifically: I think it can be closed. I’ve now covered my use case as follows:
pactumexposes a global way to attach an ‘event handler’ after any spec interaction. In that handler (which get’s all the spec data) I’m doing the following:This could theoretically be done with the
serenityglobal object, but I’m missing thecurrentActivityId()which I think I need because I need the same activityId in both theInteractionStarts,ActivityRelatedArtifactGeneratedandInteractionFinished.Result is this a collapsed step:
which can be expanded to:
Which works awesome. Thanks again for the project!
¹ it’s not too easy to describe exactly how I’m managing that now, but it roughly boils down to having actors (I coincidentally called them actors as well) that expose both functionality (i.e. a
createReservation(...)that issues a HTTP request somewhere) and state. Actors are ‘attached’ to the custom World object. I have definedParameterTypesto quickly fetch actors based on some identifiers, so I can useGiven('{someActor} does something', function(someActor: SomeActor) {}).Cool, glad you got it to work and thanks for the update! One suggestion:
and then you can replace calls to
stage.currentActivityIdwithactivityIdRegarding state management, the developer-accessible state in Serenity/JS actors is represented using a concept called a
Notepad(so actors can take “notes” of interesting things as they go about their work) - check out the examples here. Apart from that, every ability can have its own state, since an ability is instantiated for a specific actor and discarded when the actor is dismissed. For example, the ability toCallAnApiholds on to thelastResponse,Glad you found Serenity/JS useful, by the way. Let me know if you find things that could be improved or if you’d like to collaborate on making some of those improvements happen 😃