question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to find a way to create extra children with restQuery in the final report

See original GitHub issue

I’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: image

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:

image

(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:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
aukevanleeuwencommented, Jul 21, 2022

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: pactum exposes 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:

function recordSpecActivity(stage: Stage, data: SpecData): void {
    stage.assignNewActivityId();

    const interactionDetails = new ActivityDetails(new Name(`${data.request.method.toUpperCase()} ${data.request.url}`));

    try {
        serenity.announce(
            new InteractionStarts(stage.currentSceneId(), stage.currentActivityId(), interactionDetails, new Timestamp(new Date(parseInt(data.start)))),
        );

        // announce a request/response based artifact to Serenity, so it will be attached to the Serenity report
        serenity.announce(
            new ActivityRelatedArtifactGenerated(
                stage.currentSceneId(),
                stage.currentActivityId(),
                new Name(data.name ?? data.id),
                requestResponseArtifactFromSpecData(data),
                stage.currentTime(),
            ),
        );
    } finally {
        serenity.announce(
            new InteractionFinished(
                stage.currentSceneId(),
                stage.currentActivityId(),
                interactionDetails,
                new ExecutionSuccessful(),
                new Timestamp(new Date(parseInt(data.end))),
            ),
        );
    }
}

This could theoretically be done with the serenity global object, but I’m missing the currentActivityId() which I think I need because I need the same activityId in both the InteractionStarts, ActivityRelatedArtifactGenerated and InteractionFinished.

Result is this a collapsed step:

image

which can be expanded to:

image

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 defined ParameterTypes to quickly fetch actors based on some identifiers, so I can use Given('{someActor} does something', function(someActor: SomeActor) {}).

0reactions
jan-molakcommented, Jul 21, 2022

Cool, glad you got it to work and thanks for the update! One suggestion:

function recordSpecActivity(stage: Stage, data: SpecData): void {
-    stage.assignNewActivityId();
+    const activityId = stage.assignNewActivityId();

and then you can replace calls to stage.currentActivityId with activityId

Regarding 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 to CallAnApi holds on to the lastResponse,

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 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Query (Feature Service/Layer)—ArcGIS REST APIs
The query operation returns either a feature set, an array of feature IDs, and/or a result extent.
Read more >
Making REST and SOAP API Requests - Retool Docs
You can make requests to any HTTP API in Retool. Learn how to query REST and SOAP APIs using Retool. Send POST, GET,...
Read more >
REST API (v1) - codeBeamer
In that case the response body contains additional failure information: ... For example: Create a new wiki page as child of the project's...
Read more >
Define a Cloud REST Query for cloud computing devices
As part of creating or modifying a discovery pattern, you can use the Cloud REST Query operation to extract information from configuration items...
Read more >
REST API - Synopsys Community
I would like to find the scan status using REST api, If the scan failed due to an ... How to get coverity...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found