selenium IDE scripts and commands

Selenese

    The command command of selenium IDE is also called selenese.

  • The selenese command has at most two parameters, one is target and the other is value.
  • Depending on the type of command, a Selenese command can have no parameters, one parameter, or two parameters.

    The 3 types of selenese commands are as follows:

Command type

meaning

Actions

(action) type

Such commands interact directly with page elements.

For example, the "click" command will click a page element directly in the page: the "type" command will enter text in the text box of the page, and the content of the entered text will be displayed in the text box.

Accessors

(memory) type

    Such commands allow storing values ​​into variables.

    For example, the "storeTitle" command is a memory type command, it only reads out the Title information of the page and stores it in a variable, it does not produce any interaction with the page element itself.

Assertions

(assertion) type

    Such commands are used to verify that a condition actually occurs.

    The three assertion commands are as follows:

l assert: When the assert command fails to execute, the script will stop executing immediately, and subsequent script content will not be executed.

l verify: When the verify command fails to execute, a failure message will be printed in the execution log area of ​​selenium IDE, and then continue to execute the subsequent script content.

l waitFor: The "waitFor" command waits for a condition to actually occur before continuing with the next command.

Ø During the waiting period, the situation defined by the condition occurs, and the script will continue to execute.

Ø During the waiting period, if the condition defined does not occur, the script will print a failure message in the execution log area of ​​selenium IDE, and then continue to execute the subsequent script content.

Ø By default, the upper limit of the judgment condition for timeout is set to 30 seconds, and the upper limit judgment time requirement of timeout can be modified in the Options submenu of Oprions.

 Basic commands of selenium IDE

waitForText、verifyText和assertText

        The waitForText statement is used to determine whether some text is displayed in the interface during test execution. If the specified text is displayed on the interface, the test program will continue to execute; if the specified text is not displayed on the interface after a period of time, the test case will be set to the execution failure state; however, the test script will continue to execute.

        The verifyText statement is used to judge whether the text displayed on the interface is consistent with the expected text when the test is executed. If it is consistent, the test program will continue to execute; if it is inconsistent, the test case will be set to the execution failure state, but the test script will continue to execute. .

        The assertText statement is used to judge whether some text on the interface is consistent with the expected text when the test is executed. If it is consistent, the test program will continue to execute. If it is inconsistent, the test case will be set to the execution failure state and no longer Continue to execute subsequent test scripts.

        Specific use cases are as follows:

        (1) Open selenium IDE and set it to recording state.

        (2), enter in the Base URL input box in selenium IDE

        (3) Enter http://www.sogou.com in the browser and press Enter.

        (4) Right-click on the word "webpage" on the Baidu homepage, and a shortcut menu will pop up. http://www.sogou.com

        (5) Hover the mouse over the "show all available commands" menu item in the shortcut menu to pop up a submenu.

        (6), click the "waitForText css=li.cur > span" menu item.

        (7) Repeat steps 4 to 5, and click the menu item "assertText css=li.cur > span".

        (8) Repeat steps 4-5 and click the menu item "verifyText css=li.cur > span".

        (9), selenium IDE script area generates scripts, as follows:

                            

        (10) After the script is generated, click the "Execute" button, and the script will be executed successfully.

                            

        (11) Change the "web page" in the execution script of the waitForText and verifyText commands to "net ye", and execute it again, but the execution fails. After the execution of waitForText reports an error, the subsequent script continues to execute.                   

                   

        (12) Change the web ye in 11 back to the web page, move the assertText to the top layer, change the web page of assertText to web ye, and execute it again, the script still fails. But after this failure, the latter two scripts were not executed either.

                

        From this verification, the assertion failure of the waitForText and verifyText statements is that the test program will continue to execute their subsequent program code, while assertText will not.


storeTitle and echo commands

        The storeTitle command is mainly used to store the title content of the web page in a variable.

        The echo command is mainly used to print out constant strings and variable strings, especially for outputting the status of scripts when debugging scripts.

        Specific examples are as follows:

        (1) Open the selenium IDE interface and set it to recording state.

        (2) Enter http://www.sogou.com in the Base URL input box in selenium IDE.

        (3) Enter http://www.sogou.com in the address bar of the Firefox browser and press enter.

        (4) Enter the following script in the script editing area:

  • open / command line means visit http://www.sogou.com in Firefox browser
  • The storeTitle title command line means to store the value of the Title attribute of the current web page into a change named title.
  • The echo ${title} command line indicates that the variable value in the title is printed in the Log display area.

        (5) The script is executed successfully, and the result of the echo statement is printed out in the Log area.

            


openWindow and selectWindow commands

        The openWindow command is mainly used to open a new Firefox browser window. There are two parameters after the command, one is the URL to be accessed, and the other is the title attribute value of the page after the URL is opened.

        The selectWindow command is mainly used to select an open window. This command is followed by a parameter that needs to be set to the value of the title attribute of the window to be selected. It takes about 1 second to execute, so when applying, it is best to pause for a while and wait for the program to complete the operation of the selected window.

        Specific examples:

      

        Script logic:

        (1) Open the browser window A in the open command, and automatically visit the home page of http://www.sogou.com.

        (2) Execute the openWindow command to reopen a Firefox browser window B, and automatically access the URL http://www.baidu.com; the value in the openWindow command line is the title attribute of the Baidu homepage.

        (3) Execute the selectWindow command, use the "Baidu, you will know" keyword to select browser window B, and enter the string baidu in the Baidu search box of browser B.

        (4) Execute the selectWindow command, use "Sogou search engine - Internet access starts from Sogou" (the title attribute of the Sogou homepage), select browser window A, and enter sogou in the input box of browser A.

       

Guess you like

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