Interface automation test tool-Ksend

Ksend introduction

Overview

Ksend is an automation tool that can be used in automated testing, equipment maintenance and other fields. It can simulate the sending of background text messages, simulate keyboard and mouse actions, and perform simple analysis and control of windows interface and IE pages.
The main functions of Ksend:
 Text sending function: Send the text branch to one or more text windows to control the sending delay;
 Support keyboard and mouse recording and playback;
 Support TCL language control, you can use TCL language controls the keyboard, mouse, interface and text sending;
 can use TCL language to analyze, capture and control windows;
 support the analysis and control of IE pages;
application scenarios:
command line maintenance and testing: can use TCL language or batch sentences Send maintenance or test commands to telnet terminal, DOS window, serial port terminal and other windows to realize automatic configuration and maintenance. For example, add 10,000 routes, 10,000 ACLs and other parameter traversal maintenance and testing; it can carry out the connectivity traversal test of the LAN address; it can be used for batch upgrade and maintenance of equipment, etc.
Interface maintenance and testing: You can use the extended TCL statements in the program to control the interface, such as adding 1,000 users to the WEB interface, automatically sending Notes emails, and so on.

New features in Ksend

Window information function enhancement

Add the function of capturing the content of the combox, listbox, listview, and treeview windows. On the "Window Information" page, if the type of capture is the above page, the content of the page can be displayed: the
Insert picture description here
above figure shows the information captured in the browser. The window type is listview, the number of rows is 8 and the number of columns is 4, and each column is separated by TAB.

IE page analysis function

Increase the analysis function of IE page. Because IE page is very different from ordinary windows interface, special treatment is needed:
Insert picture description here
1) TCL extension commands The
following TCL extension commands are added:
2) Window interface control
tcombo: Combbox control (drop-down box)
Tlistbox: select items in the ListBox control (list box)
tlistview: select items in the ListView control (report box)
wclose: close the window with the corresponding handle
tbmp: screenshot of the desktop, save as a file
3) IE interface control
iopen : Open the specified website
iset: set the information in the page element
iclick: link, button click
iget: get the information in the page element
iselect: select/deselect the radio button, check box
4) Other
enhancements krec, trec, krecf, trecf Command to get the content of combox, listbox, listview, treeview window controls.

Implementation Mechanism

An important function of Ksend is to send text characters to each windows. There are two ways to achieve this function, one is windows message passing, the other is keyboard simulation.
Message transfer is to transfer text messages between the Ksend program and the target window program through the PostMessage function. This method does not occupy keyboard events. Therefore, in this method, the user can perform other mouse and keyboard operations while sending text , For example, you can normally write Word files, send and receive Notes emails, etc. when Ksend is sending, without affecting users.
The keyboard simulation method is to simulate the user's keyboard input. The reason for using this method is that some interfaces and controls (such as the input box in the WEB) cannot be captured by Ksend and cannot be used for message transmission. Only the keyboard can be used for simulation input. This method will occupy keyboard events. During the text simulation input process, if the user performs interface, keyboard, and mouse operations, it will affect the input content.
The above two implementation methods exist in Ksend at the same time. Among them, the message transmission method is:
 batch statement sending function;
 most of the statements in the TCL extended statement: tsend, tput, tout, ksend, ksendkey, krec, trec, trecf, krecf, crecf, win, gettop, findw, findcw, getmtext, getmhwnd, getmhwndxy, getmtextxy, tsendkey, buttondown, winclose, winwaitopen, winwaitclose.
The non-message transmission method may affect the user's current operation statements:
keyboard, mouse simulation statements and some extended TCL statements.
Extended TCL sentence:
 settop: put a window on top
 msgbox: display a dialog box
Mouse simulation sentence:
 mouse_ld: press the left mouse button
 mouse_lu: Release the left mouse button
 mouse_rd: Press the right mouse button  mouse_ru: Release the right mouse button  mouse_md: Press the
middle mouse button
 mouse_mu:
Release the
middle mouse button
 mouse_lclick: Click the left mouse button  mouse_rclick: Mouse Right click
 mouse_mclick: middle mouse click
 mouse_dbclick: left mouse button double click
 mouse_move xy: the mouse moves to the screen coordinates x, y
 mc_move window handle xy: the mouse moves to the coordinates x, y in the window
keyboard simulation statement :
 key_press keycode: the keyboard is pressed once, the keycode is the keyboard code (1~254)
 key_down keycode: the keyboard is pressed and not released
 key_up keycode: the keyboard is released
 key_send string: output string to the current window

