Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch browser through testcafe without test

I want to use testcafe to start browsers available through internal end external browser providers. I don't want any testing functionality. But I want to be able to use takeScreenshot, resizeWindow, etc.

Here is my code.

const pool = require("./node_modules/testcafe/lib/browser/provider/pool.js");

pool.getProvider("chrome").then((provider) => {
    const plugin = provider.plugin;

    console.log("open")

    plugin.openBrowser("foo", "http://google.de", "chrome").then(() => {
        console.log("done");

    }).catch(console.warn);;

    console.log("early");

}).catch(console.warn);

If I run or debug the file with this code, the open browser promise is never resolved. The console prints open and early and then the program exits.

If I copy and paste the code into an interactive node shell, the browser gets started. (I get an exception that connection is null but this code is never run if I start the file.

What am I doing wrong?

UPDATE: This is the code that uses async/await, but does not work either:

const pool = require("../node_modules/testcafe/lib/browser/provider/pool.js");

(async () => {
    const provider = await pool.getProvider("chrome");
    const plugin = provider.plugin;
    await plugin.openBrowser("foo", "http://google.de", "chrome");
    console.log("done");
})();
like image 372
htho Avatar asked Mar 18 '26 09:03

htho


1 Answers

We advise against using this internal API as it can be changed at any time without notification. You can use the testcafe-browser-tools module instead.  

The plugin.openBrowser method is async. So, you need to await the result of the method execution. Please see TestCafe's runBrowser code for more details.

like image 158
mlosev Avatar answered Mar 21 '26 03:03

mlosev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!