findAllOcrText
SequenceOfObjects findAllOcrText(text, [parameterMap], [searchRegion])
This function will perform optical character recognition on the display also showing the currently running application and search for the specific text within the result set. It will return a sequence of ScreenRectangle objects corresponding to the locations of the specified text.
The OCR will be performed over all available screens making up the desktop. At least on Windows and X11-based systems. For OCR on multi-screen setup on macOS please inquire with technical support.
The search behavior can be configured through entries passed via the optional parameterMap
argument.
language
- The language hint for OCR engine. Use an empty string to use the OCR engine defaults. The default value is the value of testSettings.defaultOcrLanguage property.profiles
- An array of OCR engine specific profile names. This parameter is used only with engines that support profiles.options
- A map of engine-specific option names and values. These options are passed to the OCR engine after loading the specified profiles.scaleFactor
- Image up-scale factor. The source image is upscaled by that factor before it is passed to the OCR engine. The default value is3.5
. It can be set to a lower value to improve the OCR performance in case the text is rendered with a large font.
# Check whether 'Test Text' is displayed on screen 3 times test.compare( len( findAllOcrText( "Test Text", { "language": "German" } ) ), 3 )
// Check whether 'Test Text' is displayed on screen 3 times test.compare( findAllOcrText( "Test Text", { "language": "German" } ).length, 3 )
# Check whether 'Test Text' is displayed on screen 3 times my @locations = findAllOcrText( "Test Text", { language => "German" } ); test::compare( scalar @locations, 3 )
# Check whether 'Test Text' is displayed on screen 3 times Test.compare( findAllOcrText( "Test Text", { "language" => "German" } ).length, 3 );
# Check whether 'Test Text' is displayed on screen 3 times test compare [ llength [ findAllOcrText "Test Text" { language "German" } ] ] 3
In case a searchRegion is specified as the last argument, the OCR is performed only within the area corresponding to it. The search region can be an AUT object, a ScreenRectangle object or an array of such objects. It can also be a special string value "all", in which case all top-level objects are used.
The searchRegion can also be an Image Object object. In such case no new screenshots are taken and the specified image is used instead. Currently it is not possible to limit the OCR scope to a portion of an Image
object; please use the Image.copy() to cut the relevant section.
# Check whether 'Test Text' is displayed on MyWidget 3 times test.compare( len( findAllOcrText( "Test Text", {}, waitForObject( names.MyWidget ) ) ), 3 ) # Check whether 'Test Text' is displayed on multiple widgets 3 times test.compare( len( findAllOcrText( "Test Text", {}, [ waitForObject( names.MyWidget ), waitForObject( names.MyOtherWidget ) ] ) ), 3 ) # Check whether 'Test Text' is displayed on the left half of the MyWidget object bounds = object.globalBounds( waitForObject( names.MyWidget ) ) bounds.width = bounds.width / 2 test.compare( len( findAllOcrText( "Test Text", {}, bounds ) ), 3 ) # Check whether 'Test Text' is displayed on the specified area test.compare( len( findAllOcrText( "Test Text", {}, UiTypes.ScreenRectangle( 100, 100, 200, 300 ) ) ), 3 ) # Check whether 'Test Text' is displayed on all top-level objects test.compare( len( findAllOcrText( "Test Text", {}, "all" ) ), 3 )
// Check whether 'Test Text' is displayed on MyWidget 3 times test.compare( findAllOcrText( "Test Text", {}, waitForObject( names.MyWidget ) ).length , 3 ) // Check whether 'Test Text' is displayed on multiple widgets 3 times test.compare( findAllOcrText( "Test Text", {}, [ waitForObject( names.MyWidget ), waitForObject( names.MyOtherWidget ) ] ).length, 3 ) // Check whether 'Test Text' is displayed on the left half of the MyWidget object bounds = object.globalBounds( waitForObject( names.MyWidget ) ) bounds.width = bounds.width / 2 test.compare( findAllOcrText( "Test Text", {}, bounds ) .length, 3 ) // Check whether 'Test Text' is displayed on the specified area test.compare( findAllOcrText( "Test Text", {}, UiTypes.ScreenRectangle( 100, 100, 200, 300 ) ).length, 3 ) // Check whether 'Test Text' is displayed on all top-level objects test.compare( findAllOcrText( "Test Text", {}, "all" ).length, 3 )
# Check whether 'Test Text' is displayed on MyWidget 3 times my @locations = findAllOcrText( "Test Text", {}, waitForObject( names::MyWidget ) ); test::compare( scalar @locations, 3 ) # Check whether 'Test Text' is displayed on multiple widgets 3 times my @locations = findAllOcrText( "Test Text", {}, ( waitForObject( names::MyWidget ), waitForObject( names::MyOtherWidget ) ) ); test::compare( scalar @locations, 3 ) # Check whether 'Test Text' is displayed on the left half of the MyWidget object my $bounds = object::globalBounds( waitForObject( names::MyWidget ) ); $bounds->width = $bounds->width / 2; my @locations = findAllOcrText( "Test Text", {}, $bounds ); test::compare( scalar @locations, 3 ) # Check whether 'Test Text' is displayed on the specified area my @locations = findAllOcrText( "Test Text", {}, new UiTypes::ScreenRectangle( 100, 100, 200, 300 ) ); test::compare( scalar @locations, 3 ) # Check whether 'Test Text' is displayed on all top-level objects my @locations = findAllOcrText( "Test Text", {}, "all" ); test::compare( scalar @locations, 3 )
# Check whether 'Test Text' is displayed on MyWidget 3 times Test.compare( findAllOcrText( "Test Text", {}, waitForObject( names.MyWidget ) ).length, 3 ); # Check whether 'Test Text' is displayed on multiple widgets 3 times Test.compare( findAllOcrText( "Test Text", {}, [ waitForObject( names.MyWidget ), waitForObject( names.MyOtherWidget ) ] ).length, 3 ); # Check whether 'Test Text' is displayed on the left half of the MyWidget object bounds = Squish::Object.globalBounds( waitForObject( names.MyWidget ) ); bounds.width = bounds.width / 2 Test.compare( findAllOcrText( "Test Text", {}, bounds ).length, 3 ); # Check whether 'Test Text' is displayed on the specified area Test.compare( findAllOcrText( "Test Text", {}, UiTypes::ScreenRectangle.new( 100, 100, 200, 300 ) ).length, 3 ); # Check whether 'Test Text' is displayed on all top-level objects Test.compare( findAllOcrText( "Test Text", {}, "all" ).length, 3 );
# Check whether 'Test Text' is displayed on MyWidget 3 times test compare [ llength [ findAllOcrText "Test Text" {} [ waitForObject $names::MyWidget ] ] ] 3 # Check whether 'Test Text' is displayed on multiple widgets 3 times test compare [ llength [ findAllOcrText "Test Text" {} { [ waitForObject $names::MyWidget ], [ waitForObject $names::MyOtherWidget ] } ] ] 3 # Check whether 'Test Text' is displayed on the left half of the MyWidget object set bounds [object globalBounds [ waitForObject $names::MyWidget ] ] property set $bounds width [ expr [ property get $bounds width ] / 2 ] test compare [ llength [ findAllOcrText "Test Text" {} $bounds ] ] 3 # Check whether 'Test Text' is displayed on the specified area test compare [ llength [ findAllOcrText "Test Text" {} [ construct ScreenRectangle 100 100 200 300 ] ] ] 3 # Check whether 'Test Text' is displayed on all top-level objects test compare [ llength [ findAllOcrText "Test Text" {} "all" ] ] 3
© 2024 The Qt Company Ltd.
Documentation contributions included herein are the copyrights of
their respective owners.
The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.
Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners.