Is it possible to check for specific value of a javascript var from the webpage?


I wish to check for a specific value of a javascript var of the page. Specifically, I want to retrieve some JSON object set as a global javascript var. I try to use WebUI.executeJavaScript to return the object, but without any success.

So far I try:

WebUI.executeJavaScript("dataLayer", [])
WebUI.executeJavaScript("return dataLayer", [])(I want to check values of the dataLayer object use by Google Tag Manager to automate tagging audit.)

I made a test case as follows:

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUIimport groovy.json.JsonOutputWebUI.openBrowser('')WebUI.navigateToUrl('')WebUI.verifyElementPresent(findTestObject('Object Repository/Page_/a_'), 10)def dataLayer = WebUI.executeJavaScript('return dataLayer;', [])WebUI.comment("dataLayer is ${dataLayer}")def jsonPayload = JsonOutput.toJson(dataLayer)WebUI.comment("jsonPayload is \n${JsonOutput.prettyPrint(jsonPayload)}")WebUI.closeBrowser()

When I ran this: I got following message in the log:

dataLayer is [[gtm.start:1543205695309, gtm.uniqueEventId:0, event:gtm.js], [gtm.uniqueEventId:7, event:gtm.dom], [gtm.start:1543205704058, gtm.uniqueEventId:10, event:gtm.js], [gtm.uniqueEventId:11, event:gtm.load]]
jsonPayload is [    {        "gtm.start": 1543206677602,        "gtm.uniqueEventId": 0,        "event": "gtm.js"    },    {        "gtm.uniqueEventId": 7,        "event": "gtm.dom"    },    {        "gtm.start": 1543206682596,        "gtm.uniqueEventId": 10,        "event": "gtm.js"    },    {        "gtm.uniqueEventId": 11,        "event": "gtm.load"    }]

Is this what you wanted? If not, what is unsatisfactory for you?