Have been able to implement this successfully for all of the standard measurement timings except one - Cumulative Layout Shift (CLS). The reference calculation can be found at the following link: Cumulative Layout Shift (CLS)
So I have the following code implementation of this logic:
//Calculate Cumulative Layout Shift (CLS)
///Setup Sentry Variable
WebUI.executeJavaScript("""
let clsValue = 0;
let clsEntries = [];
let sessionValue = 0;
let sessionEntries = [];
let CLS = 0;
""", null);
////Start Promise Action
WebUI.executeJavaScript("""
new PerformanceObserver((entryList) => {
for (const entry of entryList.getEntries()) {
// Only count layout shifts without recent user input.
if (!entry.hadRecentInput) {
const firstSessionEntry = sessionEntries[0];
const lastSessionEntry = sessionEntries[sessionEntries.length - 1];
// If the entry occurred less than 1 second after the previous entry and
// less than 5 seconds after the first entry in the session, include the
// entry in the current session. Otherwise, start a new session.
if (sessionValue &&
entry.startTime - lastSessionEntry.startTime < 1000 &&
entry.startTime - firstSessionEntry.startTime < 5000) {
sessionValue += entry.value;
sessionEntries.push(entry);
} else {
sessionValue = entry.value;
sessionEntries = [entry];
}
// If the current session value is larger than the current CLS value,
// update CLS and the entries contributing to it.
if (sessionValue > clsValue) {
clsValue = sessionValue;
clsEntries = sessionEntries;
}
}
}
CLS = clsValue
}).observe({type: 'layout-shift', buffered: true});
""",null);
///Call wait_for_condition function
Common_Functions.wait_for_condition({ return (boolean)WebUI.executeJavaScript("return (CLS > 0)", null)},
10, // or however long you want to wait before failing the test
{ return "Cumulative Layout Shift (CLS) exceeded the wait time."},
)
///Return final CLS Value and display
def cls = WebUI.executeJavaScript("return CLS;", null);
log.logInfo ('Returned amount (CLS)= ' + cls)
yet I’m getting this error, which I’m not getting with the other similar functions:
Unable to execute JavaScript. (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to execute JavaScript.
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.executeJavascript(ExecuteJavascriptKeyword.groovy:42)
at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.execute(ExecuteJavascriptKeyword.groovy:37)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.executeJavaScript(WebUiBuiltInKeywords.groovy:4873)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$executeJavaScript$1.call(Unknown Source)
at Script1675184790214$_run_closure9.doCall(Script1675184790214.groovy:226)
at Script1675184790214$_run_closure9.doCall(Script1675184790214.groovy)
at btt_portal.Common_Functions.wait_for_condition(Common_Functions.groovy:120)
at btt_portal.Common_Functions.wait_for_condition(Common_Functions.groovy)
at btt_portal.Common_Functions$wait_for_condition.call(Unknown Source)
at Browser Console Retrieval Experimentation.run(Browser Console Retrieval Experimentation:226)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:448)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1675267145594.run(TempTestCase1675267145594.groovy:25)
Caused by: org.openqa.selenium.JavascriptException: javascript error: CLS is not defined
(Session info: chrome=109.0.5414.76)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'BTT0247', ip: '192.168.0.100', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_282'
Driver info: com.kms.katalon.selenium.driver.CChromeDriver
Capabilities {acceptInsecureCerts: true, browserName: chrome, browserVersion: 109.0.5414.76, chrome: {chromedriverVersion: 109.0.5414.74 (e7c5703604da..., userDataDir: C:\Users\KEVINJ~1\AppData\L...}, goog:chromeOptions: {debuggerAddress: localhost:64343}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: b15fd01a21fd3c9ddb72f90349194f85
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at com.kms.katalon.selenium.driver.CChromeDriver.execute(CChromeDriver.java:19)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:489)
at org.openqa.selenium.support.events.EventFiringWebDriver.lambda$new$1(EventFiringWebDriver.java:105)
at com.sun.proxy.$Proxy13.executeScript(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver.executeScript(EventFiringWebDriver.java:229)
at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword$_executeJavascript_closure1.doCall(ExecuteJavascriptKeyword.groovy:48)
at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword$_executeJavascript_closure1.call(ExecuteJavascriptKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.executeJavascript(ExecuteJavascriptKeyword.groovy:42)
at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.execute(ExecuteJavascriptKeyword.groovy:37)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.executeJavaScript(WebUiBuiltInKeywords.groovy:4873)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$executeJavaScript$1.call(Unknown Source)
at Script1675184790214$_run_closure9.doCall(Script1675184790214.groovy:226)
at Script1675184790214$_run_closure9.doCall(Script1675184790214.groovy)
at btt_portal.Common_Functions.wait_for_condition(Common_Functions.groovy:120)
at btt_portal.Common_Functions.wait_for_condition(Common_Functions.groovy)
at btt_portal.Common_Functions$wait_for_condition.call(Unknown Source)
at Script1675184790214.run(Script1675184790214.groovy:226)
... 11 more
)
You two have gotten me this far, I’m almost there but can’t for the life of me figure out why this last item is failing when the other metrics ran perfectly. Any thoughts?