How to check element status in conditional statement?


This is a companion discussion topic for the original entry at https://docs.katalon.com/katalon-studio/docs/how_to_check_element_status_in_conditional_statement.html

Katalon should consider the following use case: 1) an element is not present and 2) that’s okay. Don’t fail the test case. .Optional still fails the test case. At a glance the progress-bar is red, there are 2 giant red X’s on the step and test cases, all because the webpage is working normally. This is not acceptable. You need a FailureHandling.DO_NOT_THROW_ERROR option I suppose.

Or I could just drop down to Selenium’s objects… but then why am I using Katalon?

hello,
ok great to be able to check if an element is visible or not without failing the test.

But how to code it in order to avoid any unwanted stacktrace in my console ?

Here is an example with my code :

int cpt = 0

while ((cpt < 10) && WebUI.verifyElementPresent(findTestObject(‘Object Repository/Authentification/Page_Reflex - QCSGERFX023/img_R’),
1, FailureHandling.OPTIONAL)) {
WebUI.doubleClick(findTestObject(‘Object Repository/Authentification/Page_Reflex - QCSGERFX023/img_R’))
cpt++
}

it produces this huge message in console which is too verbose for me :

[2020-07-27T10:36:01.521] 2020-07-27 10:36:01.520 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
[2020-07-27T10:36:01.521] 2020-07-27 10:36:01.520 INFO c.k.katalon.core.main.TestCaseExecutor - CALL Test Cases/Common Test Cases/Fermeture des fenetres ouvertes
[2020-07-27T10:36:01.523] 2020-07-27 10:36:01.523 DEBUG t.Fermeture des fenetres ouvertes - 1: cpt = 0
[2020-07-27T10:36:01.524] 2020-07-27 10:36:01.524 DEBUG t.Fermeture des fenetres ouvertes - 2: while (cpt < 10 && verifyElementPresent(findTestObject(“Object Repository/Authentification/Page_Reflex - QCSGERFX023/img_R”), 1, OPTIONAL))
[2020-07-27T10:36:03.057] 2020-07-27 10:36:03.056 INFO c.k.k.c.webui.common.WebUiCommonHelper - Unable to find the element located by ‘By.xpath: //div[contains(@class,‘dijitDialog’)][not(contains(@class,“a-windowNotVisible”))][not(@class=“dijitDialogDisabledMask”)][not(contains(@style,“hidden”))][last()]//span[contains(@id,’_SYSMNU_ITEM_text’)][@id!=“RFXDEM-ID_FEN_PRINC-1-_SYSMNU_ITEM_text”]/img’. Please recheck the objects properties to make sure the desired element is located.
[2020-07-27T10:36:03.447] 2020-07-27 10:36:03.446 WARN c.k.k.core.keyword.internal.KeywordMain - com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/Authentification/Page_Reflex - QCSGERFX023/img_R’ located by ‘By.xpath: //div[contains(@class,‘dijitDialog’)][not(contains(@class,“a-windowNotVisible”))][not(@class=“dijitDialogDisabledMask”)][not(contains(@style,“hidden”))][last()]//span[contains(@id,’_SYSMNU_ITEM_text’)][@id!=“RFXDEM-ID_FEN_PRINC-1-_SYSMNU_ITEM_text”]/img’ not found (Root cause: com.kms.katalon.core.exception.StepFailedException: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/Authentification/Page_Reflex - QCSGERFX023/img_R’ located by ‘By.xpath: //div[contains(@class,‘dijitDialog’)][not(contains(@class,“a-windowNotVisible”))][not(@class=“dijitDialogDisabledMask”)][not(contains(@style,“hidden”))][last()]//span[contains(@id,’_SYSMNU_ITEM_text’)][@id!=“RFXDEM-ID_FEN_PRINC-1-_SYSMNU_ITEM_text”]/img’ not found
[2020-07-27T10:36:03.447] at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword$_verifyElementPresent_closure1.doCall(VerifyElementPresentKeyword.groovy:85)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword$_verifyElementPresent_closure1.call(VerifyElementPresentKeyword.groovy)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword.verifyElementPresent(VerifyElementPresentKeyword.groovy:92)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword.execute(VerifyElementPresentKeyword.groovy:68)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementPresent(WebUiBuiltInKeywords.groovy:1444)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$verifyElementPresent$7.call(Unknown Source)
[2020-07-27T10:36:03.447] at Fermeture des fenetres ouvertes.run(Fermeture des fenetres ouvertes:25)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword$_callTestCase_closure1.doCall(CallTestCaseKeyword.groovy:59)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword$_callTestCase_closure1.call(CallTestCaseKeyword.groovy)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:68)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword.callTestCase(CallTestCaseKeyword.groovy:81)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword.execute(CallTestCaseKeyword.groovy:44)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.keyword.BuiltinKeywords.callTestCase(BuiltinKeywords.groovy:334)
[2020-07-27T10:36:03.447] at Authentification si besoin.run(Authentification si besoin:46)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword$_callTestCase_closure1.doCall(CallTestCaseKeyword.groovy:59)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword$_callTestCase_closure1.call(CallTestCaseKeyword.groovy)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:68)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword.callTestCase(CallTestCaseKeyword.groovy:81)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword.execute(CallTestCaseKeyword.groovy:44)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
[2020-07-27T10:36:03.447] at com.kms.katalon.core.keyword.BuiltinKeywords.callTestCase(BuiltinKeywords.groovy:334)
[2020-07-27T10:36:03.448] at Preparation Despatch from stock.run(Preparation Despatch from stock:20)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword$_callTestCase_closure1.doCall(CallTestCaseKeyword.groovy:59)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword$_callTestCase_closure1.call(CallTestCaseKeyword.groovy)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:68)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword.callTestCase(CallTestCaseKeyword.groovy:81)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword.execute(CallTestCaseKeyword.groovy:44)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.keyword.BuiltinKeywords.callTestCase(BuiltinKeywords.groovy:334)
[2020-07-27T10:36:03.448] at DGB - palhomo avec confirmation et sortie de stock.run(DGB - palhomo avec confirmation et sortie de stock:80)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.main.TestSuiteExecutor.accessTestCaseMainPhase(TestSuiteExecutor.java:169)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:142)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:91)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:157)
[2020-07-27T10:36:03.448] at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
[2020-07-27T10:36:03.448] at TempTestSuite1595838665006.run(TempTestSuite1595838665006.groovy:37)
[2020-07-27T10:36:03.448] )
[2020-07-27T10:36:03.448] 2020-07-27 10:36:03.448 INFO c.k.katalon.core.main.TestCaseExecutor - END CALL Test Cases/Common Test Cases/Fermeture des fenetres ouvertes
[2020-07-27T10:36:03.448] 2020-07-27 10:36:03.448 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------