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 tests automatically. I've seen a solution with gotolabel, while loops, etc. But I couldn't make any of them works. Can someone give me a tip on how to loop my test n
times, or loop forever. I appreciate any help.
问题:
回答1:
Do this:
- Download this js file: https://github.com/darrenderidder/sideflow/blob/master/sideflow.js
- Launch Selenium IDE from Firefox and open the options menu.
- 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 < 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>
回答2:
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 < 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>
回答3:
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).
回答4:
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:
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.
回答5:
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>
回答6:
Your test suite file is just an HTML file, so just do the following:
<tr><td><a href="testCase1.html">testCase1</a></td></tr>
<tr><td><a href="sameStep.html">sameStep</a></td></tr>
<tr><td><a href="testCase2.html">testCase1</a></td></tr>
<tr><td><a href="sameStep.html">sameStep</a></td></tr>
回答7:
I found this tutorial to be much more helpful, because some of the above responses are simply "go to" solutions, instead of iterative looping constructs:
http://www.software-testing-tutorials-automation.com/2013/07/example-of-while-and-endwhile-loop.html