0

I need help in katalon studio groovy script for if else statement. If the element 'Page_Quick Inbound/input_Bad_quantity' is not found then it should skip the current iteration and continue with the next iteration. 12th line in the code I have tried the if statement but it is not working.

for (def row = 1; row <= findTestData('Ship Plan Data').getRowNumbers(); row++) 
    {
                 WebUI.delay(2)
                 WebUI.setText(findTestObject('Page_Quick Inbound/input_Scan or type SKU_itemId'), 
                 findTestData('Ship Plan Data').getValue('fnsku', row))

                 rb.keyPress(KeyEvent.VK_ENTER)
                 WebUI.delay(1)
                 rb.keyRelease(KeyEvent.VK_ENTER)
                 WebUI.delay(2)

        if (WebUI.verifyElementNotPresent(findTestObject('Page_Quick Inbound/input_Bad_quantity',10,FailureHandling.OPTIONAL) )==true)
                        {continue} 
        else{
             WebUI.setText(findTestObject('Page_Quick Inbound/input_Bad_quantity'), findTestData('Ship Plan Data').getValue('Quantity',
                                row))
              rb.keyPress(KeyEvent.VK_ENTER)     
              WebUI.delay(2)
              rb.keyRelease(KeyEvent.VK_ENTER)
              WebUI.delay(3)

              WebUI.setText(findTestObject('Page_Quick Inbound/input_(You can select bin from'), findTestData('Ship Plan Data').getValue(
                                'bin', row))

              rb.keyPress(KeyEvent.VK_ENTER)
              WebUI.delay(2)
              rb.keyRelease(KeyEvent.VK_ENTER)
              WebUI.delay(2)

              WebUI.click(findTestObject('Page_Quick Inbound/button_RECEIVE  STORE'))
             }
    } 
Kanted
  • 169
  • 1
  • 12
  • *verifyElementNotpresent* looks like the P should be capitalized? No idea about the rest. Can you put a println in next to "continue" to see if you're matching? – billjamesdev Sep 16 '18 at 19:03
  • Thanks,did capitalize. the error it throws Test Cases/shipplancase2 FAILED because (of) (Stack trace: groovy.lang.MissingMethodException: No signature of method: Script1536501262795.findTestObject() is applicable for argument types: (java.lang.String, java.lang.Integer, com.kms.katalon.core.model.FailureHandling) values: [Page_Quick Inbound/input_Bad_quantity, 10, OPTIONAL] – Kanted Sep 16 '18 at 19:12
  • Did you link your data file with Katalon (File > New > New Test Data)? – Mate Mrše Sep 17 '18 at 06:22
  • yes, it picks up the values from the file and continues iteration till the object is found. once the object is not found it gives a error – Kanted Sep 17 '18 at 06:54

2 Answers2

0

findTestObject() accepts strings as argument, so the integer and the failure handling need to go.

Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
  • if (WebUI.verifyElementNotPresent(findTestObject('Page_Quick Inbound/input_Bad_quantity') )== true) hope you said this tried no luck – Kanted Sep 17 '18 at 06:55
  • You can keep the timeout and the failure handling, but inside of the verifyElementNotPresent(), not findTestObject(). – Mate Mrše Sep 17 '18 at 06:58
  • You said 'no luck'. But, are you getting the same error message? – Mate Mrše Sep 17 '18 at 07:00
  • Tried this `if (WebUI.verifyElementNotPresent(findTestObject('Page_Quick Inbound/input_Bad_quantity'),10,FailureHandling.OPTIONAL ) ==true ) { continue } else{ ` got this error Test Cases/shipplancase2 FAILED because (of) (Stack trace: com.kms.katalon.core.exception.StepFailedException: Unable to set text '450' of object 'Object Repository/Page_Quick Inbound/input_Bad_quantity' (Root cause: org.openqa.selenium.InvalidElementStateException: invalid element state: Element is not currently interactable and may not be manipulated – Kanted Sep 17 '18 at 09:47
  • The element might be present but not visible or clickable. Try using `WebUI.verifyElementClickable()` or `WebUI.verifyElementVisible()`. – Mate Mrše Sep 17 '18 at 10:29
  • `for (def row = 1; row <= findTestData('Ship Plan Data').getRowNumbers(); row++) { . . if (WebUI.verifyElementNotVisible(findTestObject('Page_Quick Inbound/div_Please update the dimensio'), 5)== true) { steps.... } else {continue} }` else continue should go to for statement and go ahead with next loop it gives a error Test Cases/sample FAILED because (of) (Stack trace: groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementNotVisible() is applicable for argument types: – Kanted Sep 17 '18 at 14:12
  • According to documentation, [verifyElementNotVisible()](https://docs.katalon.com/display/KD/%5BWebUI%5D+Verify+Element+Not+Visible) doesn't have a timeout value. But I'm not sure this is true. Try with notVisibleInViewport. – Mate Mrše Sep 18 '18 at 06:08
0

you have typo in if command:

if (WebUI.verifyElementNotPresent(findTestObject('Page_Quick Inbound/input_Bad_quantity'),10,FailureHandling.OPTIONAL) == true)

finTestObject(),10,FailureHandling

Andrej
  • 111
  • 6