Image File and Suite Information
The functions in this section return various properties associated with image files and Eggplant Functional suites.
ImageInfo
Function
Behavior: Returns an image property list for a single image, or a list of image property lists for multiple image references. Depending on the data that is available, the list can contain the following properties:
- CaptureDate: The date of the image capture, including time, in the format (yyyy-mm-dd hh:mm:ss +0000); the final four digits represent the GMT offset.
- CaptureHost: The name of the SUT on which the image was captured.
- CaptureLocation: Coordinates that indicate the position of the top-left corner of the image when it was captured in the Viewer window.
- CaptureScreenSize: The dimensions of the SUT screen on which the image was captured, given in pixels as (
width
,height
). - Description: The image description in the Suite Editor Info panel.
- HotSpot: The coordinates of the image's hot spot, given as (x, y).
- ImageLocation: The on-screen coordinates of the hot spot of the image. See the ImageLocation() function.
- ImageName: The name of the image file.
- ImagePath: The full pathname of the image file.
- ImageRectangle: The rectangle coordinates of the image found using the ImageRectangle() function.
- ImageSize: The image’s size in pixels, given as (
width
,height
). - ImageTolerance: The tolerance setting used when capturing the image on the SUT.
- Pulsing: Whether the image was captured with the pulsing setting (true/false).
- Scale: The scale used to capture the image.
- SearchType: The Search Type selected when saving the image.
Parameters: One or more Image References. Returns: An image property list, or list of image property lists. For example:
((CaptureDate:"2016-10-19 15:20:52 -0600", CaptureHost:"Windows", CaptureLocation:(527,707), CaptureScreenSize:(1024,768), Description:"", HotSpot:(11,19), ImageLocation:"", ImageName:"Value", ImagePath:"C:/Users/Carrie/Documents/Demo.suite/Images/ValueField.png", ImageRectangle:"", ImageSize:(23,39), Pulsing:"False", Scale:"1", SearchType:"Tolerant"))
Example:
put ImageInfo("BrowserIcon") into ListVariable //Stores the return of the imageInfo function in a variable.
Example:
put the number of items of imageInfo("CheckBox") into NumberinReturn //Stores the number of items in the return of ImageInfo.
if NumberinReturn is greater than 1 then log "There are" && NumberinReturn && "images in the collection." //Checks whether the number of items in the return is greater than 1, which means the image is actually an image collection.
Example:
copy file imageInfo("CompanyLogo")'s imagePath to folder "C:\Users\Carrie\Desktop\ResultsFolder" //Copies an image from inside the current suite to a new location on the eggPlant machine.
Example:
put the suiteinfo's imagesfolder into myimagefolder //Stores the path to the image folder in the current suite.
put the files of myimagefolder as a list into myimages //Stores the names of all files in the image folder (including imageinfo files) as a list.
repeat with each item of myimages by reference //Iterates on the list by reference instead of in memory.
if it contains "imageinfo" then delete it //Deletes the file name from the list if it's an imageinfo file.
end repeat
repeat with each item of myimages //Iterates on the remaining list of file names after the imageinfo file names have been removed.
put imageinfo(it)'s CaptureDate into mycapturedate //Stores the CaptureDate property value in a variable.
If mycapturedate is not empty and mycapturedate is earlier than 1 year ago then //Determines whether the CaptureDate occurred more than a year ago from today.
do merge of <<Logwarning "Image [[it]] was captured over a year ago.">>//Uses the merge function to construct a string and log a message.
end if
end repeat
ImageHotSpot
Function
Behavior: Returns the coordinates (x
,y
) of the image’s hot spot, relative to the top-left corner of the image.
If you need to work with the hot spot location of a found image on the SUT, use the ImageLocation() function.
Parameters: A single
image, excluding Image Collections.
Returns: Coordinates. For example:(-65,90)
Example:
set PointAdjustment to ImageHotSpot("Logo") - imageSize("Logo")//Finds the difference between the lower right corner of the image and the hot spot of the image.
Example:
log imagehotspot("CompanyLogo")
ImageSize
Function
Behavior: This function returns the size in pixels—given as (width
, height
)—of the given image. If the image is not found, an exception is raised.
Parameters: A single
image, excluding Image Collections.
Returns: Size in pixels (width
, height
). For example: (48,19)
Example:
put ImageSize("image") into ImageSizeVariable //Stores the return of the imageSize function in a variable.
Example:
If the ImageSize of "ConfirmationNumberField" is not(30,40) then Log "The image has changed size since original capture." //Checks whether the image size is as expected.
Example:
params CollectionName //Parameterizes the script to receive the name of an image collection.
put item 1 of ImageInfo(CollectionName) into myImage //Stores the first item of the return of ImageInfo, which is the ImageInfo for a single image in a collection.
put the folder of myImage's ImagePath into CollectionFolder //Uses the folder function to find the folder path of the image, based on the file path of the image. This is the folder path of the image collection.
put the files of CollectionFolder into ImagesList //Stores the names of the files in the image collection.
repeat with each Image of ImagesList //Iterates on each file name, including imageinfo files.
if myFile contains ".png" then //Checks whether the file name belongs to an image file.
put CollectionName & slash & myFile into ImageRelativePath //Constructs a path relative to the suite using the image file name.
put ImageRelativePath's ImageSize into ImageSize //Stores the return of the imageSize function in a variable.
insert item 1 of ImageSize times item 2 of ImageSize after ListofAreas //Creates a list of the areas of each image in the collection.
end if
end repeat
Log "The median area of the images in the collection "&CollectionName&" is "& the median of ListOfAreas&"." //Calculates the median area of the images in the collection using the median function and logs a message about it .
ImageColorAtLocation
Function
Behavior: Returns the color value, displayed in the format specified by the colorFormat global property, of a single pixel in the given image. The coordinates of the pixel are relative to the top-left corner of the image.
If you need to determine the color of a pixel on the SUT, use the ColoratLocation() function.
Parameters: One image name and one coordinate location.
Returns: A color value. For example: (255,255,255)
. For more information, see Color Values in SenseTalk.
Example:
set the colorFormat to "HSB" //Sets colors to display according to hue, saturation, and brightness values from 0 to 1
put ImageColorAtLocation("myIcon",[23,1]) //Returns the color at location [23,1] of the given image. i.e. HSB, 0.592, 0.977, 0.682
Example:
function FindChartreusePercentage myImage //Declares a function named FindChartreusePercentage with parameter value myImage.
if "Chartreuse" is not among the keys of the NamedColors then set the NamedColors.Chartreuse to color(127,255,0) //Adds chartreuses to the global property list of named colors, if it is not already a named color.
put the width of imageSize(myImage) into XDirection //Stores the x coordinate of the imageSize in a variable.
put the height of imageSize(myImage) into YDirection
set TotalPixels to XDirection x YDirection //Calculates the total number of pixels in the image.
set ColorPixels to 0 //Resets the tally of chartreuse-colored pixels to zero.
repeat YDirection times //Iterates down the height of the image.
put the repeatIndex - 1 into YCoord //Tracks the Y coordinate of the current pixel.
repeat XDirection times //Iterates across the width of the image.
put the repeatIndex - 1 into XCoord //Tracks the X coordinate of the current pixel.
put imagecoloratlocation(myImage, (XCoord,YCoord)) into ReturnedColor //Stores the RGB value of the current pixel.
if ReturnedColor is color("Chartreuse") then add 1 to ColorPixels //If the pixel is chartreuse, tallies the pixel.
end repeat
end repeat
return round((ColorPixels/TotalPixels) * 100, 1) //Returns the percentage of chartreuse pixels, rounded to the first decimal place.
end function