Hello, i was trying to figure out how to run this but still without success.
It is the web application in travel agency. There is the step where user clicks on button to find out if price is the same or there is a change.
If price is changed - the modal window is displayed - i can click OK/DENY
If price remains the same - the modal window is not displayed, you just continue
I tried this:
if (WebUI.verifyElementVisible(findTestObject(‘Tiger/00-General/03-ModalWindows/ModalWindowConfirmOk’), 0, FailureHandling.CONTINUE_ON_FAILURE)) {
WebUI.click(findTestObject(‘Tiger/00-General/03-ModalWindows/ModalWindowConfirmOk’))
}
I have got the error message that Katalon didnt find object. It seems like it ignores “IF”
or:
if (WebUI.verifyElementPresent(findTestObject(‘Tiger/00-General/03-ModalWindows/ModalWindowConfirmOk’), 5, FailureHandling.CONTINUE_ON_FAILURE) == true) {
WebUI.click(findTestObject(‘Tiger/00-General/03-ModalWindows/ModalWindowConfirmOk’))
}
if (WebUI.verifyElementVisible(findTestObject(‘Tiger/00-General/03-ModalWindows/ModalWindowConfirmOk’), 0, FailureHandling.OPTIONAL)) {
WebUI.click(findTestObject(‘Tiger/00-General/03-ModalWindows/ModalWindowConfirmOk’), FailureHandling.OPTIONAL)
}
It returns this:
01-30-2020 06:13:30 odp. Test Cases/Tiger/PROD/CZCKF/IF OFFER
Elapsed time: 59,866s
Test Cases/Tiger/PROD/CZCKF/IF OFFER FAILED.
Reason:
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementVisible() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject, java.lang.Integer, com.kms.katalon.core.model.FailureHandling) values: [TestObject - ‘Object Repository/Tiger/00-General/03-ModalWindows/ModalWindowConfirmOk’, …]
Possible solutions: verifyElementVisible(com.kms.katalon.core.testobject.TestObject, com.kms.katalon.core.model.FailureHandling), verifyElementVisible(com.kms.katalon.core.testobject.TestObject), verifyElementNotVisible(com.kms.katalon.core.testobject.TestObject, com.kms.katalon.core.model.FailureHandling), verifyElementNotVisible(com.kms.katalon.core.testobject.TestObject)
at IF OFFER.run(IF OFFER:130)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1580404407676.run(TempTestCase1580404407676.groovy:23)
It’s kinda weird you are using “verifyElementVisible” to check if something is visible. I know it’s possible, but just think of it: it is asserting that something is visible. To avoid error, you say: just continue if it’s not visible, so we get the result (false) and put that in an if-statement.
Even when using FailureHandling.OPTIONAL or FailureHandling.CONTINUE_ON_FAILURE, the whole logic seems off. To prevent warnings or whatever in your logs, it would be nicer to convert it into a WebElement and check if it’s displayed:
TestObject to = findTestObject(‘Tiger/00-General/03-ModalWindows/ModalWindowConfirmOk’)
if (WebUiCommonHelper.findWebElement(to, 3).isDisplayed()) {
// yay it's shown!
}
else {
// it's not shown
}
Or of course in a shorter version:
if (WebUiCommonHelper.findWebElement(findTestObject(‘Tiger/00-General/03-ModalWindows/ModalWindowConfirmOk’), 3).isDisplayed()) {
// yay it’s shown!
}
else {
// it’s not shown
}
The logic is sound. People do this kind of thing all the time. What you’re suggesting is to use Selenium to check the visibility, instead of the provided WebUI methods (which is how I would do it too, but that’s not the point). That’s the only difference between your code and his.
When i try with “verify element present” + OPTIONAL:
if (WebUI.verifyElementPresent(findTestObject(‘Tiger/00-General/03-ModalWindows/ModalWindowConfirmOk’), 0, FailureHandling.OPTIONAL)) {
WebUI.click(findTestObject(‘Tiger/00-General/03-ModalWindows/ModalWindowConfirmOk’))
}
It returns two warnings:
01-31-2020 10:12:08 dop. if (verifyElementPresent(findTestObject(“Tiger/00-General/03-ModalWindows/ModalWindowConfirmOk”), 0, OPTIONAL))
Elapsed time: 1m - 18,570s
com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/Tiger/00-General/03-ModalWindows/ModalWindowConfirmOk’ located by ‘By.cssSelector: [data-test-id=‘dialog-messageBox-ok’]’ not found (Root cause: com.kms.katalon.core.exception.StepFailedException: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/Tiger/00-General/03-ModalWindows/ModalWindowConfirmOk’ located by ‘By.cssSelector: [data-test-id=‘dialog-messageBox-ok’]’ not found
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword$_verifyElementPresent_closure1.doCall(VerifyElementPresentKeyword.groovy:85)
at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword$_verifyElementPresent_closure1.call(VerifyElementPresentKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword.verifyElementPresent(VerifyElementPresentKeyword.groovy:92)
at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword.execute(VerifyElementPresentKeyword.groovy:68)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementPresent(WebUiBuiltInKeywords.groovy:1418)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$verifyElementPresent$5.call(Unknown Source)
at IF OFFER.run(IF OFFER:130)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1580461855922.run(TempTestCase1580461855922.groovy:23)
)
And
Unable to find the element located by ‘By.cssSelector: [data-test-id=‘dialog-messageBox-ok’]’. Please recheck the objects properties to make sure the desired element is located.
It seems it it is not able to find this object. However as a common step it works ok.
Is it wrong that it uses CSS selector instead of xpath ?
[data-test-id=‘dialog-messageBox-ok’] - this is the CSS setting inside this object
No, checking something is present, just means it’s present in the html… might be not visible. Visible means present and shown on screen.
Well, if you follow blindy, then it’s fine… if you think of it… and check the code, it will internally also use Seleniums isDisplayed method and if it isn’t displayed, it will call the WebUIKeywordMain.stepFailed function… yes it works, but no, it’s not logically.
I don’t see the problem with this. That’s the entire point of the FailureHandling argument, so that if the user wants to handle the visibility/invisibility of an element themselves, they can.
Again, I agree with you, it’s much cleaner and easier to understand using pure selenium. But that’s not the subject of this topic.
The term and the concept behind visibility is a dense topic (argued much better by more eloquent writers online than yours truly). But if we’re going to get into the weeds here, what we need is an API that, as yet, does not exist. Selenium’s isDisplayed() may come close – I’ll leave you guys to inform me on that.
The problem, as I see it, is one of language. The specific use of certain well-known English terms in the Katalon API bring with them a set of expectations. To most programmers, coming to the Katalon API fresh, something called verifyimplies an assertion. And an assertion implies a potential fail point.
Then, said programmer learns that the API returns a boolean as well – and through its optional latter argument, is allowed to not behave as an assertion.
This annoyed the hell out of me in my early days with this product. But, I’m a big boy and I moved on. “We are where we are”.
Personally, I wrote my own JS function, isVisibleToHumans(). Since then, I wished I’d called it isInteractableByHumans() since it also fails an element that is essentially hidden behind a dimmer div or similar, meaning it is visible, but cannot be reached by the mouse or keyboard. So far, it’s serving me well. But there are rare occasions when it reports an issue that any real human user would not.
That’s a long winded way of saying, I’m with @Brandon_Hein’s pragmatic approach to the thread and his answer to the topic: this is how it is, “we are where we are”. There’s no point in arguing the toss - the toss was made years ago and apart from one odd tweak that broke a ton of existing tests (about 6 months ago? and was then reversed) the API has remained “solid”.