Need Help with Text Generator script

Hi,

I have a script that works as this:

put "Style Design" into txtstring

put (bold:"No", italic:"No", textBackgroundColor:(64,103,148), textColor:(255,255,255), TextPlatform:"WindowsClassic", underLine:"No") into stylesetup

if ImageFound(0, (text:txtstring, textStyle:stylesetup, TextFont:"Verdana", TextSize: 8))
Click (text:txtstring, textStyle:stylesetup, TextFont:"Verdana", TextSize: 8)
end if


But doesn't work as this:

//CallingScript "Style Design", "TopMenu"

params txtstring, version

(* Top menu - White text with Blue background *)
if version is equal to TopMenu or version is equal to All
(* PC version *)
put (TextPlatform:"WindowsClassic", textBackgroundColor:(64,103,148), textColor:(255,255,255), underLine:"No", bold:"No", italic:"No") & return after style
(* Mac version *)
put (textBackgroundColor:(64,103,148), textColor:(204,204,204), underLine:"No", bold:"No", italic:"No") & return after style
end if


(* Tree nodes Links - Blue text link with Tan background *)
if version is equal to TreeNodesLinks or version is equal to All
(* PC version *)
put (TextPlatform:"WindowsClassic", textBackgroundColor:(234,235,222), textColor:(21,52,98), underLine:"Yes", bold:"No", italic:"No") & return after style
(* Mac version *)
put (textBackgroundColor:(234,235,222), textColor:(42,75,112), underLine:"Yes", bold:"No", italic:"No") & return after style
(* Mac version - Highlighted *)
put (textBackgroundColor:(192,208,227), textColor:(39,74,115), underLine:"Yes", bold:"No", italic:"No") & return after style
end if


(* Main Links - Blue text bold link *)
if version is equal to MainLinks or version is equal to All
(* PC version *)
put (TextPlatform:"WindowsClassic", textColor:(21,52,98), underLine:"Yes", bold:"Yes", italic:"No") & return after style
(* Mac version *)
put (textColor:(42,75,112), underLine:"Yes", bold:"Yes", italic:"No") & return after style
end if


(* Link - Blue text link *)
if version is equal to BlueTextLinks or version is equal to All
(* PC version *)
put (TextPlatform:"WindowsClassic", textColor:(30,64,107), underLine:"Yes", bold:"No", italic:"No") & return after style
(* Mac version *)
put (textColor:(30,64,107), underLine:"Yes", bold:"No", italic:"No") & return after style
end if


(* Standard text - Black text *)
if version is equal to StandardText or version is equal to All
(* PC version *)
put (TextPlatform:"WindowsClassic", underLine:"No", bold:"No", italic:"No") & return after style
(* Mac version *)
put (underLine:"No", bold:"No", italic:"No") & return after style
end if


repeat with stylesetup = each line of style
repeat with tsize=7 to 11 step .5
if ImageFound(0, (text:txtstring, TextFont:"Verdana", textSize:tsize, textStyle:stylesetup, tolerance: 40))
Click (text:txtstring, TextFont:"Verdana", textSize:tsize, textStyle:stylesetup, tolerance: 40)
exit all
end if
end repeat
end repeat

Can you let me know what I'm doing wrong?

Thanks,
David

Comments

  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    You are putting text representations of a lot of style property lists into each line of a text value (the "style" variable). When iterating over these "styles", you'll need to turn them back into property lists by using the value() function.

    You may want to do something like this:
    repeat with stylesetuptext = each line of style 
      set stylesetup to value(stylesetuptext) -- this should help !
      repeat with tsize=7 to 11 step .5 
        if ImageFound(0, (text:txtstring, TextFont:"Verdana", textSize:tsize, textStyle:stylesetup, tolerance: 40)) 
          Click foundImageLocation() 
          exit all 
        end if 
      end repeat 
    end repeat 
    
    You'll notice that I've also used the foundImageLocation() function to click the place where the image was found. This simplifies your code somewhat, and is also a little more efficient, since Eggplant doesn't have to search for the image again.
  • Thanks, it sorta works now. I was able to get it to work with the loop for one part of it, but not the other part.

    Working Loop statement:
    put (TextPlatform:"WindowsClassic", textBackgroundColor:(64,103,148), textColor:(255,255,255), underLine:"No", bold:"No", italic:"No") & return after style

    repeat with stylesetuptext = each line of style
    put stylesetuptext
    set stylesetup to value(stylesetuptext) -- this should help !
    repeat with tsize=7 to 11 step .5
    if ImageFound(5, (text:txtstring, TextFont:"Verdana", textSize:tsize, textStyle:stylesetup, tolerance: 50))
    Click foundImageLocation()
    exit all
    end if
    end repeat
    end repeat


    Its just not constant. It might work with one part but not the other part. I'm wondering if it might be a timing issue? It works constantly with just the single Click statement, but during the loop it wouldn't find the image or at least not for the different part. I try changing from 0 to 5 seconds but it still wouldn't work. Any suggestions?

    Working Single Click statement:
    Click (Text:"123123123", Underline:"Yes", TextColor:(21,52,98), TextPlatform:"WindowsClassic")

    Not working Loop statement:
    put (Underline:"Yes", TextColor:(21,52,98), TextPlatform:"WindowsClassic") & return after style

    repeat with stylesetuptext = each line of style
    put stylesetuptext
    set stylesetup to value(stylesetuptext) -- this should help !
    repeat with tsize=7 to 11 step .5
    if ImageFound(0, (text:txtstring, TextFont:"Verdana", textSize:tsize, textStyle:stylesetup, tolerance: 50))
    Click foundImageLocation()
    exit all
    end if
    end repeat
    end repeat

    There doesn't seem to be any difference that I can find on why it shouldn't work. I'm passing in data and it would work with one part but not the other part.

    Is there a difference between how ImageFound() and Click works?

    Any help is greatly appreciated.

    Thanks,
    David
  • Nevermind, I found the problem. For some reason the ImageFound() isn't as tolerant about the slight difference in background color as Click is. Even with the tolerance set to 50.

    Not working:
    if ImageFound(5, (text:txtstring, TextFont:"Verdana", textSize:tsize, textStyle:stylesetup, tolerance: 50))

    Working:
    Click (Text:"123123123", Underline:"Yes", TextColor:(21,52,98), TextPlatform:"WindowsClassic")

    The fix was just by adding the background color into the style and then ImageFound would work. Although I thought with the tolerance set to 50, it should have taken care of that.

    Thanks again for your help. :)
  • JonathanOSXJonathanOSX ForumAdmin admin
    Just to be clear, the tolerance will be the same for any image related command (Click, WaitFor, ImageFound, etc) unless you specifically override it. However, all the other properties, TextPlatform, TextColor, BackgroundColor, etc. must be specified the same each time you use the image. In other words:

    Click (Text:"123", Underline:"Yes", TextColor:(21,52,98), TextPlatform:"WindowsClassic")

    is the same as

    ImageFound (Text:"123", Underline:"Yes", TextColor:(21,52,98), TextPlatform:"WindowsClassic")

    but is different than

    Click (Text:"123", Underline:"Yes", TextPlatform:"WindowsClassic").

    If you saw a difference in the matching behavior it probably had more to do with the state of the SUT at that particular point in your script.
  • Sorry if I wasn't clear in the last post, but both were identically with the exception of the background color and tolerance. I had set the Eggplant pref for text already.

    Font:"Verdana"
    Size: 8
    Text: Black
    Background: White

    The actual background was slightly different. Instead of (255, 255, 255) white it was (238, 238, 238) light grey. The Click command handle the slight difference without problem, but ImageFound command wouldn't or couldn't handle it without specifying the background. I had thought by adding the tolerance to 50 it would handle any difference. Is the default for tolerance set higher? In any case, it works now.

    Thanks,
    David
  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    I'd like to clarify once more, since it sounds like there may still be some misunderstanding:

    All of Eggplant's image-searching commands and functions use the same underlying search routines. So there is NO difference between Click and ImageFound (or any other command or function) as far as how they go about looking for an image on the SUT screen.

    It sounds like the difference in your case is that you were looking for similar images, but with a different background color. Because these are generated text images, the tolerance is normally calculated automatically by Eggplant based on the amount of contrast in the image. By setting the tolerance to a fixed amount (e.g. 50) you may actually be decreasing the tolerance used (and I suspect that is what happened in this case).

    In general, setting the tolerance is very straightforward for images using the "Tolerant" search type, but not for images using the "Text" search type. To see what I'm talking about, select any image in your suite that doesn't have a custom tolerance setting. In the Info drawer change the Search Type from Tolerant to Text and back again, and watch what happens to the default tolerance value. You may be surprised. :-)
  • Yes, I see what you mean. It changes the tolerance to 59 when it's set for text, higher then what I set it for.

    Thanks,
    David
Sign In or Register to comment.