Repeat with each question

Hi there!

I’m having a strange problem with the repeate with each functionality. I’ve searched and tried examples from the forum, but it’s just not quite working for me.

I have Eggplant v1.5, and I’m trying to iterate through a list to verify imagefound.

I have a list I created with this syntax:

put("file1","file2","file3") into TestResultImages

I then attempt the following loop (I used pictureimage to make sure it wasn’t a reserved word, I know it looks dumb):

repeat with each pictureimage of TestResultImages
    if not ImageFound(pictureimage)
    then
        set errorMessage = "Test result image not found: " & pictureimage
        LogError errorMessage
   end if
end repeat

When I execute this selection, I get

File not found: imagefound Error - Couldn’t Open Image File: “TestResultImages”

I’m new to EggPlant, so I’m sure I’m doing something dumb, but honest, I searched before asking. Of interest, in the line “repeat with each pictureimage of TestResultImages” the word ‘of’ is not colored or bolded in any way, which suggests to me that the interpreter doesn’t recognize it as a reserved word. Not sure if that’s normal or not, but I don’t get a syntax error. Instead, it gets to the imagefound and expects the filename to be the name of the list.

Thanks in advance!

Howdy Chairboy…

I would do it this way:

repeat with each pictureimage of TestResultImages 
    if ImageFound(pictureimage) 
         then {doSomething}
    Else set errorMessage = "Test result image not found: " & pictureimage 
        LogError errorMessage 
   end if 
end repeat

I think the problem is that you’re just running the repeat loop as a selection, without running the line where you populate your TestResultImages list. When I run all of your code together, it works. But yes, if you just run the repeat loop as a selection, then you will get the error you describe because TestResultImages is empty, so it just resolves to the string “TestResultImages”. Put the first line of code in your post right in front of the repeat loop and run them all together.

  • Matt

Ha! That’s exactly what I was doing, I was doing run selection and assuming that since I had run a selection that set the variable earlier, that it would still be in memory.

Whoops!

Gracias!