Hi,
Is it possible to customize locators by script in Katalon Studio? Something like Extension Scripts in Katalon Recorder.
We have thousands of Test object with dynamic ids and select the different locator(based on attribute name on parent element) for each one manually will take too much effort.
Thank you,
Tomas
Quoting from Is there a method to create an Object in the Object Repository using Groovy
You do not necessarily create thousands of Test object in the Object Repository
. You can create a TestObject ‘on the fly’ using the following example:
TestObject to = new TestObject(“dynamic”)
to.addProperty(“xpath”, ConditionType.EQUALS, XPath expression)
In the 3rd argument as XPath expression, you give a String which you can generate whatever you like by your code.
Also you can parameterize the Test Objects. That feature would help reducing your coding effort. See
I think you are likely going to have to investigate each element manually to ensure you have a valid pathway to it that does not include any dynamic attributes. However, the time you put into automating means reducing the repetitive task of manual testing–for every release. Let your Manager decide if checking the element’s pathway manually it too expensive–but yeah, it does take time (with 5,100 elements and going
).
Another idea you can also use is a modified Katalon Studio/Selenium style, such as:
WebDriver driver = DriverFactory.getWebDriver()
"check if required field"
pLabel = driver.findElement(By.xpath('id("RequiredField")/../preceding-sibling::div/label'))
WebUI.verifyMatch(pLabel.getAttribute('class'), 'required', false)
"check button response"
pItem = driver.findElement(By.xpath('//input[@id="RequiredField" and @value="True"]'));
WebUI.verifyMatch(pItem.isSelected().toString(), "false", false)
pItem.click();
WebUI.verifyMatch(pItem.isSelected().toString(), "true", false)
But with compare with one “click” is it still too much effort. There is no way, how to prioritize locators or just to create one from the DOM element?