I need help in katalon studio case 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. 15th 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) ))
{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'))
}
}
You are using WebUI.verifyElementNotPresent(). Calling verifyElementNotPresent makes your script fragile in case that the target web pages responds slowly. If the response is slow (e.g. 3 second), your call to WebUI.verifyElementNotPresent() would quickly return true. You should use WebUI.verifyElementNotPresent() only when you are 100% sure that the element will be found in the page at the first iteration and you expect it to disappear after a few iteration. I suppose this scenario is not what you have in mind.
Your problem can be restated:
Wait for the element ‘Page_Quick Inbound/input_Bad_quantity’ to be found; If it is found then the script do something … , otherwise the script skip the current iteration and continue with the next iteration.
You can implement it using WebUI.verifyElementPresent(). Your script would be as such:
@Mate Mrse and @4280-kazurayam Thanks been trying all possibilities for last 48 hrs. I am not a coder but putting my sincere effort to get this automated. Did try the below as said and got error. Let me know what to be changed.
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(4)
def timeout = 3
if (WebUI.verifyElementPresent(
findTestObject('Page_Quick Inbound/input_Bad_quantity',timeout, FailureHandling.OPTIONAL) ))
{
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'))
} else
{
continue
}
}
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, 3, OPTIONAL]
@4280-kazurayam & @Gerard van der Winkel Thanks I had achieved it using finding text in element ,
WebUI.navigateToUrl('https://www.amazon.in/')
WebUI.setText(findTestObject('Object Repository/Page_Amazon Sign In/input_Email or mobile phone nu'), 'ABC@XYZ.COM')
WebUI.setEncryptedText(findTestObject('Object Repository/Page_Amazon Sign In/input_Forgot Password_password'),
'ABC')
WebUI.click(findTestObject('Object Repository/Page_Amazon Sign In/input_Enter your password_reme'))
WebUI.click(findTestObject('Object Repository/Page_Amazon Sign In/input_Enter your password_sign'))
WebUI.click(findTestObject('Object Repository/Page_Two-Step Verification/span_Text me at my number endi'))
WebUI.click(findTestObject('Object Repository/Page_Two-Step Verification/input_Call me at my number end'))
WebUI.delay(15)
WebUI.click(findTestObject('Object Repository/Page_Orders/i_Orders_was-inventory-icon'))
WebUI.click(findTestObject('Object Repository/Page_Orders/i_Load More_was-receive-and-st'))
WebUI.setText(findTestObject('Page_Quick Inbound/input_Scan or Search Shipment'), '121W22HM')
Robot rb = new Robot()
rb.keyPress(KeyEvent.VK_ENTER)
WebUI.delay(1)
rb.keyRelease(KeyEvent.VK_ENTER)
WebUI.delay(5)
for (def row = 1; row <= findTestData('Ship Plan Data').getRowNumbers(); row++) {
WebUI.waitForElementPresent(findTestObject('Page_Quick Inbound/input_Scan or type SKU_itemId'), 10)
WebUI.delay(4)
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(4)
if (WebUI.verifyElementText(findTestObject('Object Repository/Page_Quick Inbound/div_Please update the dimensio'), 'Please update the dimensions of the product and try again',
FailureHandling.CONTINUE_ON_FAILURE) == true) {
continue
} else {
WebUI.waitForElementPresent(findTestObject('Page_Quick Inbound/input_Bad_quantity'), 20)
WebUI.delay(4)
WebUI.setText(findTestObject('Page_Quick Inbound/input_Bad_quantity'), findTestData('Ship Plan Data').getValue('Quantity',
row))
WebUI.delay(1)
rb.keyPress(KeyEvent.VK_ENTER)
WebUI.delay(2)
rb.keyRelease(KeyEvent.VK_ENTER)
WebUI.delay(5)
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'))
}
}
Now I need to exit for loop if the page title is matched for that I have tried the below code
title = WebUI.getWindowTitle()
WebUI.verifyMatch(title, 'Amazon Sign In', true)
plan to put this below the for statement and don’t know how to exit the for loop but it should continue from the iteration where it left. This is because this website throws me out and brings sign in page. Hence need to sign in again and continue iteration
Sign In
....
for ( loop) {
title = WebUI.getWindowTitle()
def result = WebUI.verifyMatch(title, 'Amazon Sign In', true)
if (result) {
// It should go to sigin in step and
move to else part and it should continue the iteration where it left
} else {
.....
}
....
}
@4280-kazurayam so if the sign in page is found it should sign in and proceed with iteration code which is present in else part, can duplicate the signin part in title match condition but how to proceed in with sequence continuation
Could you take a screenshot of the TestObject definition of ‘Page_Quick Inbound/input_Bad_quantity’?
And also we need to see HTML fragment around the element which ‘Page_Quick Inbound/input_Bad_quantity’ is targeted to.
@4280-kazurayam hope this is the one which you had asked. the “0” box is the Page_Quick Inbound/input_Bad_quantity I guess all these are hidden and enabled at we proceed. It that the reason I was not successful with VerifyElementPresent. sharing you another screen shot where the qty box is not present.
Thank you for providing screenshots. But I am afraid I am lost.
Your previsous comment makes me confused:
Now I need to exit for loop if the page title is matched for that I have tried the below code
title = WebUI.getWindowTitle()
WebUI.verifyMatch(title, ‘Amazon Sign In’, true)
plan to put this **below the for statement**
What do I mean?
I would see the following code sequence reasonable:
WebUI.navigateToUrl('https://www.amazon.in/')def title = WebUI.getWindowTitle()if (WebUI.verifyMatch(title, 'Amazon Sign In'), true) { // login processing if necessary}...for (def row = 1; row <= findTestData('Ship Plan Data').getRowNumbers(); row++) { // do something for each entry of the Ship Plan Data}
But the following code sequence seems to be a riddle for me:
WebUI.navigateToUrl('https://www.amazon.in/')...for (def row = 1; row <= findTestData('Ship Plan Data').getRowNumbers(); row++) { def title = WebUI.getWindowTitle() if (WebUI.verifyMatch(title, 'Amazon Sign In'), true) { // login processing } // do something for each entry of the Ship Plan Data}
You said you “plan to put this below the for statement”, which would mean you want the latter code sequence… I am lost.
After sign for the first time then ship plan iteration begins.The website throws a sign in page in suddenly hence wanted to sign-in again and then continue with iteration let’s say after 100 th ( indicativei) iteration it shows a sign in page,we need to sigin and then proceed with 101 record of iteration
Then the latter script is what you want, isn’t it?
WebUI.navigateToUrl('https://www.amazon.in/')...for (def row = 1; row <= findTestData('Ship Plan Data').getRowNumbers(); row++) { def title = WebUI.getWindowTitle() if (WebUI.verifyMatch(title, 'Amazon Sign In'), true) { // login processing if necessary } // do something for each entry of the Ship Plan Data}
In Katalon Studio 7.0.0, we have already fixed the bug that caused the verifyElementPresent() and verifyElementNotPresent() keywords to throw an exception instead of returning false when the verified elements do not exist.
Please first check out the release note and click here to download if you want to try version 7.0.0 (beta) in advance.