Stop test execution

I would like to do the following:

  • fullfill a webform with wrong data
  • press button “Next”, what results in an error being shown
  • if that element is shown (the error), stop the test.

I believe I can detect if the element is shown by using
WebUI.verifyElementVisible(findTestObject(‘Object Repository/CDASSL_Objects/span_ErroDomnioPrincipa’))
But then, I don’t know how to stop test execution. Can you please help me? I tried to close the browser, but I get an error!
Thanks in advance, Mariana

Try this:

import com.kms.katalon.core.util.KeywordUtil
KeywordUtil.markFailedAndStop("Error message is shown, so the test is failed!")

For more info:

For more info:

1 Like

In fact, the command stops the test! :slight_smile:
But I believe I haven’t been very clear: I want to test that the web form doesn’t accept some data. So, I want the test to be marked as passed, if the error message is shown. That is what I don’t now how must be done…


Yes, I have tried that one, but in that case, the browser is not closed and then, if I force it to close, by using:


I get an error, because it tries to proceed with the test and can’t find the fields to fullfill:

09-18-2018 12:29:55 PM - [START] - Start action : Statement - com.kms.katalon.core.util.KeywordUtil.markPassed()

09-18-2018 12:29:55 PM - [PASSED] -

09-18-2018 12:29:55 PM - [END] - End action : Statement - com.kms.katalon.core.util.KeywordUtil.markPassed()

09-18-2018 12:29:55 PM - [START] - Start action : closeBrowser

09-18-2018 12:29:55 PM - [INFO] - Closing browser

09-18-2018 12:29:56 PM - [PASSED] - Browser is closed

09-18-2018 12:29:56 PM - [END] - End action : closeBrowser

09-18-2018 12:29:56 PM - [END] - End action : Statement - If (com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementVisible(com.kms.katalon.core.testobject.ObjectRepository.findTestObject(Object Repository/CDASSL_Objects/span_ErroDomnioPrincipa)))

09-18-2018 12:29:56 PM - [START] - Start action : setText

09-18-2018 12:29:56 PM - [INFO] - Finding Test Object with id ‘Object Repository/CDASSL_Objects/input_name’

09-18-2018 12:29:56 PM - [INFO] - Checking object

09-18-2018 12:29:56 PM - [INFO] - Checking text

09-18-2018 12:29:56 PM - [INFO] - Checking timeout

09-18-2018 12:29:56 PM - [WARNING] - Cannot take screenshot

09-18-2018 12:29:56 PM - [FAILED] - Unable to set text ‘Maria da Silva Guedes’ of object ‘Object Repository/CDASSL_Objects/input_name’ (Root cause: com.kms.katalon.core.webui.exception.BrowserNotOpenedException: Browser is not opened

Well, of course it will do that when you close the browser! :smiley:

Why don’t you just use WebUI.verifyElementVisible(findTestObject(‘Object Repository/CDASSL_Objects/span_ErroDomnioPrincipa’))?

And if the message is present, the script will just continue with the following line. What would you want it to do?

I wanted it to stop the test, marked as passed, because my requirement is: do not be able to fullfill the field with value “X”. So, I’m trying to fullfill the field with value “X” and an error is being shown.
That means the test has been successfull, the web form acted as expected!

1 Like

I am not following. If the error is being shown, why is WebUI.verifyElementVisible() or markPassed() not enough?
That should be the last line of your script, IMO.

I’m trying to run a test suite, which repeats the same test with several lines of data.
My test goes through my web form’s several pages.
The error is shown, when I insert wrong data in a field that is in page 1 and then press button “Next”.
What is happening if I simply insert KeywordUtil.markPassed() is:

  1. Katalon fullfills the first page,

  2. Katalon presses “Next”

  3. The error is shown

  4. The test hangs forever.

What I would like to happen is:

  1. Katalon fullfills the first page,
  2. Katalon presses “Next”
  3. The error is shown
  4. The test is marked as passed
  5. Katalon fullfills the first page with the second line of data.
1 Like

OK, then you need to use some kind of a loop:

for (def i=0; i<number-of-pages; i++){
         .... fill the page and show the error

I’m sorry, I haven’t understood you.

If you want to do basically the same thing (filling the form) multiple times, the best way to do it is by using a programming loop. So, if you want to fill the form 4 times with different data, it would have to look something like this:

for (def i=0; i<3; i++){
        // here go the lines of your code that will be repeated 4 times
        // but I don't know what exactly
        // because that depends on what you are trying to do

Why don’t you just post your script and we’ll see what can be done?

Hi Mariana,

I have the same requirement now,
need to pass and stop the script.

What was ur solution ?


Well is that that hard to implement the solution for passed and stop in the same way like the error is solved? Do you really need the explanation why and what for?

Mariana, you can set a condition in your test script according to the given results and just use return.
It’s not beautiful, but it might be the only way.

I don’t understand why it’s so hard to implement.