Added a script ❌

Add a test script that gets the value of the rand property in the response JSON and sets it as the value of a variable (at collection or environment scope) named responseData. Hint: You’ll need to Send the request twice after adding your code because it won’t save the value until after the response is received the first time.

I am getting an issue in this. This is my code, where am I probably going wrong?
pm.test(‘Stats include all fields’, function () {

var jsonData = pm.response.json().data;

pm.environment.set(“responseData”, jsonData.rand);

});

Hey @telecoms-technologi1

I’m guessing this is part of the student expert training and is the skill check request.

You have .data on the end of the jsonData variable and I don’t believe that the rand property is a nested one.

ITs done, actually I did not set the environment to the new one I created. Thanks a lot.

Hi @telecoms-technologi1 @danny-dainton can you help here its saying rand is undefined

@RavneetK94 See this response and you will get it.

2 Likes

hey issue resolved thanks :slight_smile:

Hello team!

I need one help regarding Student expert skill test.

I have passed the test and after some time (after 2 mins) I again run the test now it is showing " Skill checker incomplete!". but test result (11/11) of Test collection is showing all test pass.
I am very confused what should I do?

I am attaching SS for the reference.


1 Like

Can you show the rest of the body of the skill checker response, please?

If you scroll down there will be a check list of items.

2 Likes

Hej @danny-dainton, Thank you for reply.

after spending lot of time as I am new to Postman, I resolved my problem and Completed all test.
I need to remove " " (Syntax error) from my code.
I also received Postman Student Expert Badge :heart_eyes:
It was a nice experience to solve the assignment and I will continue the rest of the training.

Have a great Day!

4 Likes

Hey unable to complete skill check .
Having problems in the last one that is added a script. Anyone plzz explain me the steps how to do it

It’s hard to help out without seeing what you have tried. Have you tried re-reading the instructions about adding the script? There are several forum posts here explaining common troubleshooting for this step. Let us know if you continue to be stuck

1 Like

How did you resolve? I didn’t get it yet

did you change anything else? Mine is not resolved yet. Can you share a screenshot?

That is what i did

pm.test(‘Checker’, function () {
var inputData = pm.response.json().rand
pm.collectionVariables.set(‘responseData’, inputData);
});

1 Like

I am lost here I passed this thing but when I go to submit it says 10 out of 11 whats up?

{
    "welcome": "You're using the Postman Skill Checker! Click Visualize for a more readable view of the response.",
    "title": "Skill checker complete!!!",
    "intro": "You completed the skill checker! To complete your training, make sure all of your requests are saved, and in the collection on the left of Postman, open the overview > then click **Share collection**. Choose the **Via JSON link** tab and click **Get JSON link** to generate or update your collection link (note that each time you make a change you need to update the link). *[**NOTE**: if the 'Share via JSON link' feature is disabled for your team, to get your public JSON link you will need to 1) **Export** your collection as a JSON file from the three dot menu on your collection, 2) **upload your JSON** text to a public filehosting site like https://www.jsonkeeper.com/ or https://www.npoint.io/]*.  Copy the address to your clipboard, then open the final folder in the collection **3. Check Progress** > open the **Test Collection** request, paste your collection link in as the request address, **Send**, and this time open the **Test Results** tab to see the status of your collection. Any failed tests will indicate parts of the collection you still need to complete. Once all of your tests pass—**Save** the request and update and copy your collection JSON link.After all your tests pass, continue with the lessons in Postman Academy to submit your collection and claim your badge (https://academy.postman.com/path/postman-api-fundamentals-student-expert/postman-api-fundamentals-student-expert-certification/1976)",
    "done": true,
    "skills": [
        {
            "name": "Changed method",
            "hint": "Change the request method to `POST`, `PUT`, or `DELETE`.",
            "value": true
        },
        {
            "name": "Sent query parameter",
            "hint": "Add `email` as a query param, with your student training email address as the value.",
            "value": true
        },
        {
            "name": "Added body data",
            "hint": "Add JSON body data including a field `name` with the value as your name.",
            "value": true
        },
        {
            "name": "Authorized",
            "hint": "Add API Key auth with the Key name `auth_key` and how much you learned from the student expert template (e.g. `loads`, `nothing`, etc) as the value (add to the request header).",
            "value": true
        },
        {
            "name": "Set a variable",
            "hint": "Add a new variable to the collection, naming it `myCourse` and enter the reason you're learning about APIs as the Current value. (Leave the other var in place.)",
            "value": true
        },
        {
            "name": "Added a script",
            "hint": "Add a test script that gets the value of the `rand` property in the response JSON and sets it as the value of a variable (at collection or environment scope) named `responseData`. Hint: You'll need to Send the request twice after adding your code because it won't save the value until after the response is received the first time.",
            "value": true
        }
    ],
    "rand": "Otha"
}

Thanks, followed your comments and resolved it too

Hey guys, I can’t completed my last step in Postman course, using the Test Script below, could you please, advise? If I run this test without Environment - I’m getting Success, with Environment - fail, screen of it added, thanks!

Task:
In this ‘Skill check’ request, add a test script in the Tests tab that gets the value of the rand property in the response JSON and sets it as the value of a collection or environment variable named responseData.

pm.test("Skill Check", function () {
var jsonData = pm.response.json().rand;
pm.environment.set("responseData", jsonData.rand);
});

@docking-module-cos13

Drop the .rand from this line.

var jsonData = pm.response.json().rand

Or change this line to.

pm.environment.set("responseData", jsonData)

At the moment, you have defined jsonData down to the rand element.

Therefore jsonData.rand would be incorrect as its already at that element.

Thank you a lot!
It helps!

pm.test("Checker", function () {

var inputData = pm.response.json()

pm.collectionVariables.set("responseData", inputData);

});