[Conversion] qtp-learn

Source: Internet
Author: User

1. Example of a calculator (manually add and write the result to the log file) systemutil. run "C: \ windows \ system32 \ calc.exe", "", "C: \ WINDOWS \ System32", "open" window ("Calculator "). winbutton ("1 "). click window ("Calculator "). winbutton ("+ "). click window ("Calculator "). winbutton ("2 "). click window ("Calculator "). winbutton ("= "). click

'Insert --> output value --> standard output value -->... window ("Calculator "). winedit ("edit "). output checkpoint ("edit") if datatable ("rusult1", dtglobalsheet) = "3. "Then 'print" calculation addition succeeded "'msgbox" calculation addition succeeded "reporter. reportevent micpass, "computing successful", "computing 1 + 2, correct results" writelog "computing 1 + 2, the result is correct. "else 'print" addition calculation failed. "'msgbox" addition calculation succeeded. "reporter. reportevent micfail, "computing failed", "calculation 1 + 2, result error" writelog "calculation 1 + 2, result error" end if

Window ("Calculator"). Close

Function writelog (STR) const forreading = 1, forwriting = 2, forappending = 8 dim FSO, Fil, MSG 'create a file system object) set FSO = Createobject ("scripting. fileSystemObject ") 'creates a file object and uses the FSO object to open the specified file set fil = FSO. opentextfile ("C: \ log.txt", forappending) fil. writeline now & "& STR 'close this file fil. close 'release this file object set fil = noder' release this file system object set FSO = nothing end Function

 

2. Computer example (Auto add, F7) systemutil. run "C: \ windows \ system32 \ calc.exe", "", "C: \ WINDOWS \ System32", "open" window ("Calculator "). winbutton ("1 "). click window ("Calculator "). winbutton ("+ "). click window ("Calculator "). winbutton ("2 "). click window ("Calculator "). winbutton ("= "). click

'Insert --> step generator -->... (check properties, in step builder) window ("Calculator "). winedit ("edit "). checkproperty "text", 3 ., 0 window ("Calculator "). close

3. Example of checking the focus sequence of the tab key systemutil. run "D: \ Program Files \ HP \ quicktest Professional \ samples \ flight \ app \ flight4a.exe", "", "D: \ Program Files \ HP \ quicktest Professional \ samples \ flight \ app \ "," open "'check whether the initial focus is correct Dialog (" login "). winedit ("agent name :"). checkproperty "focused", "true" dialog ("login "). winedit ("agent name :"). set "Mercury" dialog ("login "). winedit ("agent name :"). type mictab 'check whether the password focus is correct Dialog ("login "). winedit ("Password :"). checkproperty "focused", "true" dialog ("login "). winedit ("Password :"). setsecure "4c3a898e3c0b42e6cf2be4fa6670bd8f54459890" dialog ("login "). winedit ("Password :"). type mictab 'check whether the OK focus is correct Dialog ("login "). winbutton ("OK "). checkproperty "focused", "true" dialog ("login "). winbutton ("OK "). type mictab 'check whether the cancel focus is correct "). winbutton ("cancel "). checkproperty "focused", "true" dialog ("login "). winbutton ("cancel "). type mictab 'check whether the help focus is correct "). winbutton ("help "). checkproperty "focused", "true" dialog ("login "). winbutton ("help "). type mictab Dialog ("login "). winedit ("agent name :"). type mictab Dialog ("login "). winedit ("Password :"). type mictab Dialog ("login "). winbutton ("OK "). type micreturn window ("flight reservation "). close

4. Insert the order and check whether the inserted Order No is consistent with the Order No in the fax and fax information systemutil. run "D: \ Program Files \ HP \ quicktest Professional \ samples \ flight \ app \ flight4a.exe", "", "D: \ Program Files \ HP \ quicktest Professional \ samples \ flight \ app \ "," open "dialog (" login "). winedit ("agent name :"). set "yezhaohui" dialog ("login "). winedit ("agent name :"). type mictab Dialog ("login "). winedit ("Password :"). setsecure "4c3ab6c5b987d8082648b4c7a377b5ac00bf30dc" dialog ("login "). winedit ("Password :"). type micreturn window ("flight reservation "). activeX ("maskedbox "). type & quot; 11111111 & quot; window (& quot; flight reservation & quot "). wincombobox ("fly from :"). select "Frankfurt" window ("flight reservation "). wincombobox ("fly :"). select "London" window ("flight reservation "). winbutton ("flight "). click window ("flight reservation "). dialog ("flights table "). winbutton ("OK "). click window ("flight reservation "). winedit ("name :"). set "51 Test" window ("flight reservation "). winradiobutton ("business "). set window ("flight reservation "). winbutton ("insert order "). click 'step synchronization point window ("flight reservation "). activeX ("threed panel control "). waitproperty "text", "insert done... ", 10000 window (" flight reservation "). winedit ("Order No :"). output checkpoint ("Order No:") window ("flight reservation "). winmenu ("menu "). select "file; fax order... "window (" flight reservation "). dialog ("fax order No. "). winedit ("order :"). check checkpoint ("order: _ 2") window ("flight reservation "). dialog ("fax order No. "). activeX ("maskedbox "). type & quot; 111111111111 & quot; window (& quot; flight reservation & quot "). dialog ("fax order No. "). winbutton ("preview fax "). click window ("flight reservation "). dialog ("fax order No. "). dialog ("fax preview "). check checkpoint ("fax preview_2") window ("flight reservation "). dialog ("fax order No. "). dialog ("fax preview "). winbutton ("cancel "). click window ("flight reservation "). dialog ("fax order No. "). winbutton ("cancel "). click window ("flight reservation "). close

5. Check the order number and add one method one by one: Use datatable systemutil. run "D: \ Program Files \ HP \ quicktest Professional \ samples \ flight \ app \ flight4a.exe", "", "D: \ Program Files \ HP \ quicktest Professional \ samples \ flight \ app \ "," open "dialog (" login "). winedit ("agent name :"). set "yezhaohui" dialog ("login "). winedit ("agent name :"). type mictab Dialog ("login "). winedit ("Password :"). setsecure "4c3ac0c99f0d6cd69a0e8680e411e95f405990e5" dialog ("login "). winedit ("Password :"). type micreturn window ("flight reservation "). activeX ("maskedbox "). type & quot; 111111111 & quot; window (& quot; flight reservation & quot "). wincombobox ("fly from :"). select "Denver" window ("flight reservation "). wincombobox ("fly :"). select "London" window ("flight reservation "). winbutton ("flight "). click window ("flight reservation "). dialog ("flights table "). winbutton ("OK "). click window ("flight reservation "). winedit ("name :"). set "51 testing" window ("flight reservation "). winradiobutton ("business "). set 'get the database value to dbtable ("dbtable") in the able "). output checkpoint ("dbtable") 'changes the value of able ("db_qiwang_order", dtglobalsheet) = datatable ("db_qiwang_order", dtglobalsheet) + 1 window ("flight reservation "). winbutton ("insert order "). click 'step synchronization point window ("flight reservation "). activeX ("threed panel control "). waitproperty "text", "insert done... ", 10000 'check the data on the interface, standard checkpoint window (" flight reservation "). winedit ("Order No :"). check checkpoint ("Order No:") 'checks the data in the database. The database checkpoint dbtable ("dbtable_2 "). check checkpoint ("dbtable_2") window ("flight reservation "). close

Method 2: Use the environment variable systemutil. run "D: \ Program Files \ HP \ quicktest Professional \ samples \ flight \ app \ flight4a.exe", "", "D: \ Program Files \ HP \ quicktest Professional \ samples \ flight \ app \ "," open "dialog (" login "). winedit ("agent name :"). set "yezhaohui" dialog ("login "). winedit ("agent name :"). type mictab Dialog ("login "). winedit ("Password :"). setsecure "4c3d5bf18b8c162cfb5ba3de4ca8840bdf75f89a" dialog ("login "). winedit ("Password :"). type micreturn window ("flight reservation "). activeX ("maskedbox "). type & quot; 111111 & quot; window (& quot; flight reservation & quot "). wincombobox ("fly from :"). select "Frankfurt" window ("flight reservation "). wincombobox ("fly :"). select "London" window ("flight reservation "). winbutton ("flight "). click window ("flight reservation "). dialog ("flights table "). winlist ("from "). select "13540 FRA am Lon am Sr $167.10" window ("flight reservation "). dialog ("flights table "). winbutton ("OK "). click window ("flight reservation "). winedit ("name :"). set "51 testing" window ("flight reservation "). winradiobutton ("business "). set ''To get the value in the database to env .. d. dbtable ("dbtable") in environment variables "). output checkpoint ("dbtable") 'changes the value of this environment variable environment. value ("env_data") = environment. value ("env_data") + 1 window ("flight reservation "). winbutton ("insert order "). click 'step synchronization point window ("flight reservation "). activeX ("threed panel control "). waitproperty "text", "insert done... ", 10000 'check the data on the interface, standard checkpoint window (" flight reservation "). winedit ("Order No :"). check checkpoint ("Order No:") 'checks the data in the database. The database checkpoint dbtable ("dbtable_2 "). output checkpoint ("dbtable_2") window ("flight reservation "). close

 

6. parameterize the object name ''systemutil. run "C: \ windows \ system32 \ calc.exe", "", "C: \ WINDOWS \ System32", "open" 'window ("Calculator "). winbutton (datatable ("nu1", dtglobalsheet )). click 'window ("Calculator "). winbutton ("+ "). click 'window ("Calculator "). winbutton (datatable ("nu2", dtglobalsheet )). click 'window ("Calculator "). winbutton ("= "). click 'window ("Calculator "). winedit ("edit "). check checkpoint ("edit") ''' window ("Calculator "). close

7. Attribute parameterization systemutil. run "C: \ windows \ system32 \ calc.exe", "", "C: \ WINDOWS \ System32", "open" window ("Calculator "). winbutton ("one "). click window ("Calculator "). winbutton ("+ "). click window ("Calculator "). winbutton ("two "). click window ("Calculator "). winbutton ("= "). click window ("Calculator "). winedit ("edit "). check checkpoint ("edit") window ("Calculator "). close

8. parameterization systemutil of object data. run "D: \ Program Files \ HP \ quicktest Professional \ samples \ flight \ app \ flight4a.exe", "", "D: \ Program Files \ HP \ quicktest Professional \ samples \ flight \ app \ "," open "dialog (" login "). winedit ("agent name :"). set datatable ("name", dtglobalsheet) Dialog ("login "). winedit ("agent name :"). type mictab Dialog ("login "). winedit ("Password :"). set datatable ("secure", dtglobalsheet) Dialog ("login "). winedit ("Password :"). type micreturn window ("flight reservation "). close

 

9. perform automated GUI test on the logon page systemutil. run "C: \ Program Files \ HP \ quicktest Professional \ samples \ flight \ app \ flight4a.exe", "", "C: \ Program Files \ HP \ quicktest Professional \ samples \ flight \ app \ "," open "dialog (" login "). winedit ("agent name :"). set datatable ("name", dtglobalsheet) Dialog ("login "). winedit ("agent name :"). type mictab Dialog ("login "). winedit ("Password :"). set datatable ("passwd", dtglobalsheet) Dialog ("login "). winedit ("Password :"). type micreturn if Dialog ("login "). dialog ("flight reservations "). exist then

Dialog ("login "). dialog ("flight reservations "). check checkpoint ("flight reservations_4") Dialog ("login "). dialog ("flight reservations "). winbutton ("OK "). click Dialog ("login "). winbutton ("cancel "). click elseif window ("flight reservation "). exist then if datatable ("result", dtglobalsheet) = "Login successful" then reporter. reportevent micpass, "Login successful", "Login successful" else reporter. reportevent micfail, "error Logon", "error Logon" end if window ("flight reservation "). close end if

The data in datatable globalsheet is as follows: Name passwd result --- column name mercury please enter agent name jiangguang please enter password Wan mercury agent name must be at least 4 characters long. yezhaohui yezhaihui incorrect password. please try again please enter agent name yezhaohui mercury login successful

Instructor's answer: systemutil. run "D: \ Program Files \ HP \ quicktest Professional \ samples \ flight \ app \ flight4a.exe", "", "D: \ Program Files \ HP \ quicktest Professional \ samples \ flight \ app \ "," open "dialog (" login "). winedit ("agent name :"). set datatable ("username", dtglobalsheet) Dialog ("login "). winedit ("agent name :"). type mictab Dialog ("login "). winedit ("Password :"). set datatable ("password", dtglobalsheet) Dialog ("login "). winedit ("Password :"). type micreturn 'check whether the interface has the statement to implement if Dialog ("login") through the recording activation interface "). dialog ("flight reservations "). exist then

Dialog ("login "). dialog ("flight reservations "). static ("tipcontent "). check checkpoint ("checktipcontent") Dialog ("login "). dialog ("flight reservations "). winbutton ("OK "). click Dialog ("login "). winbutton ("cancel "). click 'check whether the interface exists. Use F7 to generate elseif window ("flight reservation "). exist then if datatable ("expectresult") = "Logon successful" then reporter. reportevent micpass, "test logon function", "Logon function is correct" else reporter. reportevent micfail, "test logon function", "Logon function error" end if

Window ("flight reservation "). activate window ("flight reservation "). close else reporter. reportevent micwarning, "test Logon", "unknown path", 'Shut down the system process systemutil. closeprocessbyname "flight4a.exe" end if
10. The calculator parameterized systemutil. run "C: \ windows \ system32 \ calc.exe", "", "C: \ WINDOWS \ System32", "open" buttonclick (datatable ("num1", dtglobalsheet )) buttonclick (datatable ("operate", dtglobalsheet) buttonclick (datatable ("num2", dtglobalsheet) window ("Calculator "). winbutton ("= "). click window ("Calculator "). winedit ("edit "). check checkpoint ("edit_3") window ("Calculator "). close

Function buttonclick (buttonnum) dim ilen = Len (buttonnum) 'print ilen for I = 1 to ilen STR = mid (buttonnum, I, 1) window ("Calculator "). winbutton (STR ). click Next end Function

11. systemutil is used to obtain the insert order. run "D: \ Program Files \ HP \ quicktest Professional \ samples \ flight \ app \ flight4a.exe", "", "D: \ Program Files \ HP \ quicktest Professional \ samples \ flight \ app \ "," open "dialog (" login "). winedit ("agent name :"). set "yezhaohui" dialog ("login "). winedit ("agent name :"). type mictab Dialog ("login "). winedit ("Password :"). setsecure "4c3d2fa62695109f452a2b119abce9c48ade1c9b" dialog ("login "). winedit ("Password :"). type micreturn window ("flight reservation "). activeX ("maskedbox "). type & quot; 1111111 & quot; window (& quot; flight reservation & quot "). wincombobox ("fly from :"). select "Denver" window ("flight reservation "). wincombobox ("fly :"). select "London" window ("flight reservation "). winbutton ("flight "). click window ("flight reservation "). dialog ("flights table "). winlist ("from "). select "20260 den am Lon pm aa $112.20" window ("flight reservation "). dialog ("flights table "). winbutton ("OK "). click window ("flight reservation "). winedit ("name :"). type "51 testing" 'starts transaction services. starttransaction "insertorder" window ("flight reservation "). winbutton ("insert order "). click do 'to obtain the value yn_jieshu = Window ("flight reservation") on the insert progress bar "). activeX ("threed panel control "). getvisibletext () loop until yn_jieshu = "insert done... "'end transaction services. endtransaction "insertorder"

Window ("flight reservation"). Close

12. Verify the order deletion function systemutil. run "D: \ Program Files \ HP \ quicktest Professional \ samples \ flight \ app \ flight4a.exe", "", "D: \ Program Files \ HP \ quicktest Professional \ samples \ flight \ app \ "," open "dialog (" login "). winedit ("agent name :"). set "yezhaohui" dialog ("login "). winedit ("agent name :"). type mictab Dialog ("login "). winedit ("Password :"). setsecure "4c3d62b0651a6971f298b22525cb0e2fe375bc75" dialog ("login "). winedit ("Password :"). type micreturn window ("flight reservation "). winmenu ("menu "). select "file; open order... "window (" flight reservation "). dialog ("open order "). wincheckbox ("Order No. "). set "on" window ("flight reservation "). dialog ("open order "). winedit ("edit "). set datatable ("ordernum", dtglobalsheet) window ("flight reservation "). dialog ("open order "). winbutton ("OK "). click 'get the total number of database records to dbtable ("dbtable") in the environment variable "). output checkpoint ("dbtable") print environment. value ("count1") 'delete window ("flight reservation "). winbutton ("delete order "). click window ("flight reservation "). dialog ("flight reservations "). winbutton ("Yes (y )"). click 'change environment variable value environment. value ("count1") = CINT (environment. value ("count1")-1 'check whether a dbtable ("dbtable_2") is missing in the number of records in the database "). check checkpoint ("dbtable_2") 'is another method for exact verification. Use the settoproperty method of to change the order number in the SQL statement to dbtable ("dbtable_3 "). settoproperty "Source", "select count (*) from orders where order_number =" & datatable ("ordernum", dtglobalsheet) dbtable ("dbtable_3 "). check checkpoint ("dbtable_3 ")

Window ("flight reservation"). Close

13. Verify the UPDATE function (with answers from instructors) '*************************************** * *********** 'Author: yezhaohui 'date: 2010/7/14 'description: verify the order update function '********************************** * *************** dbtable ("dbtable "). settoproperty "Source", "select class from orders where order_number =" & datatable ("ordernum", dtglobalsheet) dbtable ("dbtable "). output checkpoint ("dbtable") if datatable ("classnum", dtglobalsheet) <> environment. value ("beford ATA ") Then systemutil. run "C: \ Program Files \ HP \ quicktest Professional \ samples \ flight \ app \ flight4a.exe" dialog ("login "). winedit ("agent name :"). set "yezhaohui" dialog ("login "). winedit ("agent name :"). type mictab Dialog ("login "). winedit ("Password :"). setsecure "4c3d425c4f68c03a68cd0d2ce7c8052acbab14c3" dialog ("login "). winedit ("Password :"). type micreturn window ("flight reservation "). winmenu ("menu "). sele CT "file; open order... "window (" flight reservation "). dialog ("open order "). wincheckbox ("Order No. "). set "on" window ("flight reservation "). dialog ("open order "). winedit ("edit_2 "). set datatable ("ordernum", dtglobalsheet) window ("flight reservation "). dialog ("open order "). winedit ("edit_2 "). type micreturn select case datatable ("classnum", dtglobalsheet) Case "1" window ("flight reservation "). winradiobutton ("First "). set case "2" window ("flight reservation "). winradiobutton ("business "). set case "3" window ("flight reservation "). winradiobutton ("economy "). set case else reporter. reportevent micwarning, "Order class validity", "invalid!"

End select window ("flight reservation "). winbutton ("Update order "). click window ("flight reservation "). activeX ("threed panel control "). waitproperty "text", "Update done... ", 10000 'Check whether dbtable (" dbtable_2 ") is updated in the database "). settoproperty "Source", "select class from orders where order_number =" & datatable ("ordernum", dtglobalsheet) dbtable ("dbtable_2 "). check checkpoint ("dbtable_2") window ("flight reservation "). clo Se else reporter. reportevent micwarning, "whether data has changed", "No updates are required if data has not changed! "End if

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.