Student Expert Issue

Having issue with last part on skill check of check progress part in Student expert collection.

“name”: “Added a script”,
“hint”: “Add a test script that gets the value of the rand property in the response JSON and sets itas 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”: false
}
],
“rand”: “Juana”

My code in test script was:

pm.test(‘Status code is 200’, function() {
pm.response.to.have.status(200);
});

pm.test(‘Stats include all fields’, function() {
var jsonData = pm.response.json().rand;
pm.environment.set(‘jsonData’, jsonData);
});

Hi there - you’ll see discussion on this in the training section:
https://community.postman.com/tag/training

We can’t provide the answer because the purpose of this part of the template is for you to learn how to reapply what you learned in the first sections. If you look back at the requests in the second folder you’ll see examples that are similar to what you need here. :slightly_smiling_face:

I have the same problem, I have already added the test and a console.log to check if the answer is being recorded in the environment variable.
I don’t want you to give me the answer, I would like to know if mine is wrong, in my opinion there is something wrong with the exercise verification
var jsonData = JSON.parse(responseBody); pm.test('verifica retorno da variavel', function () { pm.environment.set("responseData", jsonData.rand); pm.expect(jsonData.rand).to.eql("Kamron") console.log(jsonData.rand) })
I am delighted with all the features of the postman congratulations to the whole team.

Hi @ferpioli, the part of your code that is setting the var looks correct, if you’re seeing a test fail I believe that’s probably due to the test you have set to check the hard-coded string (the rand field will change between sessions)–the request does not require this to be built into a test, it just requires you to set the var.

Hi, @suesmith even without this test, I’m still taking the error, what can be happening?
var jsonData = JSON.parse(responseBody);
pm.test(‘verifica retorno da variavel’, function () {
pm.environment.set(“responseData”, jsonData.rand);
console.log(jsonData.rand)
})

Can you share a screengrab of the error?

@suesmith Thanks for somewhat looking back. After reading responses in this question and looking back at previous ones, found that I was missing the console.log statement, so nothing was ever being returned

Hmm your code works when I try it–you are hitting the send button twice (you need to because the var is set after the request sends)? Can you also open the environment to check what the var value is for me?

Sue, had one last question. for the test collection step, not sure I am grabbing the link from the right spot. is there a doc I should view for this?

Sure, so you want the collection share link (note that you need to update it each time you make a change):

@suesmith Is that link we are to use in the student expert portion? just want to make sure I am using the right link. that’s what steps I was following but was unclear if it was right

That is the link to submit your collection to receive the badge if I’m understanding your question correctly. However if there is an issue with the link we will follow up with you!

@suesmith, look at the environment.

@suesmith
Once I share the link, and run the test collection one. I get these tests failing. But the skills pass. not sure what to do

Used GET, POST, PUT, DELETE methods | AssertionError: expected [ ‘GET’, ‘GET’ ] to be a superset of [ ‘GET’, ‘POST’, ‘PUT’, ‘DELETE’ ]
FAIL
Used query and path parameters | AssertionError: expected to have a length above 0 but got 0
FAIL
Sent body data | AssertionError: expected to have a length above 0 but got 0
FAIL
Used variables | AssertionError: expected to have a length above 0 but got 0
FAIL
Added request description | AssertionError: expected to have a length above 0 but got 0

1 Like

@suesmith
https://www.getpostman.com/collections/2b220804f742c40a50d0

@suesmith

here is the link so u can see tests that pass
https://www.getpostman.com/collections/7113b113bc0bbf5ca6ff

Hi @ferpioli I believe I can see the issue, you seem to have removed a header from the request which is required for this to work–if you can import the student expert template over again and open the skill check request you should see there is meant to be one in there named response-value that has gone missing from yours. Feel free to copy it from the newly imported version into your completed collection and try again. :upside_down_face:

1 Like

@anantsan the collection is missing some required parts–maybe you haven’t saved your requests from the first two folders…? When you work through the steps in the first two folders you need to make sure your requests are saved, and update the share link before trying again. :slightly_smiling_face:

thanks, @suesmith follow the link.
https://www.getpostman.com/collections/2b220804f742c40a50d0
I sent it through the form too