VisionTest.Core
1.0.0
dotnet add package VisionTest.Core --version 1.0.0
NuGet\Install-Package VisionTest.Core -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="VisionTest.Core" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="VisionTest.Core" Version="1.0.0" />
<PackageReference Include="VisionTest.Core" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add VisionTest.Core --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: VisionTest.Core, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package VisionTest.Core@1.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=VisionTest.Core&version=1.0.0
#tool nuget:?package=VisionTest.Core&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
VisionTest
UI test automation framework powered by computer vision (OpenCV) and OCR (Tesseract).
The primary library is VisionTest.Core, which provides screen capture, OCR/image recognition, and input simulation (mouse/keyboard) to drive UI workflows based on what’s visible on screen.
VisionTest.Core (library)
High-level capabilities
- Screen capture with DPI-awareness
- OCR text search using Tesseract
- Image template matching using OpenCV
- Input automation (mouse and keyboard)
- Locator abstraction for waiting/clicking visual targets, supporting multiple strategies (text and/or image) and regions
VisionTest Import
To install the package, use the following command:
dotnet add package VisionTest.Core --version 1.0.0
Target/runtime
- Target Framework: .NET Standard 2.0
- Windows only for the moment
Key namespaces and types
- Recognition (
VisionTest.Core.Recognition)IRecognitionEngine<TTarget>: contract returning matching rectangles for a given target.OcrEngine(TTarget = string): OCR-based search using Tesseract.- Options:
OcrOptions(whiteListChar, blackListChar, wordList, lang, PSM, OEM, useDictionnary, regexPattern). - Languages:
Languageenum withEnglish(eng) andFrench(fra). - Page segmentation modes:
PageSegmentationModeenum (Auto, SparseText, SingleBlock, etc.). - Engine modes:
OcrEngineModeenum (Auto, Legacy, LSTM, LegacyAndLSTM).
- Options:
ImgEngine(TTarget = Bitmap): OpenCV template matching usingMatchTemplatewithCCoeffNormed.- Options:
ImgOptions(threshold, colorMatch). Default threshold is 0.9f.
- Options:
- Input (
VisionTest.Core.Input)- Screen:
IScreen,WinScreenfor screen capture; exposesScreenSizeandScaleFactor(DPI scaling). - Mouse:
IMouse,Mousefor MoveTo/MoveBy/Click/Down/Up/Scroll; auto-corrects coordinates for DPI using SharpHook. - Keyboard:
IKeyboard,Keyboardfor key presses, text typing, and modified keystrokes using SharpHook.
- Screen:
- Locators (
VisionTest.Core)ILocatorV/LocatorV: waits for and clicks a visual target using one or moreSimpleLocatorVstrategies. Supports ClickAsync, RightClickAsync, DoubleClickAsync, HoverAsync, WaitForAsync, and TryWaitForAsync.SimpleLocatorV(record class inVisionTest.Core.Models): a concrete descriptor using either astringtext (OCR) or aBitmapimage (template match), plus optional region and options.ScreenElement: represents a found element with its bounds (Rectangle) and provides chaining methods (Click, RightClick, DoubleClick, Hover). Implicitly converts to Rectangle.
- Utils (
VisionTest.Core.Utils)BitmapExtensions:LoadSafelyImage(safe file loading).MatExtensions: color space conversion helpers (ConvertToBGRA,ConvertToGray) for OpenCV operations.RectangleExtensions: position helpers (Center,UpperLeft,LowerRight,UpperRight,LowerLeft) andToScreenElement(converts Rectangle to ScreenElement).RectangleFactory:FromPoints(creates Rectangle from two points).
How it works (overview)
- Capture:
Screen.CaptureScreen()grabs the desktop bitmap (DPI-aware). Optionalregioncrops to a sub-rectangle. - Recognize: a recognition engine runs on the captured bitmap:
- OCR:
OcrEngine.Find(image, "text to find")enumerates occurrences by scanning the page with Tesseract in SparseText mode and grouping word boxes. - Image:
ImgEngine.Find(image, referenceBitmap)uses OpenCVMatchTemplateto find matches above a threshold.
- OCR:
- Act:
LocatorVorchestrates capture → recognition → wait/return area and canClickAsync()the center viaMouse.
Quickstart
OCR: Wait and Click a Label
using VisionTest.Core;
using VisionTest.Core.Recognition;
// Define the locator strategy
var locator = new LocatorV(
text: "OK",
ocrOption: new OcrOptions(LTSMOnly: true, Lang: Language.English));
// Find and click in one go (waits up to 10s by default)
await locator.ClickAsync(TimeSpan.FromSeconds(10));
OCR within a Region
using VisionTest.Core;
using VisionTest.Core.Recognition;
var region = new Rectangle(0, 0, 800, 600);
var locator = new LocatorV("Hello World", new OcrOptions(Lang: Language.English), region);
// Returns a ScreenElement
ScreenElement element = await locator.WaitForAsync(TimeSpan.FromSeconds(5));
// Because of implicit conversion, you can pass it to any method expecting a Rectangle
float centerX = element.X + (element.Width / 2);
Image Matching (Template)
using VisionTest.Core;
using VisionTest.Core.Utils;
// Clean path handling
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets", "button.png");
using var refImage = new Bitmap(path);
var locator = new LocatorV(
image: refImage,
imgOption: new ImgOptions(threshold: 0.92f, colorMatch: true));
var (success, element) = await locator.TryWaitForAsync(TimeSpan.FromSeconds(3));
if (success)
{
// Chain actions directly on the element
element.Hover().Click();
}
Advanced: Dynamic Interaction Areas
// 1. Find two elements
var start = await new LocatorV("Header").WaitForAsync();
var end = await new LocatorV("Footer").WaitForAsync();
// 2. Compute a new area between them (Rectangle)
var customArea = RectangleFactory.FromPoints(start.Bounds.Location, end.Bounds.Location);
// 3. Turn it back into a ScreenElement using an existing locator's mouse context
var actionableZone = customArea.ToScreenElement(start);
actionableZone.DoubleClick();
Dependencies (VisionTest.Core)
- OpenCvSharp4.Windows (4.10.0.20241108)
- OpenCvSharp4.Extensions (4.10.0.20241108)
- Tesseract (5.2.0)
- Tesseract.Drawing (5.2.0)
- System.Drawing.Common (9.0.4)
- SharpHook (7.0.1)
- Microsoft.CodeAnalysis.CSharp (4.14.0)
Other projects (brief)
- VisionTest.ConsoleInterop: small console utilities/samples around interop/storage.
- VisionTest.Tests: unit/functional tests and test assets.
- VisionTest.TestsImplementation: example test scripts.
- VisionTest.VSExtension: Visual Studio extension that helps capture/store screen elements.
License
See LICENSE for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 4.14.0)
- OpenCvSharp4.Extensions (>= 4.10.0.20241108)
- OpenCvSharp4.Windows (>= 4.10.0.20241108)
- SharpHook (>= 7.0.1)
- System.Drawing.Common (>= 9.0.4)
- Tesseract (>= 5.2.0)
- Tesseract.Drawing (>= 5.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.