Passing images as parameters to custom functions

  • Suite1
    • MainScript1
    • Subscript
      • Function1(p1)
  • Suite2
    • Script2
      • Function1(p1)
      • Function2(p1)
  • Script3(p1)

Assuming the above, If i need to pass an image from suite1 into Suite2.Script2.Function1, what data do i need to put in the parameter?
In my snippet i use the “@” prefix to generate the image selection, but the function does not receive the data (the parameter is empty).

I also tried passing the image path into the parameter hoping the foundImage “image:” parameter would be able to resolve it, but no joy, eggplant returns “Unable to Find Image”

imageSearch:ImageInfo("imageName")'s ImagePath

Many thanks

For reference, I have also tried passing the image data to into the parameter using

get file ImageInfo("img_name.png")'s ImagePath

but the imageFound function does not like this

Is Suite2 currently set up as a helper to Suite1?

Hi
Yea, i fixed all the references - the fucntion resolves but the image path fails from suite 2

Hi Paul,

If you are able to find myImage within the Images Asset Pane of Suite2, and I expect you can, it should be this straightforward: log Script2.Function1(myImage).

Hope this helps,
Dave

Well no, Suite2 is a helper suite that wraps eggplant fucntions with our processes that we use each time we use that given function (error handling for example). Suite 2 has no direct knowledge of the image. Te image is defined in suite1 which is a library of usecases.

Is there no way to consume an image that is not part of the suite making the eggplant call?

Not completely sure I follow. Are your suites helper suites? If so it is pretty straightforward. Obviously make sure the function is set up to receive the image, then to call it you would have something like…
This function is in my helper suite:
to Example ImageVar
Log “Clicking image:”&&ImageVar
click image:ImageVar,waitfor:3
Log “Here is where I found it:”&&foundimagelocation()
return foundimagelocation()
end Example

Here is how I call it from my “parent” suite:
moveto “Helper_Utilities/Helpers”.Example (“Common_Images/QuickFind_Classic”)+[0,-75]

The location of my function is:“Helper_Utilities/Helpers” and its name is Example. Since its a function I have to enclose my image in parens, then I just added some pixels to it so it would “do” something.
Since its a helper suite Eggplant doesn’t need the name of the helper suite that the function is in.

So it click on whatever image I send it and then moves 75 pixels up from wherever it found it. And logs stuff.

You can reference scripts from other suites that are not helper suites, but I never do.
Here’s the relevant documentation: Reusing Code

Hope that helps.

I will certainly check with my colleagues, but I am relatively certain that your image must be in either the same suite or a helper suite to be consumed. Would it be appropriate for you to set up Suite1 as a helper to Suite2? Alternately, based on what task is being performed by Script2.Function1, you could pass proxy data instead of the image itself.
For example, this function returns a number from below an image:
set myTotalCases to HandlerGarage.ReadTextFromBelowImageLocation (TotalCases,50,50,No) -- TotalCases is an image file

If my HandlerGarage script was located in a suite that could not see the TotalCases image, I could code it this way:

set myImageRectangle to ImageRectangle(image:TotalCases)
set myTotalCases to HandlerGarage.ReadTextFromBelowImageRectangle (myImageRectangle,50,50,No)

In the former case, the search for the image occurs within the HandlerGarage.ReadTextFromBelowImageLocation function while in the latter, the search for the image occurs before the function is called and passes the coordinates of the rectangle.

I see I’m late to the party. Here’s another example. The first image is in the “calling” suite, the 2nd is in the helper suite.
moveto “Helper_Utilities/Helpers”.Example (“Common_Images/QuickFind_Classic”,“Helper_Utilities/Launch_and_Login/Avatar_Classic”)+[0,-75]

to Example ImageVar1,ImageVar2
Log “Waiting for image:”&&ImageVar2
waitfor 6, ImageVar2
Log “Clicking image:”&&ImageVar1
click image:ImageVar1,waitfor:3
Log “Here is where I found it:”&&foundimagelocation()
return foundimagelocation()
end Example

Hi

THanks for the reply. In my original post i used the syntax of “Suite2.Script2.Function1” purely to be explicit in the post as to what function i was calling, and where it was in the scheme of things. In practice it is referenced as “Script1.Fucntion1”

The only significant difference between your example and my code is that you define your “function” using the “to” keyword. I use the “function” keyword.

function Function1 p1, imageSearch
end function

Similarly, you are calling via the “moveTo” keyword, where as I am calling something like this:

if (Script1.Function1(p1:value, imageSearch:<image> by name)) 	
		--// do stuff on success
			
end if

where “image” has been replaced with the image reference from the suite, the full filepath to the image and the actual PNG data, all without success.

Would these differences be enough to cause my issues?

To answer your other point, yes, Suite2 is set as a helper to Suite1 in the settings screen.

thanks

So would I be right (pending your answer from colleagues) that even if I pass a full file path of an image to a helper suite, eggplant then disregards the absolute information and attempts to resolve just the filename in the context of the current or subordinate helper suites?

If you consider that the helper functions are designed to be SUT agnostic and reusable against different SUTS / software, they should not be driving the tests (in fact it would make them unusable in other SUT scenarios), which would be the case if Suite1 was made a helper of Suite2.

The word “function” and “to” are interchangeable here. I changed my example to be more like what I think you are trying to do. I think you may just be over-complicating things :slight_smile:.

if “Helper_Utilities/Helpers”.Example (“Common_Images/QuickFind_Classic”,“Helper_Utilities/Launch_and_Login/Avatar_Classic”) …
… is “Result_A”:
Log “do result A stuff”
… is “Result_B”:
Log “do result B stuff”
end if

function Example ImageVar1,ImageVar2
if …
… imagefound(image:ImageVar1,waitfor:3):
Log “Found image1:”&&ImageVar1
return “Result_A”
… imagefound(image:ImageVar2,waitfor:3):
Log “Found image2:”&&ImageVar2
return “Result_B”
else
Throw “Unable to find any images.”
end if
end Example

So it can be made to work with a big caveat: it won’t handle image collections but only individual images.

1 Like