Katalon Recorder : Verify Text Statement

In Katalon Recorder Chrome addon, I’m trying to set up a simple check to verify if an element contains a specific text.

Here is what I’ve done so far :

Katalon Recorder:

Command | Target | Value

click | id=subscribed |

StoreText | id=subscribed | i

echo | ${i}

verifyText | id=subscribed | alyx

Log result :

[info] Executing: | click | id=subscribed | |

[info] Executing: | storeText | id=subscribed | i |

[info] Store ‘alyx.vance’ into ‘i’

[info] Executing: | echo | ${i} | |

[info] Expand variable ‘${i}’ into ‘alyx.vance’

[info] echo: alyx.vance

[info] Executing: | verifyText | id=subscribed | alyx |

From here, I don’t how to set up something like this :

If VerifyText => contains alyx => Goto Label X (True)

If VerifyText => doesn’t contain alyx => Goto Label Y (False)

Thank you for your help.

Hi, use JS function includes (returns true if string contain another string) and then command “if”
runScript | var check = ${i}.includes(“alyx”); return check | check
if | ${check}
goToLabel | labelX
else
goToLabel | labelY

1 Like

Hello Piotr,
Thank you for your reply.
I’ve finaly found the solution and I did post the solution in stakoverflow forum that looks like yours and at the same date : https://stackoverflow.com/questions/64117338/katalon-recorder-if-variable-contains-some-text-true-false/64536491#64536491

@Piotr can i ask also.
What command to use if i like to fail the test?

Example (using the same sample) :

runScript | var check = ${i}.includes(“alyx”); return check | check
if | ${check} //lets say false here
<Fail the test here! cos the text is not found within the target text>
else //lets say true here
<Pass the test here! cos the text is found within the target text. Continue with the rest of the steps>

To fail test i just simply use click command but i don’t give it any Target value so it try to click empty object and it will generate fail. You can also add some error info in target so it looks like:

click | Text not found on the page

It will cause error:
Element “Text not found on the page” not found

It’s a workaround but it’s work.

1 Like

@Piotr Thanks for your reply. Can i also check with you why im getting incorrect results. Its slightly not related to runscript command. Here are my steps :

storeEval |(’${sourceText}’).includes(’${targetText}’) | Checker
echo | ${Checker} //im getting true here
if | !(${Checker}) //here im checking if ‘Checker is false’. If its false then logically it should not go inside the if.
click | Text not found on the page
endif

Basically, i just want to verify that “targetText” is within the “sourceText”. If its true (mean its within the text), then it means its pass.

But katalon recorder still executes the inside of if (the click | Text not found on the page part) even though the if clause if false.

Here are the logs :

[info] Store ‘true’ into ‘Checker’
[info] Executing: | echo | ${Checker} | |
[info] Expand variable ‘${Checker}’ into ‘true’
[info] echo: true
[info] Executing: | if | !(${Checker}) | |
[info] Expand variable ‘!(${Checker})’ into ‘!(true)’
[info] Executing: | click | Text not found on the page | |

Ah nevermind.

Katalon recorder just went through the step, but it didnt actually execute it.

But maybe katalon team should add in log something like ‘skipping this step’, instead of ‘Executing’ for steps in if else statement

1 Like

Yes, exactly, it’s only pretends but not execute them, same with gotolabel, it will not jump to your label, it will go trough every step but without executing them.
If you run your test second time it will skip it like you would expect.