How to loop tests in Selenium IDE?

后端 未结 8 1819
生来不讨喜
生来不讨喜 2020-12-13 23:31

I\'ve been testing in Selenium IDE. It\'s pretty easy to use, and I have created some test cases with it. I\'ve been searching Google, trying to find a way to repeat my test

相关标签:
8条回答
  • 2020-12-14 00:07

    Use the Flow Control plug-in for Firefox. After restarting Firefox, use the label command to mark a point in the script, and the gotolabel command to jump there.

    For example:

    enter image description here

    Or if you'd rather see the source code, this is a label:

    <tr>
        <td>label</td>
        <td>start</td>  
        <td></td>
    </tr>
    

    And this causes the execution point to jump back to the label:

    <tr>
        <td>gotolabel</td>
        <td>start</td>
        <td></td>
    </tr>
    

    There are other commands that you can see on the plug-in page, and documented in the Selenium IDE: Flow Control GitHub project.

    0 讨论(0)
  • 2020-12-14 00:08

    as stated in the answer above, install the user extension, which will add loop functionality to Selenium IDE tests. The example below shows a simple loop:

    <tr>
    <td>getEval</td>
    <td>index = 0;</td>
    <td></td>
    </tr>
    <tr>
    <td>while</td>
    <td>index &lt; 10;</td>
    <td></td>
    </tr>
    <tr>
    <td>storeEval</td>
    <td>index</td>
    <td>value</td>
    </tr>
    <tr>
    <td>echo</td>
    <td>${value}</td>
    <td></td>
    </tr>
    <tr>
    <td>getEval</td>
    <td>index++;</td>
    <td></td>
    </tr>
    <tr>
    <td>endWhile</td>
    <td></td>
    <td></td>
    </tr>
    
    0 讨论(0)
  • 2020-12-14 00:08

    Selenium IDE now has flow control. These Control Flow commands work by specifying opening and closing commands to denote a set (or block) of commands.

    Available Commands

    Here are each of the available control flow commands accompanied by their companion and/or closing commands.

    if, else if, else, end times, end do, repeat if while, end

    You can read more about it here:

    https://www.seleniumhq.org/selenium-ide/docs/en/introduction/control-flow/

    0 讨论(0)
  • 2020-12-14 00:12

    This is a sample for sampcop user in order to automate spam complaints using label and goto Label commands:

    1st Login on spamcop.net

    2nd use Report Spam option

    3rd start this script

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head profile="http://selenium-ide.openqa.org/profiles/test-case">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="selenium.base" href="http://www.spamcop.net/sc" />
    <title>testecase</title>
    </head>
    <body>
    <table cellpadding="1" cellspacing="1" border="1">
    <thead>
    <tr><td rowspan="1" colspan="3">testecase</td></tr>
    </thead><tbody>
    
    <tr>
        <td>label</td>
        <td>target1</td>
        <td></td>
    </tr>
    <tr>
        <td>clickAndWait</td>
        <td>link=Report Now</td>
        <td></td>
    </tr>
    <tr>
        <td>clickAndWait</td>
        <td>//input[@value='Send Spam Report(s) Now']</td>
        <td></td>
    </tr>
    <tr>
        <td>gotoLabel</td>
        <td>target1</td>
        <td></td>
    </tr>
    </tbody></table>
    </body>
    </html>
    
    0 讨论(0)
  • 2020-12-14 00:14

    I'm new to Selenium (just started using it a few minutes ago). After a quick Google search for "selenium loop" this stackoverflow.com question came up. I immediately jumped into the extension and started using loops. The accepted answer is very helpful. However, I wanted to point out something else for others that are new to selenium (and stumble on this page).

    I created a simple test for a simple web page. I added a loop so that the test would run indefinitely (until I paused/stopped it). However, I noticed that by doing this, the Runs/Failures counters within the Selenium GUI do not increment with each loop (I am guessing because a single test case was never running to completion, it was just looping indefinitely). So I dug a bit further. My goal was to leave the same test running for a long time (a few hours, or possibly overnight) to see if there were any failures (I'm chasing an intermittent bug at the moment).

    The simplest way (for me, after a few minutes of searching/experimenting) was to do the following (likely no plugins needed, although the attached plugin is definitely helpful if you want to run a few small loops within a test case):

    • save the test case to a text file
    • save the test suite to a text file
    • open the test suite text file in a text editor
    • copy and paste the test case multiple times within the test suite (for example, a thousand times)
    • then open the test suite in Selenium, and run the test suite

    Now I have the same simple test suite running many times, and the Runs/Failures counters are incrementing as expected (without the need for any loops).

    0 讨论(0)
  • 2020-12-14 00:15

    Do this:

    1. Download this js file: https://github.com/darrenderidder/sideflow/blob/master/sideflow.js
    2. Launch Selenium IDE from Firefox and open the options menu.
    3. Upload the .js file to the "Selenium Core extensions (user-extensions.js)" field.

    The js file provides goto, gotoIf and while loop functionality in Selenium IDE. The example below shows a simple loop:

    <tr>
        <td>getEval</td>
        <td>index = 0;</td>
        <td></td>
    </tr>
    <tr>
        <td>while</td>
        <td>index &lt; 10;</td>
        <td></td>
    </tr>
    <tr>
        <td>storeEval</td>
        <td>index</td>
        <td>value</td>
    </tr>
    <tr>
        <td>echo</td>
        <td>${value}</td>
        <td></td>
    </tr>
    <tr>
        <td>getEval</td>
        <td>index++;</td>
        <td></td>
    </tr>
    <tr>
        <td>endWhile</td>
        <td></td>
        <td></td>
    </tr>
    
    0 讨论(0)
提交回复
热议问题