I am new to katalon and testing in general. Right now I have to verify if there is some specific words on the screen. I dont want to depend on the specific captured object (because the probability of changing the text location is high), so I thought “maybe there is a way to get all presented text”. So, is there a simple way to do it with katalon functions?
You’re encountering one of the major pain points of UI testing in general - changing screen elements make the tests break. The more you rely on specific text and layouts, the more brittle your UI tests will be.
In my experience, making sure each element has a unique identifier - resource-id on Android and accessibility id (or name, as Appium calls it) on iOS - is key to making tests less brittle. Then, instead of relying on the text to match up, you can make sure that the text element is showing on the screen. This helps to offset changes in the text due to changing requirements or switching language settings.
In Katalon Studio, when you capture a Test Object, it automatically selects the properties of the element that it thinks make the element unique on the screen. These things are often too specific, including the element position within the hierarchy. I usually edit all of my captured Test Objects and uncheck the properties down to the class/type and unique identifier. Sometimes if that’s not enough to make it unique on the screen, I might also turn on the label/text property.
Granted, that’s not as thorough of a check as looking at the whole text, but I would argue that a test that is constantly breaking will quickly be ignored and soon be useless.
To answer your original question, you can get the entire contents of the screen in XML format by using the following code in your test:
AppiumDriver<?> driver = MobileDriverFactory.getDriver()
def wholePage = driver.getPageSource()
Hope this helps,
@Chris_Trevarthen You not only answered my question but also gave me very good tips, thank you very much.