Skip to content

Conversation

brendandahl
Copy link
Collaborator

Handy option to inspect the browser after the test has run.

Handy option to inspect the browser after the test has run.
@brendandahl brendandahl requested review from juj and sbc100 September 23, 2025 23:25
def browser_terminate(cls):
if EMTEST_KEEP_OPEN:
assert len(cls.browser_procs) == 1, '--keep-open only supports one browser process'
cls.browser_procs[0].wait()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But will this not also keep the test running open ? Why not just exit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least for chrome the browser will be killed when python exits.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, maybe add a comment there, something like "# Keep the python process alive until the browser is closed. This also means that http server will keep runnning"

Alternatively we could exit the python process after orphaning the browser, but then I guess that server would also go down.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least for chrome the browser will be killed when python exits.

Firefox browser windows stay open after python exits, both on Windows and Linux.

@classmethod
def browser_terminate(cls):
if EMTEST_KEEP_OPEN:
assert len(cls.browser_procs) == 1, '--keep-open only supports one browser process'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Windows on Firefox case, len(cls.browser_procs) > 1 even if there is only one test running.

Also, this failure seems like a configuration/setup failure, rather than an after-the fact failure?

I.e. if I run EMTEST_CORES=128 test/runner browser --keep-open, then this will still launch all the 128 browsers, and only when they are all being shut down at the very end of the test (or if one test fails), then that Worker will assert fail about this --keep-open not being compatible with multithreaded runs?

So maybe a better check might be to move this assert earlier when the test suite is starting, e.g. after the parallel_testsuite.NUM_CORES variable has been set, and verify that NUM_CORES==1?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of a half baked feature. I really just use it for running one test and debugging. I can move the asserts around to be earlier and only support single tester mode.

def browser_terminate(cls):
if EMTEST_KEEP_OPEN:
assert len(cls.browser_procs) == 1, '--keep-open only supports one browser process'
cls.browser_procs[0].wait()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about

for p in cls.browser_procs:
  p.wait()

?

parser.add_argument('--browser-auto-config', type=bool, default=True,
help='Use the default CI browser configuration.')
parser.add_argument('--keep-open', action='store_true',
help='Keep the browser open after tests have run.', default=None)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current form, this might not be accurate?

Is the idea to be able to run only a single fixed test with this?

I.e. test/runner browser.test_my_failing_test --keep-open ?

Or to be able to run multiple tests, and to be able to fail on first failing one?

Currently browser.terminate() will be called if a test times out in the suite? Is that intended to interact with this --keep-open?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants