Skip to content

Commit 49fdd76

Browse files
authored
Add -wait-for-browser for Linux and macOS as well. (#25658)
In previous PR #25644 I added `-wait-for-browser` use on Windows to help single-threaded Windows runner not leave behind stale browser windows. For some reason, it was not passing on CircleCI on Linux. Testing this again to see what the failure is. In local testing with a test script: ```py import subprocess, sys, time cmd = ['C:\\Program Files\\Mozilla Firefox\\firefox.exe', '-new-instance', '-profile', sys.argv[1], '-wait-for-browser', 'https://wiki.mozilla.org/Firefox/CommandLineOptions'] print('Launching browser: ' + ' '.join(cmd)) proc = subprocess.Popen(cmd) for i in range(10): if proc.poll() is not None: print('Oops: process already quit, so we did not get a process handle to keep track of the browser instance.') sys.exit(0) time.sleep(1) if proc.poll() is None: print('terminating browser process') proc.terminate() time.sleep(2) if proc.poll() is None: print('terminating did not work. killing browser process') proc.kill() print('All done') ``` I am unable to find a behavioral difference between Windows and Linux. So testing this out again on CircleCI.
1 parent 1f463d1 commit 49fdd76

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

test/common.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,29 @@ class ChromeConfig:
134134
def configure(data_dir):
135135
"""Chrome has no special configuration step."""
136136

137+
@staticmethod
138+
def open_url_args(url):
139+
return [url]
140+
137141

138142
class FirefoxConfig:
139143
data_dir_flag = '-profile '
140-
default_flags = ('-new-instance', '-wait-for-browser') if WINDOWS else ('-new-instance',)
144+
default_flags = ('-new-instance', '-wait-for-browser')
141145
headless_flags = '-headless'
142146
executable_name = utils.exe_suffix('firefox')
143147

144148
@staticmethod
145149
def configure(data_dir):
146150
shutil.copy(test_file('firefox_user.js'), os.path.join(data_dir, 'user.js'))
147151

152+
@staticmethod
153+
def open_url_args(url):
154+
# Firefox is able to launch URLs by passing them as positional arguments,
155+
# but not when the -wait-for-browser flag is in use (which we need to be
156+
# able to track browser liveness). So explicitly use -url option parameter
157+
# to specify the page to launch. https://bugzil.la/1996614
158+
return ['-url', url]
159+
148160

149161
class SafariConfig:
150162
default_flags = ('', )
@@ -160,6 +172,10 @@ class SafariConfig:
160172
def configure(data_dir):
161173
""" Safari has no special configuration step."""
162174

175+
@staticmethod
176+
def open_url_args(url):
177+
return [url]
178+
163179

164180
# Special value for passing to assert_returncode which means we expect that program
165181
# to fail with non-zero return code, but we don't care about specifically which one.
@@ -2059,7 +2075,7 @@ def browser_open(cls, url):
20592075
if (WINDOWS and is_firefox()) or is_safari():
20602076
cls.launch_browser_harness_with_proc_snapshot_workaround(parallel_harness, config, browser_args, url)
20612077
else:
2062-
cls.browser_procs = [subprocess.Popen(browser_args + [url])]
2078+
cls.browser_procs = [subprocess.Popen(browser_args + config.open_url_args(url))]
20632079

20642080
@classmethod
20652081
def launch_browser_harness_with_proc_snapshot_workaround(cls, parallel_harness, config, browser_args, url):
@@ -2076,7 +2092,7 @@ def launch_browser_harness_with_proc_snapshot_workaround(cls, parallel_harness,
20762092
procs_before = list_processes_by_name(config.executable_name)
20772093

20782094
# Browser launch
2079-
cls.browser_procs = [subprocess.Popen(browser_args + [url])]
2095+
cls.browser_procs = [subprocess.Popen(browser_args + config.open_url_args(url))]
20802096

20812097
# Give the browser time to spawn its subprocesses. Use an increasing
20822098
# timeout as a crude way to account for system load.

0 commit comments

Comments
 (0)