Reputation: 32321
This is my javascript , i am manually writing a Stress Test for my web site by making 4 virtual users .
<html>
<head>
<script type="text/javascript">
function test() {
var myStringArray = [ "user1", "user2" , "user3" , "user4" ]
var len = myStringArray.length;
for (var i=0; i<len; ++i) {
document.inform.cid.value=myStringArray[0];
document.inform.pw.value="xxxxxx";
document.inform.submit();
}
}
</script>
</head>
<body>
<form name="inform" method="post" target="newWin" action="http://localhost:8080/logon?debug=1">
<input type="text" name="cid" >
<input type="password" name="pw" />
<input type="hidden" name="throttle" value="999" />
<input type="submit" value="go" onclick="test()">
</form>
</body>
</html>
When i ran the above program , its submitting only once , that is with the last user .
My requirement is that , i want to open 4 new windows with 4 virtual users .
Please let me know , how can i open 4 new windows with 4 virtual users .
Thanks .
Upvotes: 0
Views: 80
Reputation: 66663
You need to give different values for the form's target
attribute for them to open up in new windows/tabs:
For example:
for (var i=0; i<len; ++i) {
document.inform.target = i; // a different target each time
document.inform.cid.value=myStringArray[0];
document.inform.pw.value="xxxxxx";
document.inform.submit();
}
Check this demo (uses jQuery but the concepts are the same): http://jsfiddle.net/dvJMx/
Edit
to introduce a delay between each submit, you can do something like:
Demo: http://jsfiddle.net/dvJMx/1/
var windowCounter = 1; // make sure you declare this globally
for (var i=0; i<len; ++i) {
setTimeout(function() {
document.inform.target = windowCounter++; // a different target each time
document.inform.cid.value=myStringArray[0];
document.inform.pw.value="xxxxxx";
document.inform.submit();
}, i*1000); // change 1000 to the interval you need in milliseconds
}
Upvotes: 1