2

我是使用 QAF 自动化框架的新手。我遵循了此页面上的文档 - https://qmetry.github.io/qaf/latest/setting_driver_capabilities.html

我的要求是:我必须在我的测试中下载一个文件,下载应该去我项目的下载文件夹,而不是 macbook/test 机器的下载文件夹。

我正在使用 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.capabilities 用于我想要设置的所有功能,如下所示,它也不起作用

 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.capabilities 而不是 chrome.capabilities 没有成功。

以前使用过 QAF 的人可以帮我解决这个问题吗?

4

3 回答 3

4

附加能力值的修正需要很少:

  • chrome选项的关键是chromeOptions
  • 首选项也是需要带有键的映射的选项之一prefs
  • 尝试提供下载目录的绝对路径。

您的附加功能应如下所示(确保没有换行符):

 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

下面的示例显示了如何在使用侦听器进行驱动程序初始化之前为复杂对象附加功能。例如,为了使用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);
    }
于 2017-07-27T03:48:45.643 回答
1

以下设置放在 application.properties 文件中。

对于铬:

driver.name=chromeDriver
chrome.capabilities={"chromeOptions":{"args":["--allow-outdated-plugins","--always-authorize-plugins","--headless --disable-gpu","-disable-extensions"],"prefs":{"profile.default_content_settings.popups":0,"download.default_directory":"C:\\server","credentials_enable_service":false,"profile.password_manager_enabled":false}}}
webdriver.chrome.driver =C:/server/chromedriver.exe

以下设置适用于 IE11

driver.name=iExplorerdriver
system.webdriver.ie.driver = C:/server/IEDriverServer.exe
iexplorer.additional.capabilities={'ignoreProtectedModeSettings':true}
iexplorer.additional.capabilities={'nativeEvents':false}
iexplorer.additional.capabilities={'unexpectedAlertBehaviour':accept}
iexplorer.additional.capabilities={'enablePersistentHover':true}
iexplorer.additional.capabilities={'ignoreZoomSetting':true}
iexplorer.additional.capabilities={'requireWindowFocus':true}
iexplorer.additional.capabilities={"ignoreProtectedModeSettings":"true",'nativeEvents':false,'unexpectedAlertBehaviour':accept,'enablePersistentHover':true,'ignoreZoomSetting':true,'requireWindowFocus':true}
iexplorer.additional.capabilities={'ignoreProtectedModeSettings':true,'nativeEvents':false,'unexpectedAlertBehaviour':accept,'enablePersistentHover':true,'ignoreZoomSetting':true,'requireWindowFocus':true}
于 2020-04-30T06:37:26.680 回答
0

感谢@user861594 回答问题。

我最近发现了一种在 BaseTestCase 类本身而不是在 application.properties 中设置此 chrome 功能的更简单方法。

这就是我所做的,而且效果很好!!

声明你的 filePath = "xyz";

String chromePrefs = "{'acceptSslCerts': true,'chromeOptions':   {'prefs': {'prompt_for_download': false,'download.default_directory': '"+filePath+"'}}}";
      ConfigurationManager.getBundle().setProperty("chrome.additional.capabilities", chromePrefs);

享受自动化!

于 2017-09-02T03:22:07.880 回答