我刚开始使用 QAF 自动化框架。我按照本页上的文档 - https://qmetry.github.io/qaf/latest/setting_driver_capabilities.html
我的要求是:我必须在测试中下载一个文件,并且下载应该转到我项目的下载文件夹,而不是 macbook/测试机的下载文件夹。
我正在使用 chromeDriver,并且必须在 QAF 框架内的 application.properties 文件中设置 chrome 功能。我添加了以下内容,但它不起作用
chrome.capabilities.profile.default_content_settings.popups=0
chrome.capabilities.download.default_directory=/downloads
chrome.capabilities.credentials_enable_service=false
chrome.capabilities.profile.password_manager_enabled=false
chrome.capabilities.CapabilityType.ACCEPT_SSL_CERTS=true
chrome.additional.capabilities={"chrome options":{"args":["--headless -
-disable-gpu"]}}
我还尝试直接使用 chrome.additional.capability 来设置我想要设置的所有功能,如下所示,但它也不起作用
chrome.additional.capabilities={"chrome options":{"args":["--allow-
outdated-plugins","--always-authorize-plugins","--headless --disable-
gpu","-disable-extensions"]},"prefs":
[{"profile.default_content_settings.popups":0},
{"download.default_directory":"/downloads"},
{"credentials_enable_service":false},
{"profile.password_manager_enabled":false}]}
当我执行测试时,测试成功运行并通过,但文件被下载到我的 macbook 下载目录,而不是在我使用功能设置的项目特定下载文件夹中。
我尝试使用 chromeDriver.capability 而不是 chrome.capability,但没有成功。
以前使用过 QAF 的人可以帮我解决这个问题吗?
最佳答案
附加功能值方面几乎不需要修正:
- chrome 选项的键是
chromeOptions
- 首选项也是需要使用键
首选项
进行映射的选项之一 - 尝试提供下载目录的绝对路径。
您的附加功能应如下所示(确保没有换行符):
chrome.additional.capabilities={"chromeOptions":{"args":["--allow-
outdated-plugins","--always-authorize-plugins","--headless --disable-
gpu","-disable-extensions"],"prefs":
{"profile.default_content_settings.popups":0,
"download.default_directory":"/usr/workspace/testproject/downloads",
"credentials_enable_service":false,
"profile.password_manager_enabled":false}}}
编辑:
根据驱动程序版本,您可能需要在 Chrome 特定功能中添加 goog
前缀,例如:
chrome.additional.capabilities={"goog:chromeOptions":{"args":["start-maximized","--ignore-certificate-errors"]}}
下面的示例展示了如何在使用监听器初始化驱动程序之前向复杂对象附加功能。例如,为了使用 Firefox 配置文件,您可以使用 qaf driver listener .
@Override
public void beforeInitialize(Capabilities desiredCapabilities) {
FirefoxProfile profile= new FirefoxProfile();
//create and set profile as per need
profile.setPreference( "layout.css.devPixelsPerPx", "0.9" );
((DesiredCapabilities)desiredCapabilities).setCapability(FirefoxDriver.PROFILE, profile);
//you also can provide existing profile name. AFAIK firefoxdriver supports existing profile name as well.
//((DesiredCapabilities)desiredCapabilities).setCapability(FirefoxDriver.PROFILE, "my-profile");
}
@Override
public void beforeInitialize(Capabilities desiredCapabilities) {
ChromeOptions options = new ChromeOptions();
//set options and merge to capabilites
//options.addExtensions(paths);
desiredCapabilities.merge(options);
}
关于java - 使用 QAF 自动化框架在 application.properties 文件中设置 chrome 功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45313983/