| 704 | |
| 705 | @classmethod |
| 706 | def browser_open(cls, url): |
| 707 | assert has_browser() |
| 708 | browser_args = EMTEST_BROWSER |
| 709 | parallel_harness = worker_id is not None |
| 710 | |
| 711 | config = get_browser_config() |
| 712 | if not config and EMTEST_BROWSER_AUTO_CONFIG: |
| 713 | exit_with_error(f'EMTEST_BROWSER_AUTO_CONFIG only currently works with firefox, chrome and safari. EMTEST_BROWSER was "{EMTEST_BROWSER}"') |
| 714 | |
| 715 | # Prepare the browser data directory, if it uses one. |
| 716 | if EMTEST_BROWSER_AUTO_CONFIG and config and hasattr(config, 'data_dir_flag'): |
| 717 | logger.info('Using default CI configuration.') |
| 718 | browser_data_dir = DEFAULT_BROWSER_DATA_DIR |
| 719 | if parallel_harness: |
| 720 | # Running in parallel mode, give each browser its own profile dir. |
| 721 | browser_data_dir += '-' + str(worker_id) |
| 722 | |
| 723 | # Delete old browser data directory. |
| 724 | if WINDOWS: |
| 725 | # If we cannot (the data dir is in use on Windows), switch to another dir. |
| 726 | while not force_delete_dir(browser_data_dir): |
| 727 | browser_data_dir = increment_suffix_number(browser_data_dir) |
| 728 | else: |
| 729 | force_delete_dir(browser_data_dir) |
| 730 | |
| 731 | # Recreate the new data directory. |
| 732 | os.mkdir(browser_data_dir) |
| 733 | |
| 734 | if WINDOWS: |
| 735 | # Escape directory delimiter backslashes for shlex.split. |
| 736 | browser_data_dir = browser_data_dir.replace('\\', '\\\\') |
| 737 | config.configure(browser_data_dir) |
| 738 | browser_args += f' {config.data_dir_flag}"{browser_data_dir}"' |
| 739 | |
| 740 | browser_args = shlex.split(browser_args) |
| 741 | if hasattr(config, 'launch_prefix'): |
| 742 | browser_args = list(config.launch_prefix) + browser_args |
| 743 | |
| 744 | logger.info(f'Launching browser: {browser_args}') |
| 745 | |
| 746 | if (WINDOWS and is_firefox()) or is_safari(): |
| 747 | cls.launch_browser_harness_with_proc_snapshot_workaround(parallel_harness, config, browser_args, url) |
| 748 | else: |
| 749 | cls.browser_procs = [subprocess.Popen(browser_args + config.open_url_args(url))] |
| 750 | |
| 751 | @classmethod |
| 752 | def launch_browser_harness_with_proc_snapshot_workaround(cls, parallel_harness, config, browser_args, url): |