Issue with verifyMatch(actualText, expectedText, isRegex, flowControl)

Bonjour to everyone,
I want to test a website and as a good start to reach this goal, I am thinking about looking for any error message. To find any message of this kind, I use the solution gave at the following link: how to check the existence of text on the entire web page?. Unfortunately, I am facing issue. I am actually able to get an error message when there is one, and this is exactly what I want but when there is none, I have a message on the logInfo and my script stop. I am making my code and the error message I read following. I wonder what I am doing wrong? What would be a fix for this issue? Is verifyMatch returning a boolean? Is it possible to make the test continuing with FailureHandling.CONTINUE_ON_FAILURE, no finding an error message is actually a good point, why not continuing?
That makes a lot of question… sorry… but I am new into the website-testing world and I am using Katalon Studio for only one week. So, in advance thanks for your time and your answer.
Friendly :slight_smile:
ac

P.S.: I am an intern and my studies field is not programmation nor script writing, if you see any mistake or have suggestion for me to improve, let me know. Thanks again

From the error report (shame it’s an image and not the text – it’s en Francais and I can’t translate an image) I am seeing a failed comparison.

From the Test Case, it seems you’re getting the entire document text using xpath: //body.

If my deductions are correct, then you should make a better xpath that returns the text from the HTML element that hosts it.

Hello Russ, thank you so much for your answer. I kept trying while I was waiting for someone answering and there what I got:

-First of all I correct line 57 in my CustomKeyword definition, I forgot the FailureHandling.CONTINUE_ON_FAILURE. That was making my script execution stop.

-Then I decided to change the verifyMatch() into verifyNotMatch(). I think it is a wiser option as I want the test to be ok when I don’t find error message.

I now get right answer from script, it stops when the page is wrong and passes when everything is alright. Or almost. Indeed, even when there is an error message, the script is not running to the end and I don’t get why…
Here follow the new code (as a text :wink: ):

Main script:

import org.assertj.core.util.URLs as URLs
import com.kms.katalon.core.testobject.ConditionType as ConditionType
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI


WebUI.openBrowser('https://www.planning-medical.com/error.php')
TestObject monObjetTest = new TestObject('')
monObjetTest.addProperty('xpath', ConditionType.EQUALS, '//body')
def contenu = WebUI.getText(monObjetTest)
WebUI.comment(contenu)
CustomKeywords.'com.acurnillon.monkatalon.eratum.errorFound'(monObjetTest)
WebUI.comment(String.valueOf(CustomKeywords.'com.acurnillon.monkatalon.eratum.errorFound'(monObjetTest)))
WebUI.closeBrowser()

CustomKeyword definition:

package com.acurnillon.monkatalon
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.annotation.Keyword
import com.kms.katalon.core.checkpoint.Checkpoint
import com.kms.katalon.core.checkpoint.CheckpointFactory
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase
import com.kms.katalon.core.testcase.TestCaseFactory
import com.kms.katalon.core.testdata.TestData
import com.kms.katalon.core.testdata.TestDataFactory
import com.kms.katalon.core.testobject.ObjectRepository
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords

import internal.GlobalVariable

import MobileBuiltInKeywords as Mobile
import WSBuiltInKeywords as WS
import WebUiBuiltInKeywords as WebUI

import org.openqa.selenium.WebElement
import org.openqa.selenium.WebDriver
import org.openqa.selenium.By

import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory
import com.kms.katalon.core.webui.driver.DriverFactory

import com.kms.katalon.core.testobject.RequestObject
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObjectProperty

import com.kms.katalon.core.mobile.helper.MobileElementCommonHelper
import com.kms.katalon.core.util.KeywordUtil

import com.kms.katalon.core.webui.exception.WebElementNotFoundException

import com.kms.katalon.core.util.KeywordUtil


class eratum {
	/**
	 * cherche des messages d'erreurs dans le contenu total de la page
	 */
	@Keyword
	def errorFound(TestObject to) {
		
		def contenu = WebUI.getText(to)
		WebUI.comment(contenu)
		KeywordUtil.logInfo("Recherche d'erreurs")
		if (WebUI.verifyNotMatch(contenu, ".*Fatal error.*", true, FailureHandling.CONTINUE_ON_FAILURE) == false) {
			WebUI.comment("error find")
			KeywordUtil.markErrorAndStop("Erreur(s) détectée(s)")
			return true
		} else {
			WebUI.comment("no error")
			KeywordUtil.markPassed("Aucune erreur détectée")
			return false
		}
	}
}

Log:

07-23-2019 06:14:41 PM com.acurnillon.monkatalon.eratum.errorFound(monObjetTest)

Elapsed time: 0,094s

Unable to verify not match between actual text 'Accueil > Page d'erreur

Aller au menuAller au contenu

Page d'erreur

Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "file:/Users/fabrice/Sites/smarty/planning/templates/fr/error.tpl" on line 35...

Une démo ?

Laissez-nous vous démontrer comment Planning-Medical.com peut vous aider dans la réalisation de vos plannings de gardes ou vos plannings de service.

Nom :

Téléphone :

Adresse e-mail :

Demander une démo

ou bien appelez-nous au

09 721 700 21

Accueil

L’offre

Collaboration

Nous contacter

Accès à l’application

© 2008-2019 - Planning-Medical.com - v1.50 - r19.30 - contact@planning-medical.com

Mentions légales - Nous contacter - On recrute

Application réalisée par K‑Web‑Media' and expected text '.*Fatal error.*' using regular expression (Root cause: com.kms.katalon.core.exception.StepFailedException: Actual text 'Accueil > Page d'erreur

