Validation script

Hi! I’m newbie of Katalon also their code.

I’m confused to make some script to validation some element. Hope anybody help me.

So, I’m wanna make validation for text ‘minimum 1 pcs’ with the number of items in the box ‘kuantiti’. I’m confused how to make the validation. Or anybody have other ways, can share them with me.

The only idea that I have is to parse out the “1” of the label and then use WebUI.greaterThanOrEqual(). I would start with using getAttribute() to get the value of the Kuantiti textbox:

kuantitiAmt = WebUI.getAttribute(findTestObject('kuantiti textbox'), "value")

Then, you likely have to get the label and parse out the “1” of the “1 pcs”.

pieceCounter = WebUI.getText(findTestObject('minimumLabel').split(':')[1].trim().substring(0,1)
WebUI.greaterThanOrEqual(kuantitiAmt as int, pieceCounter as int)

Edit: This assumes the label is 1 element and not 2 elements; “Minimum” being one and “1 pcs” being the other. You will have to get back to us if it is 2 elements or don’t use the “split(‘:’)”.

Hi! Thank u so much for your help but I’m sorry I don’t get the point here.

so here the script

kuantitiAmt = WebUI.getAttribute(findTestObject(‘Object Repository/Pesanan/text_Minimum 1 pcs’), ‘1’)

pieceCounter = WebUI.getText((findTestObject(‘Object Repository/Pesanan/Box Qty’).split(‘:’)[1]).trim().substring(0, 1))

WebUI.GreaterThanOrEqual(((kuantitiAmt) as int), ((pieceCounter) as int))

I get error when they run start from kuantitiAmt = WebUI.getAttribute(findTestObject(‘Object Repository/Pesanan/text_Minimum 1 pcs’), ‘1’)

Then here the containt of the elemet

text_Minimum 1 pcs

xpath=//div[@id=‘headlessui-tabs-panel-18’]/div/div/div/div/div[3]/span

Box Qty

xpath=//input[@value=‘1’]

You have reversed the elements that I used in my post above. The “kuantitiAmt” was supposed to be the textbox that displayed the 2 in your image above.

The label (span) element is the other item, that I called “pieceCounter”.

There is no value attribute of the span. So, your code will not work. There is a value attribute of the textbox; you are using it to find the textbox. Fix these two areas and try again…

Edit: Just a note that I think using the value attribute of the textbox is spurious because if you change it, then the element cannot be identified with your pathway.