assertEval find one instance

I am using Katalon Recorder to test a page where a dynamic list pops up. I need to find that at least one item in the list contains specific text. I am using a WHILE loop and assertEval using .includes to looks for these phrases. The problem is that my only options are TRUE or FALSE, so the test will fail and stop because it assumes I want ALL results to be only true or false, whereas I just need to make sure it finds one instance.

First picture is showing the webpage giving us a dynamic list after inputting “CHINA.” I now need to verify that the dynamic list which appears has at least one entry with the words “RIVERS EDGE” and at least one entry with the word “CARDINAL” in it.

The second picture is the logic I’m trying to use, but I run into the problem where it expects every item on that list to assert TRUE or it fails. I just need ONE item to assert true for each phrase. How would you go about doing this?

The logic I’m using right now expects everything on the list to have the same result.

How about creating two boolean variables, such as “hasFoundRivers” and “hasFoundCardinal”, start them out as False ahead (above) of your while loop. Then inside your while loop, use an if condition to test if you find each one of the texts, then set the specific variable to True? After the loop, you can compare the two variables to see if they are both True.

3 Likes

So I tried to set up something like that - first time trying out an if statement in Katalon Recorder. But it didn’t seem to pan out. One iteration and did not keep looping through the index. What am I doing wrong here?

NOTE - I just caught that I should set hasRivers=“true”, but still doesn’t tell me why it won’t iterate through the WHILE loop.

EDIT - Noticed that I probably needed an “endIf” after each “if.” Corrected and it ran through the whole While loop, but did not do exactly what I was looking for…

Can we see the updated version of your script with your improvements, especially your final comparisons of “hasRivers” and “hasCardinal”? And, what was it that you were looking for?

1 Like

I FINALLY got it to work with several tweaks and attempts. It seemed weird, but my problem was having the variable names in the Target Field and thinking I assign them the Value of “false”, but it’s the other way around, which was counterintuitive to me. It now works as I wanted -

Now my problem is how do you assert or verify the values of the variables. I tried two different ways (see the line in red and the one below it) and neither one works. What is the correct syntax for me to verify that each variable now has the string “true” in it?

Hello,

Please see the link below for a demo.

Let me know if you have further questions.