Skip to content

Commit

Permalink
Add simple monkey click feature
Browse files Browse the repository at this point in the history
  • Loading branch information
manuquentin committed Oct 21, 2013
0 parents commit 94cd27f
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
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.
16 changes: 16 additions & 0 deletions demo/index.html
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>
7 changes: 7 additions & 0 deletions demo/style.css
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;
}
52 changes: 52 additions & 0 deletions monkey-test.js
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));

0 comments on commit 94cd27f

Please sign in to comment.