I want to enter a web application and start a simulation - for example, visit some pages and change some values.
My code is:
var Browser = require("zombie");
fail = function (error) {console.log(error)}
function login(browser){
return browser.visit("http://example.com/login").then(function(){
browser.fill('input[name="email"]', 'example@example.com')
browser.fill('input[name="password"]', 'example')
browser.pressButton("#login")
return browser.wait().then(function() {
return browser;
})
})
}
function simpleScenario(browser, id) {
browser.visit("http://example.com/next_page")
.then(function () {
browser.wait(function() {
var n = 5;
var step = function () {
var period = 100 + n;
browser.evaluate("m.productvalue(" + period + ")");
if(n > 0) {
setTimeout(step, 1000);
}
n--;
};
step()
})
.fail(fail)
});
}
function sampleScenario(id) {
var browser = new Browser({debug:false})
login(browser)
.then(function () {
console.log("logged in");
simpleScenario(browser, id);
})
.fail(fail);
}
function loadTest(numberOfThreads) {
for(i = 0; i < numberOfThreads; i++) {
sampleScenario(i)
}
}
loadTest(50);
My problem : when I execute my function in the loop once, everything is fine, but when numberOfThreads is 10 or more, I get the error message:
[TypeError: cannot use the 'in' operator to search for 'compareDocumentPosition' in null]
It seems that if there are many browser objects, then the zombies will not cope with this. Maybe the zombie library is too slow to work with many threads? Can I do the same without using Zombie.js, only with node.js? Or maybe some part of my script should be optimized to work with Zombie.js?