Skip to main content

WaitForScreenMatch

Waits until a bitmap image appears in the expected location on the screen.

public Rectangle WaitForScreenMatch(Rectangle expectedLocation, string bitmapFile);
public Rectangle WaitForScreenMatch(Rectangle expectedLocation, string bitmapFile, int maxWait, int searchRadius);

Parameters

expectedLocation: The screen Rectangle to search. These are absolute screen coordinates.

bitmapFile: The bitmap image name or the path to the bitmap. If the path is only a filename, it is assumed to be in the Data\Files folder of the test.

maxWait: The maximum time milliseconds to wait before raising a Facilita.Exception.TimeoutException.

searchRadius: A screen search radius around the expected location within which to match the bitmap in pixels.

Return Value

The Rectangle (x,y, width, height) where the image is found.

Remarks

The bitmap would previously have been created either manually using a capture tool such as fcWinSpy or using the SaveBitmap function.

If the maxWait and searchRadius fields are omitted, maxWait will use the value of MaxWait (default 120,000 milliseconds) and searchRadius to 0 pixels.

The searchRadius it typically used when the expectedLocation is identical to the original captured image and the searchRadius value allows for a change in the original location.

The bitmapFile can either be an absolute path or a filename. If only a filename is supplied it is assumed to be in the data\Files for the project. i.e. in code: string path = Datapath + "Files\\" + bitmapFile;

The .bmp suffix can be omitted from the bitmapFile.

note

All files in the Files folder for the project (e.g. C:\<MyWorkspace>\projects\<myProject>\data\Files) will automatically be copied to all injectors. There is no need to associate the with the test in Studio.

Example

wordWindow = FindTopWindow("Document1 - Microsoft Word");
Control toolbar = wordWindow.FindControl("Standard", TextMatch.Exact);
SaveBitmap(@"C:\Screenshots\word_bar.bmp", toolbar.Rectangle);
WaitforScreenMatch(toolbar.Rectangle, @"C:\Screenshots\mainWindow.bmp", 60000, 50);
// this will wait for 60 seconds until the saved window is within a 50-pixel radius of where it was in the saved bitmap

Related: