Using "verifyelementnotpresent" interrupt the script

Hello guys, I’m trying to use “verifyelementnotpresent” to interrumpt my testcase.

take a look:

WebUI.verifyTextNotPresent(‘Please, insert a valid e-mail adress.’, false)

if (verifyTextNotPresent == false)
{
KeywordUtil.markError (“Invalid e-mail adress”)

}

when I’m running this message appears in console

est Cases/Cadastro de usuarios personalizados FAILED.
Reason:
groovy.lang.MissingPropertyException: No such property: verifyTextNotPresent for class: Script1578330826082
at Cadastro de usuarios personalizados.run(Cadastro de usuarios personalizados:46)
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:328)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:319)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:298)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:290)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:224)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:97)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1578512816884.run(TempTestCase1578512816884.groovy:22)

What I’m doing wrong?

Try something like…

if(WebUI.verifyTextNotPresent("Please, insert a valid e-mail adress.", false)) {
  KeywordUtil.markError ("Invalid e-mail address")
}

From my expierience this still would Fail…, you would still need to add Failure Handling i think at least…

import com.kms.katalon.core.model.FailureHandling as FailureHandling


if(WebUI.verifyTextNotPresent("Please, insert a valid e-mail adress.", false, FailureHandling.CONTINUE_ON_FAILURE)) {
  KeywordUtil.markError ("Invalid e-mail address")
}

Both of this condicionals worked but when I insert a valid e-mail adress it shows the failure message.

click(findTestObject(“Page_Molde Test/button_Salvar”)) FAILED.
Reason:
com.kms.katalon.core.exception.StepErrorException: Invalid e-mail address
at com.kms.katalon.core.util.KeywordUtil.markError(KeywordUtil.java:64)
at com.kms.katalon.core.util.KeywordUtil$markError.call(Unknown Source)
at Cadastro de usuarios personalizados.run(Cadastro de usuarios personalizados:51)
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:328)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:319)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:298)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:290)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:224)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:97)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1578594170115.run(TempTestCase1578594170115.groovy:22)

What us “it” ? I think we need to see your code, the HTML and the full error.

By the way, make sure your spelling is consistent, if not correct. You’re using both “adress” (wrong) and “address” (correct - two “dd”).

it = the console log.

follow my html code:

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import org.openqa.selenium.Keys as Keys
import com.kms.katalon.core.model.FailureHandling as FailureHandling

WebUI.openBrowser(’’)

WebUI.navigateToUrl(’’)

WebUI.setText(findTestObject(‘Object Repository/Page_Molde Test/input_E-mail_email (2)’), ‘’)

WebUI.setEncryptedText(findTestObject(‘Object Repository/Page_Molde Test/input_Senha_password (1)’), ‘’)

WebUI.click(findTestObject(‘Object Repository/Page_Molde Test/button_Acessar (1)’))

WebUI.click(findTestObject(‘Object Repository/Page_Molde Test/p_Usurios (1)’))

WebUI.click(findTestObject(‘Page_Cad_Usuarios/div_UsurioNome do usurioE-mail’))

WebUI.setText(findTestObject(‘Object Repository/Page_Molde Test/input_Nome do usurio_Fullname (1)’), ‘Katalon’)

WebUI.setText(findTestObject(‘Object Repository/Page_Molde Test/input_E-mail_Email (1) (1)’), ‘thisisainvalidemail-email.com.br’)

WebUI.click(findTestObject(‘Object Repository/Page_Molde Test/div_E-mail’))

WebUI.verifyTextNotPresent(‘Por favor insira um endereço de e-mail válido.’, false)

if(WebUI.verifyTextNotPresent(“Por favor insira um endereço de e-mail válido.”, false)) {
KeywordUtil.markError (“O endereço de e-mail inserido é inválido”)
}

WebUI.setEncryptedText(findTestObject(‘Object Repository/Page_Molde Test/input_Senha de acesso_Password (1)’), ‘’)

WebUI.setEncryptedText(findTestObject(‘Object Repository/Page_Molde Test/input_Confirmao de senha_Passw (1)’), ‘=’)

WebUI.selectOptionByValue(findTestObject(‘Object Repository/Page_Molde Test/select_-- Selecione --Administ (1)’), ‘1’, true)

WebUI.click(findTestObject(‘Object Repository/Page_Molde Test/label_Ativo (1)’))

WebUI.click(findTestObject(‘Page_Molde Test/button_Salvar’))

I already put the all error message before.

Remove the first line and use

if(WebUI.verifyTextPresent("Por favor insira um endereço de e-mail válido.", false, FailureHandling.CONTINUE_ON_FAILURE))

It didn’t work. I used a valid email and the console showed the error message :frowning:

01-13-2020 01:04:28 PM click(findTestObject(“Page_Molde Test/button_Salvar”))

Elapsed time: 2,173s

click(findTestObject(“Page_Molde Test/button_Salvar”)) FAILED.
Reason:
com.kms.katalon.core.exception.StepErrorException: Invalid e-mail address
at com.kms.katalon.core.util.KeywordUtil.markError(KeywordUtil.java:64)
at com.kms.katalon.core.util.KeywordUtil$markError.call(Unknown Source)
at Cadastro de usuarios personalizados.run(Cadastro de usuarios personalizados:52)
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:328)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:319)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:298)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:290)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:224)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:97)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1578931395082.run(TempTestCase1578931395082.groovy:22)

You are probably missing a import at the beginning:

import com.kms.katalon.core.model.FailureHandling as FailureHandling

Try adding it and then rerun

Use

if(WebUI.verifyTextPresent('Por favor insira um endereço de e-mail válido.', false, FailureHandling.OPTIONAL)){
    KeywordUtil.markError('Error message')
}
else{
    WebUI.setEncryptedText(findTestObject('Page_Molde Test/input_Confirmao de senha_Passw (1)'), '=')
    WebUI.selectOptionByValue(findTestObject('Page_Molde Test/select_-- Selecione --Administ (1)'), '1', true)
    WebUI.click(findTestObject('Page_Molde Test/label_Ativo (1)'))
    WebUI.click(findTestObject('Page_Molde Test/button_Salvar'))
}

Sorry guys for take too long to answer you.
I tried this and worked for me, not way I expected but it helps for now.

if (WebUI.verifyTextPresent(‘Por favor insira um endereço de e-mail válido’, true, FailureHandling.OPTIONAL)) {

WebUI.setText(findTestObject(‘Object Repository/Page_Molde Test/input_E-mail_Email (1) (1)’), ‘katalon@appsmold.com.br’)
WebUI.click(findTestObject(‘Page_Molde Test/button_Salvar’))

I apreciate your time to help me to resolve this “problem”.

Just as an FYI, the three failure handling args have different results in the event of a failure. From the documentation:

/**
 * Enum for flow control for test execution
 * <p>
 * - <b>STOP_ON_FAILURE</b>: stop execution when errors or fail cases happened
 * <p>
 * - <b>CONTINUE_ON_FAILURE</b>: continue execution when errors or fail cases happened
 * <p>
 * - <b>OPTIONAL</b>: continue execution when errors or fail cases happened and not marking tests as failed
 */

So basically STOP_ON_FAILURE (which is the default) will stop execution and mark the test as failed, CONTINUE_ON_FAILURE will continue execution and mark the test as failed, and OPTIONAL will continue execution and will NOT mark the test as failed.

By rereading the first post, if you just want to interrupt the testcase, you can use

if(WebUI.verifyTextPresent('Por favor insira um endereço de e-mail válido.', false, FailureHandling.OPTIONAL)){ 
      KeywordUtil.markErrorAndStop('Error message') 
}

See KeywordUtil javadoc for all methods