简体   繁体   中英

Selenium with Node.js: can't stop loop execution

I've wrote some test with Selenium and Node.js, but when I run that test, it never ends.

My code is:

driver.wait(function () {
    return driver.executeScript('return document.readyState').then(function (readyState) {
        if (readyState === 'complete') {
            doTest();
            // HERE I WANT TO EXIT
        };
    });
});

The method doTest() is called infinitely times.

And where now you can see " HERE I WANT TO EXIT " I tried to stop the loop with:

return true;
return false;
resolve();
driver.close();
driver.quit();

But none worked, any help please?

It's unclear why return true; does not work. The possible issue is that doTest() fails with some exception which is propagated by the wait. Did you check that your code get to the line "HERE I WANT TO EXIT"?

I would suggest either adding a console.log after doTest() to make sure the doTest() is completed successfully

or make doTest() return true if everything is ok and false if there was any exception and make it as

    if (readyState === 'complete') {
        return doTest();
    };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM