forked from marmelab/gremlins.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 94cd27f
Showing
4 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# WebMonkeyTest | ||
|
||
A library that stress test your frontend application like a monkey on steroids. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>WebMonkeyTest</title> | ||
|
||
<link rel="stylesheet" type="text/css" href="style.css" /> | ||
</head> | ||
|
||
<body> | ||
<a href="/not-here.html">Not here</a> | ||
<a href="/admin/here.html">Here</a> | ||
|
||
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> | ||
<script src="../monkey-test.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
a { | ||
display: block; | ||
float: left; | ||
margin-right: 45px; | ||
|
||
font-size: 35px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/*jslint browser: true*/ | ||
/*global jQuery*/ | ||
|
||
(function ($) { | ||
|
||
"use strict"; | ||
|
||
var MoneyTest = { | ||
config: { | ||
urlPattern: /.+/ | ||
}, | ||
furry: null, | ||
width: null, | ||
height: null, | ||
|
||
init: function () { | ||
this.width = $(window).width(); | ||
this.height = $(window).height(); | ||
|
||
this.furry = setInterval(this.clickEveryWhere.bind(this), 10); | ||
}, | ||
|
||
/** | ||
* Click everywhere on the screen | ||
*/ | ||
clickEveryWhere: function () { | ||
var x = Math.floor(Math.random() * this.width), | ||
y = Math.floor(Math.random() * this.height), | ||
$targetElement = $(document.elementFromPoint(x, y)); | ||
|
||
if (this.canClickOnElement($targetElement)) { | ||
$targetElement.click(); | ||
} | ||
}, | ||
|
||
/** | ||
* Check if the monkey can click on an element | ||
* @param element | ||
* @returns {boolean} | ||
*/ | ||
canClickOnElement: function ($element) { | ||
if ($element[0].tagName !== 'A') { | ||
return true; | ||
} | ||
|
||
return this.config.urlPattern.test($element.attr('href')); | ||
} | ||
}; | ||
|
||
// Start the monkey | ||
$(window).on('load', MoneyTest.init.bind(MoneyTest)); | ||
}(jQuery)); |