Ksend usage introduction

Batch statement sending function

Insert picture description here
The program opened interface is as above, divided into three columns: configuration, batch statement, and sending.
The configuration bar is used for automatic generation of batch sentences. For example, 254 sentences such as "ping 192.0.0.1" ~ "ping 192.0.0.254" should be sent to the DOS window. If input one by one, the efficiency is very low. At this time, you can use the configuration function to generate , Enter "ping 192.0.0.(*)" in the "initial sentence" column, select the second option in the "processing" column, and the replacement character from 1 to 254, and then click the "sentence generation" button in the batch sentence column , The required string will be generated in the batch statement text box.

Insert picture description here
You can enter multiple lines in the initial statement. For example, if you need to execute the tracert command after the ping statement, enter the two statements "ping 192.0.0.( )" and "tracert 192.0.0.( )" in the initial statement. The keyboard can switch statements, and then click statement generation, the result is shown in the following figure:
Insert picture description here
If you don’t need the statement generation function, you can directly enter the statement you want to send in the text field of the batch statement, or you can read it from a file, or you can use the batch statement Save the text in the text field.
After entering the batch sentence, you need to send the sentence to the relevant window. At this time, you need to manually capture the target window. The capture operation method is to drag the magnifying glass icon in the figure below to the corresponding window:

Insert picture description here
Specific operation: Press and hold the left mouse button on the magnifying glass icon, the mouse icon will change to a magnifying glass icon, do not release the mouse at this time, move the mouse to the target window (such as a DOS window), and then release the mouse, it will The window under the mouse is captured. During the movement of the mouse, the window border under the mouse will be highlighted, and you can see that the program title bar will also change. It indicates the window handle under the current mouse:
Insert picture description here
there is another change during the mouse movement. The place is the color of the "Window Capture" column and the text under the "Start Send" button. It indicates the color of the current mouse position and the specific hexadecimal value. This function can be used to obtain the color value on the screen:
Insert picture description here
as shown above Indicates that the color currently pointed by the mouse is dark blue, the blue component value is 0xA5, the green component value is 0x49, and the red component value is 0x42.
After the window is captured, the captured window will be displayed in the "Send Window List":
Insert picture description here
If you want to send text to multiple windows at the same time, you need to select the "Multi-Window Send" option, and then follow the above method to capture multiple windows.
Insert picture description here
After all windows are captured, you can set the sending interval time of each line and the interval time between each character (some windows, such as HyperTerminal, have a slow response, and characters will be lost if they are sent too fast, so you need to set the interval time between characters ), and then click the "Start Sending" button to send the text.
During the sending process, you can click the "Stop" button to stop sending, the stop button and the start sending button are the same button.
If you want to remove the captured window, just right-click in the sending window list, and there will be a corresponding menu processing:
Insert picture description here
Other options:
automatic carriage return/line feed: whether to automatically send carriage return/line feed after sending a line is
always the most Top level: Keep ksend at the top level of windows and not be covered by other windows. This option is valid for all pages (TCL pages, keyboard and mouse pages, etc.). In some cases, this option needs to be removed.
Loop: Send the generated or read statements in a loop.
Instructions: Help button for the batch statement sending function

*If the user wants to control the delay time separately, you can use the delay statement:
you can manually increase the delay by adding the #delay command in the batch statement, #delay syntax:
#delay
The effective range of the number of milliseconds of the delay is 1~60,000, which can delay one clock at most.
For example, the sentence with a delay of 1 second is: #delay 1000

TCL language sending function

