Automated testing--use AUTOIT to automatically upload pictures and other functions

1. What is AutoIt and its role?

    AutoIt is a free software that uses a scripting language. In this chapter, we apply AutoIt to UI automation testing. Using this software, we can easily simulate mouse, keyboard, window and other operations.

    When we are writing an automated script, such as the picture below, we want to upload a picture, we write the following script to locate the selected picture:

        driver.findElement(By.id("file")).click();


    At this point, jump to the following interface, the program stops, and the picture cannot be uploaded, because selenium does not support calling the operating system's own pop-up frame, so selenium cannot complete the upload of the picture, which is why we use the AutoIt tool.


2. Download AutoIt

    1) Baidu search AutoIt, enter AutoIt official website


    2) On the DOWNLOADS page under the first column, you can select the version you want
   


3. Use the AutoIt widget to automatically upload pictures

     After AutoIt is successfully installed, the following tools will be used, which can be viewed in All Programs -> AutoIt.

    The general process of using AutoIt is as follows:

        1) Use AutoIT Window Info to identify Windows controls, and write scripts according to the identified control information;

               By dragging the tool in the red box, select the information of the control you want to know

        

    2) Write scripts through SciTE Script Editor

        

        Among them, each method is used as follows:

            (1) ControlFocus ("window title", "window text", control ID) Set the input focus to a control in the specified window

            (2) WinWait ( "window title" [, "window text" [, timeout]] ) suspends the execution of the script until the specified window exists (appears)

            (3) ControlSetText ("window title", "window text", control ID, "new text") Modify the text of the specified control

            (4) Sleep (delay) causes the script to pause for a specified period of time

            (5) ControlClick("window title", "window text", control ID[, button][, clicks]]) Send a mouse click command to the specified control

    3) Compile the script into an executable file through Compile Script to.exe, and put this file in the corresponding project directory (easy to call)

    4) Execute AutoIt's script information through Run Script (ps: the operating system's own pop-up box needs to be opened at this time )

Fourth, how to call this script under selenium to complete automated testing

    

        Among them, Runtime.getRuntime().exec("external file"); is used to call a program file outside the system, and it will generate a new process to run the called program.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325848299&siteId=291194637