Robot's Identification of Grid Controls in Delphi

zhaozj2021-02-16  54

Recently, a Guangzhou test friend encountered such a problem when learning automation test in actual work, the identification of Grid control in Delphi, using Robot to position the problem on a field of a field, his software is shown:

At that time, I saw this problem. I thought that one of the two solutions was to use the object's method, assign value, compiled functions, input columns and rows, and then handled them directly, high efficiency, and one idea is to use coordinates. Location and then entering data, but also the write function, the specific calculation is handled by the function, although it cannot be used, but simple and practical.

According to the first idea, the software tested the software to develop Delphi, where gird is a third-party control. Here I use TDBGRID to replace his third-party control to simplify, first solve the actual problem, yourself Make a program, connect the database with the ADO to simulate the actual situation with the DataGrid display data. The recording script is as follows:

Sub

Main

Dim Result As INTEGER

'INITIALLY Recorded: 2004-4-22

23:01:19

'Script name: first

"" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Window setContext, "CAPTION = Form1", ""

GenericObject DBLClick, "Class = TDBGRID; ClassIndex = 1", "Coords = 168, 27"

InputKeys "good"

GenericObject Click, "Class = TDBGRID; ClassIndex = 1", "CoRDS = 369, 33"

Window Closewin, "", ""

End Sub

People who have used Delphi know that the TStringGrid has a Cell property, we can use the Robot function SQASetProperty to assign the CELL assignment to the function, first use Robot's GUI INSERT Object Properties to capture the properties of the object TDBGRID, this is because The function sqasetproperty can only work on the attribute of the Robot grab, that is, even if there is a Cell property, Robot's Object Properties can't capture this property, we can't achieve the idea of ​​the front. After grabbing the properties of TDBGRID with Object Properties, it is found that only some attributes can only be used, how to do it, how to do, use Delphi Enabler to see if you can get more properties, I put Sqasrv.pas In fact, the core of Delphi Enabler is this Delphi unit file) Add to the project file, recompile (there may be some problems when it can be compiled, the problem I encountered is Unit 'oleauto' is deprecated, with $ warn unit_deprecated on / off You can solve it), re-recording the script is as follows: (This is basically grabbed by the attributes of TDBGRID).

Sub

Main

Dim Result As INTEGER'Initially Recorded: 2004-4-22

23:38:55

'Script name: second

"" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Window setContext, "Name = form1; type = form", ""

GenericObject DBLClick, "Name = DBGRID1; TYPE = CustomGrid", "CoRDS = 93, 30"

InputKeys "jack"

GenericObject Click, "Name = DBGRID1; TYPE = Customgrid", "Coords = 338, 26"

Window Closewin, "", ""

End Sub

But there is still no Cell attribute we want, only the columns attribute, there is no Cell property I need, what should I do? So the source code of Delphi's TDBGRID found that there is HideEdit, UpdateEdit, etc. in TDBGrid inherited TCUSTOMGRID, indicating that TDBGIRD is generated in the background when entering the data, and the text box automatically disappears with the data. TDBGRID. This way we can simply be assigned to this Edit's text attribute, because the TDBGrid does not have a Cell property, cannot directly use the SQASetProperty function to assign the Cell's FOCUS attribute. You can only use the CELL to give it focus, because only focus is in this Cell After the up, the floating text box will appear, modify the script on the upper side:

Sub

Main

Dim Result As INTEGER

DIM VAR AS STRING

'INITIALLY Recorded: 2004-4-22

23:38:55

'Script name: second

"" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Window setContext, "Name = form1; type = form", ""

GenericObject DBLClick, "Name = DBGRID1; TYPE = CustomGrid", "CoRDS = 93, 30"

Result = SQASetProperty ("Name =; type = Customgrid; INDEX = 1", "Text", "Mr.")

Result = SQAGETPROPERTY ("name =; type = Customgrid; Index = 1", "text", var)

GenericObject Click, "Name = DBGRID1; TYPE = Customgrid", "Coords = 338, 26"

if Result = 0 THEN

Msgbox "Hello"

END IF

GenericObject Click, "Name = DBGRID1; TYPE = CustomGrid", "Coords = 338, 26" 'Window Closewin, "", ""

End Sub

Although the assignment is successful, DataGrid cannot display the data you need (here you need to study), because the time is, use the second way to coordinate, consider the multi-platform sharing, write the setgridfocus function, thoughts get TDBGRID Objects, gets high, calculating coordinates, calculating coordinates (these are implemented inside the function), where moving a fixed value 24 is 24 in tracking TDBGRIGHT attributes 24

The final code is as follows:

Sub setgridfocus (Strobject As String, Strrow As String, Strign As String)

DIM IRESULT AS INTEGER

DIM ICOUNT AS INTEGER

DIM COLWIDTH () AS INTEGER

DIM IWIDTH AS INTEGER

DIM STRCOLPOS AS INTEGER

DIM STRROS AS INTEGER

DIM STRCOR AS STRING

DIM ITEMP AS INTEGER

Strcolpos = 0

StrrowPOS = 0

Itemp = 0

SqagetProperty Strobject, "Columns.count", ICOUNT

IF ICOUNT <> 0 THEN

Redim Collwidth (ICOUNT - 1)

While Itemp

IRESULT = SQAGETPROPERTY (Strobject, "Column.Items (" CSTR (Itemp) "). Width", iWidth)

COLWIDTH (itemp) = iWidth

Itemp = itemp 1

Wend

END IF

Strcolpos = 20

IF CINT (STRCOL) <> 1 THEN

For itemp = 1 to CINT (STRCOL) -1

Strcolpos = Strcolpos COLWIDTH (itemp-1)

Next Itemp

END IF

For itemp = 1 to CINT (STROW)

StrowPOS = 24 StrowPOS

Next Itemp

Strcor = "COORDS =" & strcolpos & "," cstr (strrowpos)

GenericObject Click, Strobject, Strcor

InputKeys Strvalue

STOP

Strcor = "Coords =" & strcolpos & " cstr (strroWPOS 24)

GenericObject Click, Strobject, Strcor

End Sub

There are still many missed places, but the value of the floating text box is successful, but there is no in-depth study in the TDBGRID. This function has a small problem in practical applications, and there is no complete "thoughtful", Back time correction. Remarks:

Finally, I optimize and extend the code, developed the related functions for GRID, one of them below

// Get the number of columns

Function getColcount (SGridRecogstr as string) AS Integer

Dim Result As INTEGER

DIM VVALUE AS VARIANT

Dim SlogMessage As String

DIM SERRORMESSAGE AS STRING

GRDGETROWCOUNT = -1

Result = SQAGetProperty (SGridRecogstr, "Column.count", vValue)

If Result = SQASUCCESS THEN

GetRowcount = CINT (VVALUE)

Else

SlogMessage = "Unable to get the number of columns"

SERRORMESSAGE = "[" & cstr (result) & "=" & error (result) & "]"

SQALogMessage Sqafail, Slogmessage, SERRORMESSAGE

END IF

END FUNCTION

Just here.

Written in the early morning of 2004-4-23 1.30

转载请注明原文地址:https://www.9cbs.com/read-23773.html

New Post(0)