There are many inflexible places to send text using batch sentences. For example, if you want to send a number from 1 to 10000, you must first construct the corresponding text; some non-text control characters (such as F1, CTRL, ALT, etc.) cannot Send; there is a need to capture the corresponding window before sending, etc., and the use of TCL language control can solve the above problems.
The TCL language sending interface is as follows: The
Insert picture description here
TCL language sending interface is also divided into three columns: TCL language window, execution window, and sending window.
The TCL language window is used to edit TCL scripts. The keywords of the TCL language and the keywords of the extended commands will be displayed in red in the window. The comment statement starts with the'#' character and displayed in blue, and the help of the extended TCL command Listed in the "Syntax Description" button page. The user can save the edited TCL language file, or read in the TCL file originally saved. There are some common script examples on the "Examples" button page. Users who are not familiar with TCL syntax can refer to them for quick start. In fact, the syntax is relatively simple.
TCL language is a script description language. TCL statements will not be compiled before TCL language is executed. Therefore, if there are several TCL statements and one of them has an error, then the TCL statement before this error statement will be executed. TCL execution will stop at the error statement.
The execution window bar is used to display the information when the sentence is sent (tsend, tput, etc.) and TCL syntax error prompts.
The function of the sending window bar is basically the same as that of batch sentence sending. However, unlike batch sentence sending, the target window must be captured in the sending window list for batch sentence sending, but TCL language sending can be sent directly to the target window through a sentence, such as using "Ksend" statement, its grammar is "ksend target window handle string", the handle of the target window can be obtained by moving the magnifying glass icon in the "Window Capture" column to the target window:
Insert picture description here
and then sent by the ksend statement, such as "ksend 66944 test123".
You can also search for the window title through findw and findcw statements, such as the following TCL statement:
Insert picture description here
First find the window with the "notepad" character in the window title through the findw statement, then store the window handle into the variable i, and then use the findcw statement to find the child window whose sub-window type is "Edit" in this window, and set the child window The handle of is stored in the b variable, and then the string "test123" is sent to the child window through the ksend statement.
*It should be noted that when using the "ksend" statement to send characters, the window handle should be the handle of the input control in the window (the above example is in the variable b), not the handle of the entire window (variable i), the type of the child window You can query in the 4th page "Window Information" or directly use the window capture function to query. In addition, if the same program is closed and then opened, its window handle will change.
After editing the TCL statement, you can click the "Execute Send" button to execute the TCL command. During the execution, you can click the "Pause/Resume" button to control the execution process, or click the Stop Send button to interrupt the execution process.
In addition, some options have been added to the TCL language sending window. The specific functions are as follows:
 "Minimize before execution": Because Ksend's TCL statement can control keyboard and mouse operations, sometimes ksend's own
interface may interfere with the execution of the program. This option can minimize the interface of ksend itself before TCL is executed.
 "Prohibit screen saver during execution": Selecting this option will disable the screen saver of the system during TCL execution, so as not to affect the execution of TCL statements. It is useful when running for a long time. After TCL is executed, the system's screen saver settings will be automatically restored.
 "Window List": The window name and handle list of the current system.
 "Shortcut keys": In some long-term keyboard and mouse simulations, it is more difficult to pause or stop the simulation in the middle, especially when the keyboard and mouse simulation actions are frequent. At this time, we can Pause or suspend the execution of TCL language through shortcut keys. The default shortcut key for "Execute/Stop" is "F2", and the shortcut key for "Pause/Resume" is "F3". Users can modify the settings themselves.
* TCL language simulation keyboard and mouse functions can be written manually, or imported from screen recording (in the third page "mouse/keyboard information"), some keyboard key values ​​and mouse positioning positions can also be in the third Page get.
The delay time of the TCL sending character interval is the same as the character interval sending of the batch sentence.
For specific TCL extended commands (including sentence sending, keyboard/mouse simulation, interface control, etc.), please refer to section 4 of this article.

Keyboard capture and playback function

Keyboard and mouse simulation are generally used for interface maintenance and testing, or used in occasions where the messaging mechanism cannot be used. The function interface is as follows: The
Insert picture description here
function interface is divided into two parts: mouse positioning and keyboard code comparison.
The keyboard code comparison is mainly used in the following TCL extended commands:
tsendkey, ksendkey, key_press, key_down, key_up,
they all need the keyboard code as the command parameter. Among them, tsendkey and ksendkey are messaging mechanisms, and key_press, key_down, and key_up are keyboard simulation mechanisms.
There is a "Record" button in the mouse positioning bar. Click this button to record the mouse and keyboard (including the recording of the keyboard). When recording, the ksend interface is reduced to a small box
Insert picture description here
at the bottom right corner of the screen: the mouse will be displayed in the box in real time The current position. This position value can be used for the "mouse_move" extended command.
After clicking Stop, the recorded keyboard and mouse actions will be displayed on the left side of the interface:
Insert picture description here
Click the "Script generation" button at this time to convert the keyboard and mouse actions into TCL language format:
Insert picture description here
Click the "Copy to TCL window" button to convert the script Copy to the second page (send in TCL language), the user can edit, optimize, and execute the script. For example, the above recorded is a script of [mouse click on the windows start menu, and then enter the "CMD" command]. When recording, the keyboard is captured by a single character, that is, pressing the "CMD" three keys requires 6 actions: press keyboard C, release keyboard C, press keyboard M, release keyboard M, press keyboard D, release Open the keyboard D, there is a delay sentence in the middle. We can optimize the above script and use the key_send statement to complete the "CMD" action: "key_send CMD". key_send is an extended command to simulate the keyboard to send a string.
In addition, the click action of the mouse is also decomposed (the mouse is pressed first, and then the mouse is released). We can merge it with the mouse_lclick (left mouse button click) command. The optimized script is as follows:
Insert picture description here
If you want to loop the above operations, you only need to put the above statement in the for statement loop.
After editing, you can click the "Execute Send" button on the TCL interface to simulate keyboard and mouse.
After recording the keyboard and mouse actions, you can also use the "Playback" button to perform simple playback operations.
There is also a "detail capture" option on the function interface. After removing this option, the program only captures mouse clicks and keyboard clicks, so the amount of script will be greatly reduced, but for some complex operations such as holding down the mouse to select a piece of text, press Actions such as copying text with the Ctrl+C key combination will be missed. Since the above-mentioned input CMD command operation is relatively simple, we can remove the "detail capture" option, and the recording results are as follows: It
Insert picture description here
can be seen that the amount of scripts is greatly reduced compared to the amount of scripts recorded last time.
During keyboard and mouse simulation, delay is a key parameter. Too short delay may cause errors. The delay is completed by the after statement, and the delay unit is milliseconds. For example, "after 1000" means a delay of 1 second.

