Node.js zombie.js multiple browser errors

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){
    //console.log("login")

    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.wait().then(function() {

        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?

+4
2

[TypeError: Cannot use 'in' operator to search for 'compareDocumentPosition' in null] , zombie Document, null, , .

, login , . , - wait:

function login(browser) {

    return browser.visit('http://example.com/login').then(function() {
        browser.fill('input[name="email"]', 'example@example.com')
            .fill('input[name="password"]', 'example')
            .pressButton("#login").then(function() {
                // check if h1 tag is there in 7 seconds.
                return browser.wait({waitDuration: '7s', element: "h1"});
            });
    })
}

simpleScenario - wait. 5 .

+1

, . 1.4.1, 2.0 -

0

Source: https://habr.com/ru/post/1530106/


All Articles