selenium Race Condition ? (ECONNREFUSED connect ECONNREFUSED 127.0.0.1:xxxxx)

Viewed 88
const { Builder, By, Key } = require('selenium-webdriver');
const fs = require('fs');

const categories = fs.readFileSync('./categories.txt').toString().split("\n");
const list = fs.readFileSync('./list.txt').toString().split("\n");

async function check(check, index) {
    let driver = await new Builder()
        .forBrowser('chrome')
        .build();

    await driver.manage().setTimeouts({
        implicit: 3000,
        pageLoad: 3000,
        script: 3000
    });

    try {
        console.log(`now list: ${list[index]}`)
        await driver.get(`http://localhost/${check}`);

        return new Promise(async (resolve, reject) => {
            resolve(true)
        })
    } catch (err) {
        console.log(err);
    } finally {
        await driver.quit();
    }
}

(async () => {
    var index = 0;
    var i = 0;

    while (true) {
        if (index > list.length) {
            index = 0;
        }

        var idx = i * 2;
        var first = categories[idx];
        var second = categories[idx + 1];

        if (first !== undefined && second !== undefined) {
            await Promise.all([check(first, index), check(second, index+1)])
        } else {
            if (first !== undefined) {
                await check([first, index]);
            } else {
                console.log('end');
                break
            }
        }

        i += 2;
        index += 2;
    }
})();

I have 20,000 data, and I want to call a specific function every two in order.

But there seems to be something very wrong.

Want: When 'selenium' runs on the 20th line, It seems to run on the same 'port' under competition conditions. I found this error. Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:49809

I'm totally Newbie here. I need your help!

0 Answers
Related