-
Notifications
You must be signed in to change notification settings - Fork 11
[Use case] Asserting Page Load time
This use case describes the scenario of running functional UI tests of webpages, collecting navigation timing and asserting the PageLoad time (plt).
Assuming you already have the timings API up and running, you have installed and configured the timings client, you can now call the API from within your functional test script(s). This example is based on Python. For other clients, refer to the installation pages.
-
Grab the "inject" code from the API
/v2/api/cicd/injectjs
INJECT_CODE = PERF.injectjs(inject_type="navtiming", mark="visual_complete", strip_qs=True)
-
Execute the JavaScript from step 2 in the browser/webdriver
TIMING = BROWSER.execute_script(INJECT_CODE)
-
Set the API parameters
API_PARAMS = PERF.getapiparams(sla={"pageLoadTime": 3000})
Note that you can overwrite the default config values here! The sample config file has a pageLoadTime SLA of
2000
but using the.getapiparams()
function, we can set it to another value just for a particular test case.See the values that you can set:
- for the python client (
.getapiparams()
): https://github.com/godaddy/timings-client-py#client-methods - for the JavaScript client (
.getApiParams()
): https://github.com/godaddy/timings-client-js#client-methods
- for the python client (
-
Send the timing data and API parameters to the API endpoint
API_RESP = PERF.navtiming(TIMING, API_PARAMS)
-
Analyze the result Use the
assert
field in the API's response. This field tells you if the "measured" pageLoadTime was higher (=False) or lower (=True) than the SLA. You can use your preferred assertion method to pass/fail the test.
Example API response:
{
"status": 200,
"api_version": "1.1.3",
"assert": true,
"route": "navtiming",
"esSaved": "ElasticSearch is not available or 'flags.esCreate=false'!",
"export": {
"et": "2018-01-05T18:03:52.418Z",
"@timestamp": "2018-01-05T18:03:52.418Z",
"status": "pass",
"@_uuid": "38ec95e5-5dd3-4b93-b2a4-a4d1cdb6d6c5",
"dl": "www.test-godaddy.com/",
"perf": {
"flatSLA": 3000,
"measured": 830,
"baseline": 0,
"threshold": 3000,
"visualComplete": 1734
},
"info": {
"ranBaseline": false,
"usedBaseline": false,
"assertMetric": "pageLoadTime",
"api_took": 0,
"api_version": "1.1.3",
"hasResources": true
},
"log": {
"team": "Sample team",
"test_info": "Sample App (navtiming)",
"env_tester": "test",
"browser": "chrome",
"env_target": "prod"
},
"flags": {
"assertBaseline": true,
"debug": false,
"esTrace": false,
"esCreate": false,
"passOnFailedAssert": false
},
"baseline": {
"days": 7,
"perc": 75,
"padding": 1.2
},
"nav": {
"loadEventStart": 830,
"domComplete": 829,
"domInteractive": 777,
"firstByteTime": 130,
"dnsTime": 0,
"redirectTime": 0,
"connectTime": 14,
"processingTime": 57
}
}
}
- Installation
- General info
- Use cases