This theme seems to be an endless one for me. A test can fail in so many ways, leaving browsers open with open modal dialogues, file dialogues, etc. For now, I have ended up with starting all tests with trying to close all existing browsers, then killing any browser processes left. But some times that leaves some browsers (like Chrome) to start up with warnings, which then have to be handled… It feels like a never ending challenge…
And yes, I know, tests should always leave the environment intact. But they doesn't

Do you have an effective way of cleaning up? Are you using some kind of sandboxing or virtualization to start from scratch each time?
All good ideas welcomed…
(Primarily doing browser based tests, stored In GitLab, run on a virtual server via Jenkins).
Best Regards
Bo