30 days challenge : Day 28 - UI testing

Hi, Iā€™m trying to complete the day 28 about UI testing, where I need to request a document from pagespeedonline API, retrieve a score and save it.

I tried to do it for https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https://www.example.com. However, the details for this challenge and I donā€™t know exactly which field to use in the tests - the return JSON has 1.5k lines of ā€œcodeā€, where the string ā€œscoreā€ appearsā€¦ 120 times!

Which field should I be using? I would post the response here but itā€™s too longā€¦ Help would be greatly appreciated!

As a rant, I think the challenge is great but the documentation about 3rd party libraries or APIs is a bit lackluster.

EDIT: found the answer.

By digging deeper into the docs of the pagespeed API (Get Started with the PageSpeed Insights API Ā |Ā  Google Developers), with some trial and error, and even establishing a mock server to avoid exceeding quota for Page Speed requests, I was able to find the correct field: lighthouseResult.categories.performance.score, at line 1409. And unlike stated in the documentation, the score goes from 0 to 1.0, not from 0 to 100.

Maybe this was the ultimate Postman test!

6 Likes

Hi @pnt12,

In this case, you have to find the performance score of the website. In JSON response, you may need to search the same.

1 Like

Thank you @pranavdavar, but once again, this is a huge JSON with a tons of different scores.

By reading the docs and doing some trial and error I was able to find the answer. I will edit the OP with the answer to help others,

3 Likes

Dear all,
I think there is an alternative to @pnt12 solution. However I had a syntax issue in Postman.
Metrics contribute to the lighthouse performance score.
Here we are focused on those six metrics:
1.first-contentful-paint
2.speedIndex
3.largest-contentful-paint
4.time to interactive
5.total-blocking-time
6.cumulative-layout-shift

To calculate the performance score, we can apply the weighted average score to each metric score. The calculator can be checked for Weighting.
However I donā€™t pass through this error :
var speedIndex = JSON.stringify(jsonData.lighthouseResult[ā€˜speed-indexā€™][ā€˜scoreā€™]);
There is a error in postman while trying to access each metric score.
Can someone help ?

Hi i have done the Day 28 challenge i couldnā€™t find out the performance score ranges from 90 -100 rather i could see categories-performance-score = 1.is that one is right one we need to check ?

pm.test(ā€œYour test nameā€, function () {

var jsonData = pm.response.json();

 score=jsonData.lighthouseResult.categories.performance.score;



console.log(score);

if (score<=1)

{

pm.test('The score lies between 0 and 1', function() {

    // check here

});

} else {

pm.test('the score is greater than 1', function() {

    // check here

});

}

// pm.expect(jsonData.score).to.eql(0.98);

});
When i execute the script its passes whether my script is right or wrong whether i need to consider different metric score can anyone suggest me thank you very much .