Need to change the script everytime when devloper changes placement of elements

Hello All,
Is there a way to write a test script in Katalon studio once and for all.

Meaning, if the placement of an element is changed on the UI page, the test script should still validate that element on the UI page and tester does not have to change the test script ( or change the x path of an object in object repository residing under Katalon studio)

Thanks in advance.

Regards
Rajeshri

Mostly this can be addressed by identifying right xpaths. Remember, an object can identified with different xpaths, there is no unique one. you will have to identify the correct xpath that is independent of the changes on the applications.
Can you give some sample xpaths? Also, are you working on any ERP application? In house build application.
For inhouse built apps, the best way to address is to have dev guy add an attribute that will remain sam irrespective of the position of the html element on the page

Thanks, Manu for the reply.

Its neither an in-house application nor ERP application.

When I click on that particular object under Object repository folder in katalon studio selection method has 3 different options available as radio-buttons. and the one which is selected is Attributes always.

Do I have to manually go and change it XPath as my selection method ?? here is the sample example of one of the elements :-

image

I will send you an example of xpaths!!

feel like something missing in the screenshot. You can select xpath in the attributes.
This xpath should error out if the position changes.

You will need to be locating the elements in question in the way that suites you but doing it youself, not using the katalon recording tools. This will consist of you creating your own objects and writing your own xpath which you will want to use the relative xpath instead of the absolute, this will allow changes to be made without you having to rewrite, and as Manu said, use attributes that are not going to change. Theres also the option of using CSS to locate the elements.

Katalon published an article which describes how to write a robust XPath against changes in the target HTML design.

https://docs.katalon.com/katalon-studio/tutorials/xpath_katalon_studio_tips.html#xpath-best-practices

For example , it says

XPath Best practices

  1. The very best and ultimate practice is to avoid using absolute Xpaths . Use this only and only when there is no other choice. It works, but it is really hard to maintain – even the smallest change in page’s source code can make Xpath invalid. Sample absolute Xpath in our sample code: /body/div/div/div/button This example does not look so bad, BUT – in feature-rich websites, you may have 15-20 elements between the root element and your object.

This tips applies to you, @rajeshri.zade, doesn’t it? Please read through this artcle. I suppose you can find some tips for your improvements.

Hi Manu,

This is what Katalon studio generates for me when I record the test scenario.
Do you mean I need to explicitly go and change it to XPath always?
Here is the full screen-shot :

Just gonna leave this here…

https://www.guru99.com/page-object-model-pom-page-factory-in-selenium-ultimate-guide.html

Carry on.

1 Like

@rajeshri.zade The selectors generated by Katalon during Spy or Record sessions may not work every time. You would need to edit those to make sure they will work every time otherwise you will have test that doesn’t work every time. There is a great tool available that you can utilize

Here is a similar discussion: Katalon Studio Object Repository AND Spy . There @Russ_Thomas wrote:

A knowledgeable human is much better at building robust, efficient (and therefore successful) selectors. If you use Spy, you will end up having to manage an unwieldy OR (as you’ve already discovered). My advice: Learn CSS selectors and use those to target elements in your tests.

I know Russ prefers CSS Selector to XPath expression. I would translate his words as follows.

Learn XPath expressions by reading some good tutorials (e.g, Guru99 Xpath in Selenium WebDriver: Complete Tutorial ) and write expressions to target elements in your tests manually for yourself. You can use tools (Spy, Recorder of Katalon etc); but you shouldn’t rely on them. Just let them assist you by generating various possible expressions. You can choose one which you think most appropriate among the generated candidates.

1 Like

No changes required in katalon settings. if you are experiencing problems with identifying the object then it all boils down to the xpath or locators you chose to use. Do not rely on katalon to generate the xpaths or locators for you. Many at times for the complex elements it will be incorrect or unstable
With details provided I cannot provide any further assistance.