1. Connection
DatabaseQuery example, no parameterization
// Query the number of records in the database.
// 1. Output record value, for example, 78 records. 2. Obtain the output record value. 3. Connect to the database and query the number of records.
4. Compare the output record value with the record value queried from the database. If the value is equal, the operation succeeds. If the value is not equal, the operation fails.
Browser ("Zhanjiang Informatization
TestLog on to "). Page (" Zhanjiang Dongxing Petroleum Enterprise Co., Ltd. office automation system "). Frame (" mainframe "). Output checkpoint (" 78 ")
Dim mm
'Mm = datatable. globalsheet. getparameter ("mainframeoutput_text_out"). Value
// Annotation, get the able value and the able ("mainframeoutput_text_out", dtglobalsheet) are consistent
Mm = datatable ("mainframeoutput_text_out", dtglobalsheet)
Msgbox mm
Dim res, CMD, SQL
Set res = Createobject ("ADODB. recordset ")
Set cmd = Createobject ("ADODB. Command ")
Cmd. activec
Cmd. commandtype = 1
SQL= "Select count (*) from oa_receivebumf where bumfnamelike '% receive test % '"
'SQL = "select count (*) from oa_receivebumf where bumfname ='" & NN &"'"
// Annotation, SQL statement, equivalent to the SQL statement
// SQL = "select count (*) from oa_receivebumf where bumfname like '% NN %'" // like the SQL statement
Cmd. commandtext = SQL
Set res = cmd. Execute ()
// Msgbox res ("name ")
Msgbox res (0)
If CSTR (RES (0) = CSTR (MM) then
Reporter. reportevent micpass ,"Test"," Query successful"
Else
Reporter. reportevent micfail, "test", "query failed"
End if
Set res = nothing
Set cmd. activeconnection = nothing
Set cmd = nothing
2. register the user and check whether the registration is successful.
// Register the user and check whether the user exists in the Database
1. parameterization 2. Obtain the parameterized value 3. assign a value to the query condition in the query statement.
4. query the username from the database and compare it with the parameterized median.
The script is as follows:
Browser ("test Logon "). page ("office automation system "). frame ("mainframe_2 "). webedit ("addressvo. name "). set datatable ("p_text", dtglobalsheet)
Dim xname
Xname = datatable ("p_text", dtglobalsheet)
Msgbox xname
Dim res, CMD, SQL
Set res = Createobject ("ADODB. recordset ")
Set cmd = Createobject ("ADODB. Command ")
Cmd. activec
Cmd. commandtype = 1
SQL = "Select name from address_list t where name = '" & xname &"'"
Cmd. commandtext = SQL
Set res = cmd. Execute ()
'Msgbox res ("name ")
Msgbox res (0)
Set res = nothing
Set cmd. activeconnection = nothing
Set cmd = nothing
Part 2
1. datatable method getrowcount
Datatable. getsheet ("Action1"). getrowcount // get the total number of rows
Example:
Countnum = datatable. getsheet ("Action1"). getrowcount
2. datatable method setnextrow
Datatable. getsheet ("Action1"). setnextrow // get the next row
Datatable. setcurrentrow (n) // obtain a row
3. datatable method getcurrentrow // obtain the current row number
Example: datatable. getcurrentrow
4. Get the datatable Value
4.1 datatable ("p_text", dtlocalsheet) // obtain the value of the parameter name p_text in the datatable.
4.2 datatable. globalsheet. getparameter ("p_text"). Value // obtain the parameter value using the same method as datatable ("p_text", dtlocalsheet)
For example, xname is a variable and dim xname
Xname = datatable ("p_text", dtlocalsheet)
Xname = datatable. globalsheet. getparameter ("p_text"). Value
5. datatable. Value ("num") is omitted only in the global form. The complete form is:
Datatable. Value ("num", dtlocalsheet)
----- Assign values to cells in a column:
Datatable. Value ("column_name", dtlocalsheet) = "Nanjing"
6. character conversion CSTR
Dim mm
CSTR (mm)
7. Get object property name usage:
Getroproperty ---- get the object property from the application interface (that is, the object dynamic property value obtained when the script is running)
For example, to obtain the index attribute value in the object library, it seems that only gettoproperty can be used, because the object on the application interface does not have this attribute,
QtpDescription attributes created to identify this object;
Gettoproperty ---- describes the attributes and static values of an object from the object library.
Gettoproperties ---- get the property set used to identify the object; for this set, there are attribute methods such as Count
8. In the pop-up dialog box, you can obtain the above prompt information and compare it with the information in the table. This does not necessarily prove that the pop-up prompt has an error and is mainly used for verification.
If browser ("web_name"). Dialog ("dialog_name"). exist (1) then' is not displayed = false
Error_message = browser ("web_name"). Dialog ("diaglog_name"). Static ("incorrect user password! ". Getroproperty (" text ")
If error_message <> (datatable. Value ("error_info") then
Msgbox (error_message)
End if
Browser ("web_name"). Dialog ("diaglog_name"). Close
End if
Two tips are summarized here:
1. For dialog, although the prompt message object name is "User Password error", if the information object name is "this user does not exist", it will be automatically recognized without changes, I think the main reason is that when recording the first time, the "User Password error" only allows the runtime to find this control, no matter what it is, because in the object repository, text is not the property of the object.
Second, if the prompt information is relatively long, you can use mid (error_message, n, m) to obtain a part of the feature prompt information for verification, So that I want to save processing time, avoid handling characters such as length and space.
9. Database checkpoint module:
Sub database_check
Set con = Createobject ("ADODB. Connection ")
Con. Open "Description = ibm_odbc; driver = SQL Server; server = IBM; uid = sa ;"&_
"Pwd = 123456; APP = quick test pro; wsid = IBM; database = ibm_table"
'Access method: con. Open "driver = {Microsoft Access Driver (*. mdb)}; DBQ = D: \ test. mdb"
Orocle mode: con. open "driver = {oracle in orahome92}; server = Ceshi; uid = cnd_test; Pwd = CND; DBQ = Ceshi; DBA = W; APA = T; EXC = F; xsm = default; Fen = T; qto = T; FRC = 10; FDL = 10; lob = T; rst = T; GDE = f; FRL = lo; Bam = ifallsuccessful; MTS = f; MDI = Me; CSR = f; fwc = f; PFC = 10; tlo = O ;"
Set record = Createobject ("ADODB. recordset ")
SQL = "select * From ibm_one_table"
Record. Open SQL, con
Do
If (Record ("ibm_table_column") = "Kai") then' // find the number of Kai instances in the table
Num = num + 1;
End if
Record. movenext
Loop until record. EOF = true
Record. Close
Set record = nothing
Con. Close
Set con = nothing
End sub
10. "Is + *" Type Function
Isarray' is an array
Isconnected 'determines whether qtp is connected to TD
Isdate' is a valid date type
Isempty' determines whether to initialize
Isnull' determines whether it is null
Isnumeric 'determines whether it is a number
Isobject' determines whether a function object is used
Isready' determine whether the device is ready
Isrootfolder' is the root directory
11. For method 1, select dtlocalsheet for parameterization.
Dim countnum
Countnum = datatable. getsheet ("Action1"). getrowcount
For I = 0 to CountNum-1
---- Xunhuanti ------
Datatable. getsheet ("Action1"). setnextrow // use the setnextrow Method
Next
12. For method 2, select dtlocalsheet for parameterization.
Dim countnum
Countnum = datatable. getsheet ("Action1"). getrowcount
For I = 1 to countnum
Datatable. getsheet ("Action1"). setcurrentrow (I) // use the setcurrentrow (I) Method
--Ddd ―――
Next
13. When using while method 1, select dtlocalsheet for parameterization.
Dim countnum, I
I = 1
Countnum = datatable. getsheet ("Action1"). getrowcount
While I <= countnum
------ Xuhuanti ---
Datatable. getsheet ("Action1"). setnextrow
I = I + 1
Wend
14. When using while method 2, select dtlocalsheet for parameterization.
Dim countnum, I
I = 1
Countnum = datatable. getsheet ("Action1"). getrowcount
While I <= countnum
Datatable. getsheet ("Action1"). setcurrentrow (I)
---- Xuhuanti ---
I = I + 1
Wend
Part 3
15. Do While Method
Dim I, rowcount 'defines two variables
I = 0
Rowcount = datatable. getsheet ("Action1"). getrowcount 'sets rowcount to equal to the number of rows in action1.
Msgbox rowcount
Do while I <rowcount
I = I + 1 'the first time you enter the loop, after executing this sentence, I = 1
I commented out the 'able able. getsheet ("Action1"). setcurrentrow (I) 'sentence. The correct statement should be as follows and written separately.
Datatable. getsheet ("Action1 ")
Datatable. setcurrentrow (I)
---- Xunhuanti ----
Loop
16. Get the object property value
Dim usname
Usname = browser ("test Logon "). page ("office automation system "). frame ("mainframe_2 "). webedit ("addressvo. name "). getroproperty ("value") 'gets the object property value, for example, property is value
Msgbox usname
17. Get the ID to be deleted and delete it.
'Url is obtained from the object on the page for viewing the information of the new record. Therefore, during recording, register, view (modify), and delete the record.
Dim struserid, ID, Strid
Id = browser ("test Logon "). page ("office automation system "). frame ("mainframe_4 "). getroproperty ("url") 'contains the ID information of the record to be deleted in the URL attribute.
Strid = mid (ID, instr (60, ID, "=") + 1) 'is to obtain the required id value, for example: Strid = mid (ID, instr (1, ID, "=") + 1)
Struserid = strid' struserid is the ID of the check box attribute value before the record I want to delete
Browser ("test Logon "). page ("office automation system "). frame ("mainframe "). webcheckbox ("value: =" & struserid ). set "on" to select the record to be deleted.
Browser ("test Logon"). Page ("office automation system"). Frame ("mainframe"). webbutton ("delete"). click' is deleted.
17.2 obtain the id value from the database and assign a value to delete it.
Browser ("test Logon "). page ("office automation system "). frame ("mainframe_2 "). webedit ("addressvo. name "). set datatable ("p_text", dtglobalsheet)
Browser ("test Logon "). page ("office automation system "). frame ("mainframe_2 "). webedit ("addressvo. address "). set datatable ("p_text1", dtglobalsheet)
Browser ("test Logon "). page ("office automation system "). frame ("mainframe_2 "). webedit ("addressvo. unittel "). set datatable ("p_text2", dtglobalsheet)
Dim xname, address, unittel
Xname = datatable ("p_text", dtglobalsheet )'
From: http://www.51testing.com /? Uid-138711-action-viewspace-itemid-126459