Aller au menuAller au contenu

Page d'erreur

Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "file:/Users/fabrice/Sites/smarty/planning/templates/fr/error.tpl" on line 35...

Une démo ?

Laissez-nous vous démontrer comment Planning-Medical.com peut vous aider dans la réalisation de vos plannings de gardes ou vos plannings de service.

Nom :

Téléphone :

Adresse e-mail :

Demander une démo

ou bien appelez-nous au

09 721 700 21

Accueil

L’offre

Collaboration

Nous contacter

Accès à l’application

© 2008-2019 - Planning-Medical.com - v1.50 - r19.30 - contact@planning-medical.com

Mentions légales - Nous contacter - On recrute

Application réalisée par K‑Web‑Media' and expected text '.*Fatal error.*' are matched using regular expression, but expected not to be matched

at com.kms.katalon.core.keyword.builtin.VerifyNotMatchKeyword$_verifyNotMatch_closure1.doCall(VerifyNotMatchKeyword.groovy:54)

at com.kms.katalon.core.keyword.builtin.VerifyNotMatchKeyword$_verifyNotMatch_closure1.call(VerifyNotMatchKeyword.groovy)

at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:68)

at com.kms.katalon.core.keyword.builtin.VerifyNotMatchKeyword.verifyNotMatch(VerifyNotMatchKeyword.groovy:60)

at com.kms.katalon.core.keyword.builtin.VerifyNotMatchKeyword.execute(VerifyNotMatchKeyword.groovy:45)

at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)

at com.kms.katalon.core.keyword.BuiltinKeywords.verifyNotMatch(BuiltinKeywords.groovy:92)

at com.acurnillon.monkatalon.eratum.errorFound(eratum.groovy:57)

at com.acurnillon.monkatalon.eratum.invokeMethod(eratum.groovy)

at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:50)

at Test_Warning_Present.run(Test_Warning_Present:12)

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 TempTestCase1563898477347.run(TempTestCase1563898477347.groovy:21)

)

As it is an error, I guess that it could work but I am not sure of the “beauty” of the solution. What could I improve?
Merci beaucoup in advance and sorry for the French

Improvements are always possible (but sometimes unnecessary). To help you, I think I need a short statement (en Francais if you prefer) that covers your real need.

I’m thinking (guessing?) there is a much shorter way to achieve what you want, but I need that statement to be sure.

You’re very welcome. French in the code is tres bien, mais dans votre posts, ne cool pas. :wink:

(Jeez, I haven’t spoken French since high school… 45 years ago). :blush:

Ok, so I’ll try to explain what is my goal with this test.
I have a website with many pages, I want to ensure myself that none of them is returning an error message.
I want that if the test find this kind of trouble stop everything right now and send an email to the developer.
The second part is facultative and more relative to a Test Suites I guess, but the first thing is my main goal.
Is my explication detailed enough? Do you think of a more proper way to achieve this task?
(I hope it is only good memories you have of them)
Thanks in advance for your answer :wink:

I don’t see much wrong with your code. In the following example, I used the katalon website:

WebUI.navigateToUrl("https://www.katalon.com/about-us/")

WebUI.waitForPageLoad(10)

TestObject monObjetTest = new TestObject('')
monObjetTest.addProperty('xpath', ConditionType.EQUALS, '//body')
String contenu = WebUI.getText(monObjetTest)

//if(WebUI.verifyNotMatch(contenu, ".*Rue de Pecher.*", true, FailureHandling.CONTINUE_ON_FAILURE)) {
if(WebUI.verifyNotMatch(contenu, ".*Peachtree Street.*", true, FailureHandling.CONTINUE_ON_FAILURE)) {
  KeywordUtil.markPassed("Success")
} else {
  KeywordUtil.markErrorAndStop("Erreur(s) détectée(s)")
}

Personally, I would try to make the code target the container that holds the text you’re trying to match – getting all the text from the body element is less than ideal.

Hi,
You have to use FailureHandling.OPTIONAL to make your else statement possible.

The error “[…] are matched using regular expression, but expected not to be matched” will become a warning message.

Salutations to everyone,
Thank you very much @Russ_Thomas, your answer to get a result close of what I excepted.
Thank also to you @HeleneB, the change of the parameter from CONTINUE_ON_FAILURE to OPTIONAL helped me to get script executing the markErrorAndStop() function.
A thousand thank to both of you for your help :blush:

Here follow the final code to help anyone that could pass through :wink:

Main:

WebUI.openBrowser('https://www.katalon.com/about-us/')

WebUI.waitForPageLoad(10)

TestObject monObjetTest = new TestObject('')

monObjetTest.addProperty('xpath', ConditionType.EQUALS, '//body')

def contenu = WebUI.getText(monObjetTest)

WebUI.comment(contenu)

CustomKeywords.'com.acurnillon.monkatalon.eratum.errorFound'(monObjetTest)

WebUI.comment(String.valueOf(CustomKeywords.'com.acurnillon.monkatalon.eratum.errorFound'(monObjetTest)))

WebUI.closeBrowser()

CustomKeyword:

def errorFound(TestObject to) {
		
		def contenu = WebUI.getText(to)
		if(WebUI.verifyNotMatch(contenu, ".*Peachtree Street.*", true, FailureHandling.OPTIONAL)) {
			KeywordUtil.markPassed("Success")
		} else {
			KeywordUtil.markErrorAndStop("Erreur(s) détectée(s)")
		}
	}
1 Like