Is there a way to Mass-Edit many objects in the object repository?

I’ve discovered that in web app, Katalon has issues detecting some objects because of them having dynamic ID’s.

However, I’ve found a easy solution by forcing all the objects to be located by class.

Is there a way to change every object to be only found by class, instead of doing this one by one?

It’s not that i’m lazy, but I don’t want to go through 2000 objects…

Andrew,

yes and no. It is pretty complex problem, but can be solved under few conditions:

1. You have to know, which object you want to replace
2. When you have a list of objects, you have to know, which selectors you wanna use and what values there should be

I can see this solution:
- get list of files for your objects (Object Repository folder in Katalon project) - easy
- parse XML file and get only those object which you want to change - also quite easy
- change those files (test objects) - and this becomes a problem - how do you know which selector value is going to be used for particular object?

Marek Melocik said:

Andrew,

yes and no. It is pretty complex problem, but can be solved under few conditions:

1. You have to know, which object you want to replace
2. When you have a list of objects, you have to know, which selectors you wanna use and what values there should be

I can see this solution:
- get list of files for your objects (Object Repository folder in Katalon project) - easy
- parse XML file and get only those object which you want to change - also quite easy
- change those files (test objects) - and this becomes a problem - how do you know which selector value is going to be used for particular object?

1. So, Pretty much every available object.

2. The only selectors I need is Tag, and Class.

I was hoping there was a way to do it from with in Katalon.

I am afraid there is nothing like this in Katalon. The main problem is to put correct selector to each object. And it is really hard to automate.

1 Like

is there a way to export objects into csv format, and import back in via csv?

Test objects are stored as XML object and you can’t simply convert them to CSV. It has specific structure and the only thing you can do is to edit XML file (then, you don’t need to export/import). This is sample test object:

<WebElementEntity>   <description></description>   <name>testobject123</name>   <tag></tag>   <elementGuidId>81487eba-bcb3-4054-9760-900fb23b883a</elementGuidId>   <selectorCollection>      <entry>         <key>BASIC</key>         <value></value>      </entry>   </selectorCollection>   <selectorMethod>BASIC</selectorMethod>   <useRalativeImagePath>false</useRalativeImagePath>   <webElementProperties>      <isSelected>true</isSelected>      <matchCondition>equals</matchCondition>      <name>class</name>      <type>Main</type>      <value>xxx</value>   </webElementProperties></WebElementEntity>

And you want to change _WebElementEntity -> _webElementProperties like name and value.

one by one it is…

andrew,

2000 xml files, …

I would be able to write a tool project which you can start in a single line in console.
> gradlew go
The script will be built on top of Gradle, it drives XSLT, it transforms your 2000 xml files in a minute.

In order to develop an appropriate XSLT stylesheet I need a example input (xml, a Test Object definition) and desired output. I need to see which nodes to be discarded, which nodes to be retained. Please paste a pair of input/output XML codes here. If you have groups of input files (one to be processed and others not to be processed) please specify the grouping criteria if possible by the pattern of file names etc.

I have made a set of code. It seems I have got success transforming Test Object XML files (*.rs) by XSLT retaining <webElementProperties[name=‘css’] and discarding other .

Developing the codes was a fun — 3 files, 80 lines in total. But I have not written description how to use it. I will write it later.

I am a bit concerned. I used XSLT for implementing XML transformation. I am well-trained for XSLT. But other people (including you, andrew) would not know XSLT at all. My code might not be so much helpful for those who lack XSLT skill.

Andrew,

you wrote:

1. So, Pretty much every available object.
2. The only selectors I need is Tag, and Class.

However, can you make 100% sure that all of your Test Objects have appropriate Tag and Class defined?

If any of them lacks Tag and Class, you need to work out manually implementing ‘tag’ and ‘class’ for them one by one. My tool can not help in this intellectual part.

I would write a Test Case in Katalon Studio. Namely ‘Object Repository Verifier’.

The ObjectRepositoryVerifier will scan all the *.rs files in the Object Repository directory, and verify each with the following criteria:

(1) A Test Object (a document) should contain a with its child node tag and its child node true

(2) A Test Object should contain a with a child node class and its child node true

This ObjectRepositoryVerifier will enable you, andrew, to distinguish Test Objects which are “Not Ready for Batch Transformation”.

I would implement the code using the javax.xml.xpath.* package built-in the JDK.

kazurayam said:

I would write a Test Case in Katalon Studio. Namely ‘Object Repository Verifier’.

The ObjectRepositoryVerifier will scan all the *.rs files in the Object Repository directory, and verify each with the following criteria:

(1) A Test Object (a document) should contain a with its child node tag and its child node true

(2) A Test Object should contain a with a child node class and its child node true

This ObjectRepositoryVerifier will enable you, andrew, to distinguish Test Objects which are “Not Ready for Batch Transformation”.

I would implement the code using the javax.xml.xpath.* package built-in the JDK.

Thanks for your help, but by the time i’m done with all of those steps, I would also be done doing each individual one by one.

Considering I’ve already started yesterday, I only have about 1,750 to go.

Group-edit should be built into Katalon at some point.

OK then.

Here I paste my test case named “Object Repository Verifier” for reference. This test case checks all of the Test Objects in the Object Repository directory to make sure a test object is assigned `BASIC` method, has a `tag` selector, a `class` selector defined and selected.

This test case applies the following 2 XPath expressions against each *.rs files in the Object Repository directory.

'/WebElementEntity/webElementProperties[name="tag" and isSelected="true"]','/WebElementEntity/webElementProperties[name="class" and isSelected="true"]' 

The test counts the number of xpath evaluations to false. If this test case fails, there must be one or more test object which lacks `tag` or `class` selector.

import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.util.stream.Collectors
import javax.xml.parsers.DocumentBuilder
import javax.xml.parsers.DocumentBuilderFactory
import javax.xml.xpath.XPath
import javax.xml.xpath.XPathConstants
import javax.xml.xpath.XPathFactory
import org.w3c.dom.Document
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.logging.KeywordLogger
import com.kms.katalon.core.util.KeywordUtil

KeywordLogger logger = new KeywordLogger()
XPath xpath = XPathFactory.newInstance().newXPath()
List<String> expressions = [
    '/WebElementEntity/webElementProperties[name="tag" and isSelected="true"]',
    '/WebElementEntity/webElementProperties[name="class" and isSelected="true"]'
]
Path objectRepository = Paths.get('Object Repository')
List<Path> rsFiles = Files.walk(objectRepository)
    .filter {p -> Files.isRegularFile(p)}
    .filter {p -> p.toString().endsWith('.rs')}
    .collect(Collectors.toList())
def failureCount = 0DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance()for (Path p : rsFiles) {
    DocumentBuilder db = dbf.newDocumentBuilder()
    Document doc = db.parse(p.toFile())
    String name = (String)xpath.evaluate("/WebElementEntity/name", doc, XPathConstants.STRING)
    Boolean isBasic = (Boolean)xpath.evaluate('/WebElementEntity/selectorMethod[. = "BASIC"]', doc, XPathConstants.BOOLEAN)
    if (isBasic) {
        for (String expr : expressions) {
            Boolean result = (Boolean)xpath.evaluate(expr, doc, XPathConstants.BOOLEAN)
            if (!result) {
                logger.logFailed("FAILURE ${p} against XPath \"${expr}\"")
                failureCount += 1	
            }
        }
    }
}
if (failureCount > 0) {
    KeywordUtil.markFailed("${failureCount} failures")
}

I have created another post:

There I explained ‘Teset Cases/ObjectRepositoryTransformer’ which transformes mass of Test Objects (*.rs files) using XSLT.

1 Like