testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

Reuse browser instance during test time (not dev time)

Open kennardconsulting opened this issue 2 months ago • 3 comments

What is your Scenario?

The time taken to open a browser instance and initialise TestCafe can be significant (5-10 seconds). For integration test suites with many separate tests, this is around an extra +1 minute for every 6 tests.

What are you suggesting?

It would be great to be able to reuse the existing browser instance to save this startup time. This is similar to what TestCafe Live does, but note I'm talking about saving time when running integration test suites, not during test development time.

What alternatives have you considered?

No response

Additional context

No response

kennardconsulting avatar Oct 15 '25 00:10 kennardconsulting

Hello, it is not fully clear what you mean by open a browser instance and initialise TestCafe By default, TestCafe initializes the browser once and uses it for all tests.

I created a simple project to reproduce the behavior you described, but I did not manage to do so. Could you please take a look at it and configure it so I can reproduce your issue on my side? It will also be helpful if you share a screencast to demonstrate the mentioned behavior. example.zip

Bayheck avatar Oct 17 '25 14:10 Bayheck

Thanks for trying to help! And thanks for all the work you do on TestCafe, it's an awesome tool.

You are correct that, by default, TestCafe initializes the browser once and uses it for all tests.

However, for our integration test suite, we have a lot of tests and in-between each test we need to setup/tear down data on our app server (we are using WildFly and Arquillian for our back-end). TestCafe 'fixtures' are kind of inside-out for our purposes (since they require TestCafe to be 'in charge' of the integration test suite from the client-side, whereas we have JUnit 'in charge' from the server-side). So instead we are running TestCafe multiple times. Each time we: setup on server, re-initialize the browser, run TestCafe, tear down on server.

We have a similar situation for a different integration test suite, using Selenium. But the Selenium API allows us to grab a handle to the browser (and not close it) after the first test, and then load subsequent test URLs into that same browser. Perhaps the TestCafe API could allow that?

In a perfect world, we could just supply a command-line switch to TestCafe, such that it looks for and hooks into an existing running browser instance when starting. This would definitely save browser initialization time. It may also improve TestCafe first-compilation time (i.e. when we see the TestCafe logo and spinner), since the JS would already be JIT-ed.

kennardconsulting avatar Oct 17 '25 21:10 kennardconsulting

Hello @kennardconsulting ,

Thank you for the detailed explanation. I understand your use case. We will take it into account, but at the moment I cannot promise if or when we will address this scenario.

We will update this thread when we've made any progress with this task.

aleks-pro avatar Oct 22 '25 15:10 aleks-pro