For that item, I realized (too late before question was closed) the the answer was not correct.
I need to be able to retrieve the xpath from the Object Repository itself, without finding the object on the page first. How do I retrieve the value of the item’s selection method (xpath in this case) directly from the object repository itself?
The way I understood your concern is that the element was already in your Object Repository. And Katalon Studio supports Java and Groovy coding. The element in your Object Repository is just a file. Get the file, read through the file and either collect all the Key/Value pairs or only the BASIC one. Again, its only an idea of how it can be done, and it can be done as you are running a script. You just need to know some programming and some String manipulation methods. You can probably find most of this on Java / Groovy forums.
I can assume that GetProperty or GetAttribute would work on the web page, not the OR. The xpath you may be trying to find is not “on the web page”, but an artifact that we create to “find” a pathway to the specific element on the web page. Saying that, there may be a number of other ways, but I’m not thinking of it or them yet: Inheritance, Web Element, Test Object inspect properties…
That’s why I was curious to see if there was a function that would allow the retrieval from the object repository element itself. Katalon has to do so in order to run the script, was hoping there was a function that users would be able to tap into
I would disagree with this. Your question was unclear, was not detailed enough.
You want to get a list of Test Object IDs from the Object Repository, right? Once you got the list of Test Object IDs, you can iterate over it to see if each Test Object has the XPath of your interest.
“Katalon Studio API” com.kms.katalon.core.testobject.ObjectRepository provides no method that returns a list of Test Objects contained.
Possibly Katalon developers have never imagined that users sometimes need to “refactor” the Object Repository. The "Recorder " tool tends to generated hundreds or thousands of Test Objects in the Object Repository, which includes a lot of entities unusable and a lot of duplications. Users need a way to find out rubbish Test Objects and clean them out. But Katalon Studio does not provide any feature of refatoring Test Objects. It’s a shame. Possibly Katalon developers never use the Recorder tool and Object Repository for their own sake. Software developers do not necessarily use their products.
How about me?
Well, I personaly rarely use Object Repository. I always construct TestObjects on the fly by code. Therefore I do not have any bulky TestObjects in the Object Repository folder.
So you need to develop a solution for yourself. Grasp the “Object Repository” folder in your project, and get the list of descendant .rs files as Test Objects. If you have layers of sub-folders, you need to visit them all. Possibly you want to study:
to = findTestObject('Object Repository/Sample Test Object')
I was expecting getProperties() or getActiveXpaths() to produce something, but are just empty lists.
2023-02-28 11:54:21.774 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2023-02-28 11:54:21.776 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/SampleTest Case
2023-02-28 11:54:22.158 DEBUG testcase.SampleTest Case - 1: to = findTestObject("Object Repository/Sample Test Object")
2023-02-28 11:54:22.210 DEBUG testcase.SampleTest Case - 2: println(to.getClass())
2023-02-28 11:54:22.220 DEBUG testcase.SampleTest Case - 3: println(to.getProperties())
2023-02-28 11:54:22.222 DEBUG testcase.SampleTest Case - 4: println(to.getActiveXpaths())
2023-02-28 11:54:22.223 DEBUG testcase.SampleTest Case - 5: println(to.getXpaths())
2023-02-28 11:54:22.225 DEBUG testcase.SampleTest Case - 6: println(value)
2023-02-28 11:54:22.239 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/SampleTest Case
so looks like only getXpaths() produce a certain populated list, so I am confused.
Is my testobject wrong or the methods I tried are simply not working?
first guess will be, getProperties retrieves the settings under the Attributes tab, not the actual object properties.
must dig more.
Here’s the context: I have an element that appears on 90% of our pages, but has to be preceded in the xpath mapping by the specific instance of that element (i.e. - there can be more than one of these on the page, so I have to validate each one via a combination of (parent xpath) + (common object’s xpath).
I want to make this as easy to adjust and change in the future as possible, so I have the common element’s xpath stored in the script object repository, and was hoping to be able to retrieve that common xpath value so I could feed it into the (parent xpath) + (common object’s xpath) formula within a new TestObject, this way if the common object’s xpath characteristics (say the id property) were to change at any point in the future I only have to change it in one place instead of 30+ (this object is on a LOT of pages ).
Thus in order to do this optimization, I need to be able to retrieve the xpath selector value directly from the object repository object. I’m new to Katalon, but have used QTP for almost a decade and was able to pull the object properties directly out of the object repository, so am attempting to duplicate this logic here and failing.
UPDATE: I could bury the common object xpath as a variable in an class file somewhere, but I figured it would be easier for others to find and manipulate if I had it in the object repository like everything else. As mentioned, this was fairly easy to do in QTP, so I was assuming it would be the same within Katalon as accessible by a GetXXXX type statement somehow.
Negative, as your query is pulling the xpath from an object on the page already, not from the object repository. You’re assuming that the object on the page can be found via the object repository item, when based on my example it cannot. @bionel is following the logic I need to resolve, in that they are attempting to pull the xpath information directly from the object repository.
Katalon has to be retrieving this information somehow as well, or the object repository wouldn’t work, I’m trying to figure out how Katalon is doing this and duplicate that methodology.