Chromedriver 版本 121 及以上版本在隐身模式下下载文件时强制显示“另存为”窗口

问题描述 投票:0回答:1

我正在使用 Webdriverio 来测试具有登录功能的 Web 应用程序,并且并行运行测试套件需要隐身模式。

但是 chromeDirver 121+ 在隐身模式下运行时,下载文件会提示“另存为”对话框出现在浏览器会话中,并且不会下载文件。

对于这个版本的升级,我是否缺少 chrome 的首选项或参数?

我使用的ChromeOptions如下(wdio conf格式):

            'goog:chromeOptions': {
                prefs: {
                    download: {
                        default_directory: downloadDir,
                        prompt_for_download: false,
                        extensions_to_open: 'applications/pdf',
                        directory_upgrade: true
                    },
                    savefile: {
                        default_directory: downloadDir
                    },
                    profile: {
                        default_content_setting_values: {
                            automatic_downloads: 1,
                        },
                        default_content_settings: {
                            popups: 0,
                        },
                    },
                    plugins: {
                        plugins_disabled: 'Chrome PDF Viewer',
                        always_open_pdf_externally: true,
                    },
                },
                args: [
                    '--window-size=1800,1500',
                    '--incognito',
                    '--print-to-pdf',
                    '--allow-running-insecure-content',
                    '--ignore-certificate-errors',
                    '--disable-features=DownloadBubble,DownloadBubbleV2',
                    '--no-sandbox',
                ],
                localState: {
                    browser: {
                        enabled_labs_experiments: ["download-bubble-v2@2", "download-bubble@2"],
                    },
                },
            }

此配置适用于120,升级到121是突破点。 当我在版本 121 中遇到问题时,我将以下块添加到 chromeOptions

                    savefile: {
                        default_directory: downloadDir
                    },

期望将其传递到文件资源管理器,但这没有任何区别。

附注 这种行为在以前的版本中已经出现,我在升级到 117 时添加了“localState”块,然后在升级到 119 时添加了“--disable-features”参数,两者都是为了修复完全相同的“另存为”问题。

google-chrome automated-tests webdriver-io chrome-options
1个回答
0
投票

即使我遇到了同样的问题,但可以通过使用轻松解决

browser.cdp('页面', setDownloadBehavior', { 行为:'允许', downloadPath: //你的路径 });

© www.soinside.com 2019 - 2024. All rights reserved.