java - 使用 QAF 自动化框架在 application.properties 文件中设置 chrome 功能不起作用

标签 java selenium selenium-chromedriver qaf

我刚开始使用 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}}}

引用chromeOptions-object

编辑: 根据驱动程序版本,您可能需要在 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/

相关文章:

java - 如何从 Android Studio 上的 txt 文件中获取一行

java - 如何在 Java 中解析 "Event XML"?

java - Selenium HtmlUnitDriver 中的未知主机

java - React.js 服务器端渲染与 Java [无 Node.js]

java - 如何根据需要重新调整数组的尺寸

javascript - Selenium IDE javascript 去掉最后一个字符

django - 将存储过程加载到 Django 单元测试数据库中的最佳方法是什么?

Selenium、FluentAutomation 和 NUnit - 如何为每个测试用例切换浏览器?

ruby - 在 W3C 模式下(Selenium::WebDriver::Error::UnknownCommandError)无法在 Cucumber Ruby 中使用 Selenium ChromeDriver 调用非 W3C 标准命令

java - 成功执行测试后,Selenium 测试抛出错误