marmelab / gremlins.js

Monkey testing library for web apps and Node.js
https://marmelab.com/blog/2020/06/02/gremlins-2.html
MIT License
9.03k stars 424 forks source link

Uncaught RangeError: Chance: Min cannot be greater than Max. #47

Closed danb235 closed 10 years ago

danb235 commented 10 years ago

We got gremlins up and running (neat project, btw) but are encountering an error after a second or two of testing. I was hoping for some insight.

Uncaught RangeError: Chance: Min cannot be greater than Max. gremlins.min.js?bust=1395340612814:22
f gremlins.min.js?bust=1395340612814:22
u.natural gremlins.min.js?bust=1395340612814:22
u.pick gremlins.min.js?bust=1395340612814:22
l gremlins.min.js?bust=1395340612814:22
u gremlins.min.js?bust=1395340612814:22
s gremlins.min.js?bust=1395340612814:22
t gremlins.min.js?bust=1395340612814:22
p gremlins.min.js?bust=1395340612814:22
(anonymous function)

Here is a screenshot of my chrome dev console with the error:

screen shot 2014-03-20 at 11 37 16 am

Any suggestions?

fzaninotto commented 10 years ago

Can't reproduce. Could you share the test page you run gremlins on? Could you paste the detailed error stack when using the non-minified version of gremlins?

alexeygolev commented 10 years ago

same thing here

fzaninotto commented 10 years ago

Same comment: can you help me reproduce the bug?

gabehayes commented 10 years ago

After rebuilding the js file with the optimize property set to none, then running the test, here is the stack for the error:

Uncaught RangeError: Chance: Min cannot be greater than Max. gremlins.min.js?bust=1395780871173:481
testRange gremlins.min.js?bust=1395780871173:481
Chance.natural gremlins.min.js?bust=1395780871173:603
Chance.pick gremlins.min.js?bust=1395780871173:662
fillSelect gremlins.min.js?bust=1395780871173:2002
formFillerGremlin gremlins.min.js?bust=1395780871173:1975
iterator gremlins.min.js?bust=1395780871173:2564
executeInSeries gremlins.min.js?bust=1395780871173:2576
executeNext gremlins.min.js?bust=1395780871173:2789
(anonymous function) gremlins.min.js?bust=1395780871173:2791

Looks like the error is being thrown by this method in chancejs:

    function testRange(test, errorMessage) {
        if (test) {
            throw new RangeError(errorMessage);
        }
    }

Which means that the passed options here are invalid?

    // NOTE the max and min are INCLUDED in the range. So:
    //
    // chance.natural({min: 1, max: 3});
    //
    // would return either 1, 2, or 3.

    Chance.prototype.natural = function (options) {

        // 9007199254740992 (2^53) is the max integer number in JavaScript
        // See: http://vq.io/132sa2j
        options = initOptions(options, {min: 0, max: MAX_INT});

        testRange(options.min > options.max, "Chance: Min cannot be greater than Max.");

        return Math.floor(this.random() * (options.max - options.min + 1) + options.min);
    };

Happens every time we launch. Loading the module via requirejs and launching with gremlins.createHorde().unleash().

After looking at the stack, please let me know if there are any specific variables you care for us to log.

JaSpr commented 10 years ago

where is MAX_INT getting defined?

gabehayes commented 10 years ago

I haven't traced exactly where it is getting defined, yet, but it's value is as the comment indicates: 9007199254740992

image

The issue definitely seems to be with chance's handling of picking a random item. For some reason at a given moment, element.querySelectorAll('option') returns no items:

image

Then, calling pick (with the count argument not defined), it is setting the max value to be -1:

image

Which then leads to this error being called by chance's natural method, because the range is invalid:

image

fzaninotto commented 10 years ago

Thanks, you helped me find a bug in case a page contains an empty select. Should be fixed by #52.

gabehayes commented 10 years ago

:+1: awesome work, thanks for taking care of that.