Setting chrome capabilities in application.properties file using QAF Automation framework is not working

穿精又带淫゛_ 提交于 2021-02-08 05:17:46

问题


I'm new to using QAF Automation framework. I followed the documentation on this page - https://qmetry.github.io/qaf/latest/setting_driver_capabilities.html

My requirement is: I have to download a file in my test and the download should go to my project's download folder and not on macbook/test machine's download folder.

I'm using chromeDriver and have to set chrome capabilities in the application.properties file within QAF framework. I added the below but it's not working

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"]}}

I also tried directly using chrome.additional.capabilities for all the capabilities I wanted to set, like below, and it didn't work either

 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}]}

When I execute my test, the test runs successfully and passes but the file is downloaded to my macbook download directory and not within my project specific download folder I've set using capabilities.

I tried using chromeDriver.capabilities instead of chrome.capabilities with no success.

Can anyone who used QAF before, help me with solving this issue?


回答1:


Few correction needs in additional capability value:

  • Key for chrome options is chromeOptions
  • preferences is also one of the option which requires map with key prefs
  • Try providing absolute path for download directory.

Your additional capability should look like below (make sure there is no line break):

 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}}}

Refer chromeOptions-object

Below example shows how you can append capability with complex object before driver initialization using listener. For instance, in order to use Firefox profile you can utilize 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"); 
} 



回答2:


Thanks @user861594 for answering the question.

I recently found out an easier way to set this chrome capabilities in the BaseTestCase class itself and not in application.properties.

Here is what I did and it worked wonderfully!!

Declare your filePath = "xyz";

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

Enjoy automating!




回答3:


Below settings are placed in application.properties file.

For Chrome:

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

Below setting worked for me for 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}


来源:https://stackoverflow.com/questions/45313983/setting-chrome-capabilities-in-application-properties-file-using-qaf-automation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!