Window information

The window information function is mainly used to analyze the control information in the window and sub-windows, and provide extended command services for windows such as "findw" and "findcw". The function interface is as follows:
Insert picture description here
first drag the icon in the "window capture" to select the target window, and the selected The window border will be highlighted. After releasing the mouse, the title and type of the sub-window in the window will be displayed. The value of the sub-window type can be applied in the "findcw" command.
The window information in the above figure shows the window information of Windows Notepad. It can be seen that it contains two sub-forms, one is of Edit type, which is where we usually enter text, and the other is of msctls_statusbar32 type, which is the type of Notepad. Status bar; it should be noted that if you want to use the "ksend" command to send text characters to the Notepad window, the handle should be the handle of the Edit control (394254 above), not the handle of the Notepad window (459784). In addition, if you
close the Notepad and reopen it, the window handle will change.
In addition, this functional interface has some additional functions, such as changing the window title and attributes, etc.
When the captured window type is Combo, Listbox, Listview, Treeview, the item content in these windows will be displayed in the child window list:
Insert picture description here

Web analytics

A WEB page is composed of a series of WEB elements, which include our common URL links, input boxes, forms, buttons, texts, etc. Each element has its own unique identification and attributes. When we want to manipulate the WEB element through the program, the first thing to do is to identify the WEB element. The attributes of some common WEB elements are as follows:
A WEB page is composed of a series of WEB elements, which include our common URL links, input boxes, forms, buttons, text, etc. Each element has its own unique identification and attributes. When we want to manipulate the WEB element through the program, the first thing to do is to identify the WEB element. The attributes of some common WEB elements are as follows:
link: link test
check box:
radio button:
drop-down box:

Test1
Test2
Test3

list box:

test 1
test 2

input box:
button:
form:

