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
@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
@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 | |
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.