How to exclude attribute(s) from object name (Web)

Last edited on

Overview

Squish generates object name during the recording process.
However for various reasons, sometimes there might be a need to exclude some attribute(s) during the object name generation process.
Here we will show you some of the ways to do that.
NOTE: This information is specifically for Squish for Web.

How to exclude "id" attribute from object name

Excluding "id" attribute while Squish generates object name.

This is possible by editing the "IncludeIdPropertyInGeneratedNames" entry from "true" to "false".
This entry can be found under the path "\etc\webwrapper.ini" of the Squish installtion directory.

For instance following is an example of editing the "IncludeIdPropertyInGeneratedNames".

Object Name Before:

test_or2sqjv_text = {"container": test_BrowserTab, "id": "or2sqjv", "name": "or2sqjv", "tagName": "INPUT", "type": "text", "visible": True}
test_or2sqk1_password = {"container": test_BrowserTab, "id": "or2sqk1", "name": "or2sqk1", "tagName": "INPUT", "type": "password", "visible": True}

Object Name After:

test_or2sqjv_text = {"container": test_BrowserTab, "name": "or2sqjv", "tagName": "INPUT", "type": "text", "visible": True}
test_or2sqk1_password = {"container": test_BrowserTab, "name": "or2sqk1", "tagName": "INPUT", "type": "password", "visible": True}

How to exclude "name" attribute from object name

Excluding "name" attribute while Squish generates object name.
NOTE: The same concept can be applied for other attributes of your need.

This is possible by creating a custom extension. And the steps are as follows:

  1. Create Javascript file (ex: myextension.js) under the path "lib/extensions/web" which is located on the Squish installation path.
  2. Create a custom function (ex: myUiExtension.nameOf) which invokes "Squish.nameOf".
    "Squish.nameOf" returns the real (multi-property) name of the given element in String format.
    https://doc.qt.io/squish/web-squish-object.html#string-squish-nameof-objectorname
  3. By using String manipulation and regular expression, remove the "name" attribute and its associated value, and return the result from the custom function.
  4. Register that custom function to "Squish.addNameOfHook". https://doc.qt.io/squish/web-squish-object.html#squish-addnameofhook-function

The custom function code looks something like this.

~ snip code ~
var myUiExtension = new Object;
myUiExtension.nameOf = function(obj) {
    if (obj.tagName == "INPUT") {
        var tmp = Squish.nameOf(obj, true); // This returns the real (multi-property) name of the given element in String format. (https://doc.qt.io/squish/web-squish-object.html#string-squish-nameof-objectorname)
        var unEsMsg = unescape(tmp) // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/unescape
                                    // Before "unescape" %7Bvisible%3D%27true%27%20tagName%3D%27INPUT%27%20name%3D%27or2sqjv%27%20type%3D%27text%27%7D
                                    // After  "unescape"  {visible='true' tagName='INPUT' name='or2sqjv' type='text'}
        var result = unEsMsg.replace(/name='[^']+'/, "") // Remove the "name" attribute and associated value 
        return escape(Squish.uniquifyName(result, obj));
    }
    return undefined;
}

Squish.addNameOfHook(myUiExtension.nameOf, true); // Register that custom function to "Squish.addNameOfHook". (https://doc.qt.io/squish/web-squish-object.html#squish-addnameofhook-function)
~ snip code ~
 

For instance following is an example of adding custom extension.

Object Name Before:

test_or2sqjv_text = {"container": test_BrowserTab, "name": "or2sqjv", "tagName": "INPUT", "type": "text", "visible": True}
test_or2sqk1_password = {"container": test_BrowserTab, "name": "or2sqk1", "tagName": "INPUT", "type": "password", "visible": True}

Object Name After:

test_text = {"container": test_BrowserTab, "tagName": "INPUT", "type": "text", "visible": True}
test_password = {"container": test_BrowserTab, "tagName": "INPUT", "type": "password", "visible": True}

For reference attached the test html page and the custom extension file. test.html myextension.js