The red font above indicates the type of page element. For example, "href" means that this page element is a link, and "radio" means that this element is a radio button. The blue font part indicates the ID or name that identifies the element on this page. If there are multiple input boxes in a page, to distinguish each input box, we need to distinguish by the name or ID of the input box, such as: " name = "typeinme"". One way to view element attributes is to view the source code of the WEB page (IE menu "View"-"Source File"), but the efficiency is lower. The page analysis function of ksend provides a simpler method to obtain the attributes of each element. For example, we need to analyze Baidu's webpage: ![Insert the picture description here](https://img-blog.csdnimg.cn/20210113163359920.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0blG0dvubGR ,size_16,color_FFFFFF,t_70) Select Ksend's "Web Analysis", drag the magnifying glass icon to the input box of Baidu, the following information will be displayed on the Ksend interface: ![Insert the picture description here](https://img-blog .csdnimg.cn/20210113163421385.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0dvbGRlFFFF,color_FFu,size_16 t_70) The attribute of the input box is "", and then drag the icon to the search button to display the button attribute as "". During the movement of the icon, the element information can be dynamically updated according to the element pointed by the mouse. We can also modify the element attributes on the page. For example, we can rename the "Baidu Click" button, in the element content column, change "" to "", and then click the "Modify Content" button, the page becomes the following graphic: After capturing the WEB page, you can process the page to a certain extent, such as making the WEB page editable, obtaining all URL links on the page, setting the page background color, and so on. Note: 1. The web analysis function of Ksend is only valid for IE browser. 2. When we want to operate on WEB elements through TCL extended syntax, we need to capture or find WEB pages. The attribute of a WEB window is "IEFrame" (you can view it through Ksend's "Window Information"), but the real WEB page It is the child window "Internet Explorer_Server", so what we want to capture is the handle of the page with the category "Internet Explorer_Server", not the handle of "IEFrame". Capture method 1: #First find the WEB window through the window title set i [findw "Huawei WebMail"] #Find the child window in the WEB window set p [findcw $i "Internet Explorer_Server"] puts $pp is the WEB we are looking for Page handle 3. The drop-down box and list box in the WEB page are different from other page elements. They have their own handles. The control types are "Internet Explorer_TridentLstBox" and "Internet Explorer_TridentCmboBx". The processing is the same as the windows control (such as using tcombo to control the selection item). 4. Currently, nested pages in Frame format are not supported. ## TCL extended syntax description TCL extended command syntax is as follows: ![insert picture description here](https://img-blog.csdnimg.cn/20210113163855759.

other instructions

The ksend program also supports command line execution. For example, enter the following command in the Dos command line:
Ksend test.tcl
can execute the test.tcl file on the command line without entering the program interface. If you need to add a path,
follow the format below: Ksend c:\tcl\test.tcl
If you need to use the Package statement, you need to copy the relevant files into the LIB directory in the parent directory where the program execution file is located. For example, if the Ksend program is in the C:\test\bin directory, the called file needs to be in the C:\test\lib directory.

Application examples

Multiple telnet automatic login

Script function description: automatically open 3 DOS windows, and respectively telnet 192.168.0.1~192.168.0.3 and other 3 addresses, automatically enter the login password "good", and automatically execute the "dir" command after login.
for {set i 1} { KaTeX parse error: Expected'EOF', got'}' at position 5: i<=3} ̲ {incr i} {#Execute... i" after 1000 #Get the top-level window handle, that is, just The handle of the opened DOS window set j [gettop] after 1000 ksend $j "good" after 1000 ksend $j "dir" after 1000 } *Note: When executing this script, because the handle of the top-level window needs to be taken, the " "Always at the top" option is turned off. Execution mode: Copy this script into the TCL language window, click "Execute Send".










Batch route addition

Script function description: add 20 routes for the computer, from 30.0.0.0 to 50.0.0.0.
#Execute the windows CMD command, open the DOS window
win cmd
#Delay 2 seconds, wait for the DOS window to be established
after 2000 #Get the
top-level window handle, that is, the handle of the DOS window just opened
set j [gettop]
for {set i 30} {$ i<=50} {incr i} { #Execute route add command ksend $j "route add KaTeX parse error: Expected'EOF', got'}' at position 51: …54" after 1000 }̲ The previous DOS window was established And handle capture... i<=50} {incr i} { #Execute the route add command tsend "route add $i.0.0.0 mask 255.0.0.0 120.163.86.254" after 1000 } It should be noted that some windows characters cannot Send too fast, otherwise it is easy to lose characters. The solution is to increase the delay between lines and the interval between characters (the delay between lines is through the after statement, and the delay between characters is set in the first batch statement sending page) . Similarly, other telnet and serial port maintenance windows can be captured manually or automatically to implement batch data configuration and maintenance.







Automatic calculator

Script function description: automatically open the calculator program, and automatically close after calculating a formula.
# Prompt the user whether to start the program
set i [msgbox whether to start the program prompts the calculator. 4]
IF == {$ I}. 7 { MsgBox prompts the user aborts 0 } the else { # Start Calculator win Calc # wait calculator window opens winwaitopen Calculator # Send formula key_send 2 4 8*16 = after 2000 #Close the calculator window winclose calculator winwaitclose calculator











WEB automatic login

Script function description: automatically open the WEB page, access webmail and automatically enter the user name and password to log in. #Open
IE window
win "C:\Program Files\Internet Explorer\IEXPLORE.EXE" #Delay
waiting
after 5000 #Get
WEB window handle
set i [gettop]
tput $i #Get
WEB page handle
set p [findcw $i” Internet Explorer_Server"]
tput $p #Open the
URL
iopen $p "http://webmail"
after 3000 #Enter the
username
iset $p name textfield y00118932 #Enter the
password
iset $p type password 123456
after 1000 #Click the
login button
iclick $p type submit
after 1000 #Close the
window
wclose $i

The WEB window handle can also be obtained through the window title search, you can change the above "set i [gettop]" to "set i [findw Webmail]"

Guess you like

Origin blog.csdn.net/GoldenRolan/article/details/112574467