21

I'm looking for a way to Monkey test a website. Something like a browser plugin in which you could define a time interval and non-clicking zones, and then the plugin would start clicking (and possibly other actions) everywhere (except the non-clicking zones or DOM elements) during the specified time interval.

I've searched online and only found this type of tests for iPhone and Android.

fbernardo
  • 10,016
  • 3
  • 33
  • 46

3 Answers3

13

I'd recommend gremlins.js, a "Monkey testing library for web apps and Node.js"

https://github.com/marmelab/gremlins.js

Disclaimer: we wrote it.

François Zaninotto
  • 7,068
  • 2
  • 35
  • 56
  • 1
    it is a magic library, but can you show me how i understand my mogwai error (it just show mowai fps < 10 and i dont known how to fix it) – Makio Jul 08 '14 at 05:38
  • You'll have to use profiling tools, like the Chrome Developer Tools, for that purpose. Gremlins.js just reveals the problems, it's up to you to solve them. – François Zaninotto Aug 14 '14 at 14:21
  • I was looking somewhere in the web to thanks the people who did it. It's like a passion and I'm hours looking tireless my gremlings workings over and over again and my app working 100% with no errors. – Ismael Sep 30 '14 at 18:35
  • 2
    Looks nice, although I don't understand how to use it. Is there a way to invoke the Gremlin's horde from a browser? (I want to test a web app without introducing anything new in the code itself, I can only interact with it from a client (browser). Can I use Gremlins in that case? – Alexandre Dumont Jul 14 '17 at 06:14
  • @FrançoisZaninotto have you ever wrote your own gremlin to test drag and drop functional part of your web-application ? – ventro_art Jan 02 '19 at 12:13
1

If you want to roll your own in Python, you could start with

import json
import random

import selenium

SUBDOMAIN = "your-domain.com/subdomain"
d = selenium.webdriver.Firefox()
d.get("http://" + SUBDOMAIN)

while True:
    try:
        nexturl = random.choice(d.find_elements_by_tag_name("a")).get_attribute("href")
    except selenium.common.exceptions.StaleElementReferenceException:
        pass
    except IndexError:
        d.get(random.choice(SEEN))
    if nexturl and SUBDOMAIN in nexturl and nexturl not in SEEN:
        print(nexturl)
        d.get(nexturl)
        # some test code for each page
        SEEN.append(nexturl)

This starts a browser, loads the URL of your subdomain, and randomly clicks links on the page if the still lead to the subdomain. Write your own code in the while loop to further test each single page.

serv-inc
  • 35,772
  • 9
  • 166
  • 188
1

Selenium allows you to search the DOM elements in a page, and simulate clicks or keyboard events directed to a certain DOM element. That's not quite the same as defining "non-clicking zones" (which would presumably be defined in terms of X/Y coordinates), but it might possibly be even easier this way.

Alex D
  • 29,755
  • 7
  • 80
  • 126
  • Is it fast? I saw it does support recording macros but I want something completely random on ANY page that might appear. And does it emulate events like scrolling, hover, right clicking, typing? – fbernardo Feb 24 '12 at 20:05
  • My experience with Selenium is limited, but from what I've seen, it seems to perform well. You can search the DOM element tree, choose an element randomly, and simulate mouse clicks, double clicks, or keystrokes on it. I'm not sure about right clicks... maybe someone else knows? – Alex D Feb 24 '12 at 20:16
  • 1
    Selenium is simply a framework which lets you script interactions with a browser. The randomness of the 'Monkey' would have to be written by you. We wrote a 'smoke' test that simply grabbed all the links on our page, and if the href had not been visited already, clicked through the link and then kept going recursively until the entire site was visited. This test told us we had no broken links but all that logic was our own custom stuff, selenium was just the tool we used to interact with the website. – Jesse Webb Feb 24 '12 at 20:21
  • JesseWebb, thanks for making that clear. And yes, when I said "you can choose an element randomly", I meant that fbernardo will have to write his own script to select random elements, not that Selenium will do that for him. Do you know if it can simulate right clicks? – Alex D Feb 24 '12 at 21:09
  • Thanks, I was looking for something more simple. I guess I'll just wrap a quick Chrome plugin and upload it to github. I'll leave the question open for a few days hoping for an alternative response. – fbernardo Feb 25 '12 at 14:20
  • Selenium is an awesome tool; if you do a lot of web development, it is well worth your time to learn. And once you write your test scripts you can easily run them against different browsers. But it's really up to you. – Alex D Feb 25 '12 at 15:01