Use the loop control function when using selenium to test the web interface

Source: Internet
Author: User

Selenium is a good web interface testing framework. However, its functions are also inadequate. For example, it is not supported in selenium IDE.ProgramControl statement. The following describes how to add the program control function in selenium IDE.

1) download the selenium plug-in (sideflow. JS ):

If you do not want to downloadCodeYou can also save it to the local machine.

VaR gotolabels ={}; var whilelabels ={}; // overload the original selenium reset functionselenium. prototype. reset = function () {// reset the labels this. initialiselabels (); // proceed with original reset code this. defaulttimeout = selenium. default_timeout; this. browserbot. selectwindow ("null"); this. browserbot. resetpopups ();} selenium. prototype. initialiselabels = function () {gotolabels ={}; whilelab Els = {ends :{}, whiles :{}}; var command_rows = []; var numcommands = testcase. commands. length; For (VAR I = 0; I <numcommands; ++ I) {var x = testcase. commands [I]; command_rows.push (x);} var cycles = []; for (VAR I = 0; I <command_rows.length; I ++) {If (command_rows [I]. type = 'command') Switch (command_rows [I]. command. tolowercase () {Case "label": gotolabels [command_rowspolici#.tar get] = I; break; Case "while": Case "endwhile": cycles. push ([command_rows [I]. command. tolowercase (), I]) break;} var I = 0; while (cycles. length) {if (I> = cycles. length) {Throw new error ("non-matching while/endwhile found");} switch (cycles [I] [0]) {Case "while ": if (I + 1 <cycles. length) & ("endwhile" = cycles [I + 1] [0]) {// pair found whilelabels. ends [cycles [I + 1] [1] = cycles [I] [1]; whilelabels. whiles [cycles [I] [1] = cycles [I + 1] [1]; cycles. splice (I, 2); I = 0;} else ++ I; break; Case "endwhile": ++ I; break ;}} selenium. prototype. continuefromrow = function (row_num) {If (row_num = undefined | row_num = NULL | row_num <0) {Throw new error ("invalid row_num specified. ");} testcase. debugcontext. debugindex = row_num;} // do nothing. simple labelselenium. prototype. d Olabel = function () {}; selenium. prototype. dogotolabel = function (Label) {If (undefined = gotolabels [label]) {Throw new error ("specified label" + label + "'is not found. ");} This. continuefromrow (gotolabels [label]) ;}; selenium. prototype. dogoto = selenium. prototype. dogotolabel; selenium. prototype. dogotoif = function (condition, label) {If (eval (condition) This. dogotolabel (Label);} Sel Enium. Prototype. dowhile = function (condition) {If (! Eval (condition) {var last_row = testcase. debugcontext. debugindex; var end_while_row = whilelabels. whiles [last_row]; If (undefined = end_while_row) throw new error ("corresponding 'endwhile 'is not found. "); this. continuefromrow (end_while_row) ;}} selenium. prototype. doendwhile = function () {var last_row = testcase. debugcontext. debugindex; var while_row = whilelabels. ends [last_row]-1; if (undefined = while_row) throw new error ("corresponding 'wait' is not found. "); this. continuefromrow (while_row );}

: Https://

2) configure the plug-in selenium. As shown in, add sideflow. js to the "Selenium core extensions (user-extensions.js)" text box and restart selenium IDE.

3) in this way, you can use Process Control in selenium, such

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: 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.