I am trying to run some tests where I need to download a file to a specific directory and check the file.
Before downloading the file, I tried to override the desired capabilities using “RunConfiguration.setWebDriverPreferencesProperty” but i seem to be passing the wrong arguments. Please help me with the right args for this function call.
Also let me know if “RunConfiguration.setWebDriverPreferencesProperty()” needs to be called before “WebUI.openBrowser()” statement or it could be a written in a function that is called as a utility whenever needed.
At present, I have used it in the listener as per the below code-
The above suggested code worked. Although I encountered some error. #1 After setting the above Browser capabilities, I used ‘WebUI.openBrowser()’ to launch the browser instance which removed all the capabilities. #2 My download path contained ‘/’ instead of ‘\’ because of which is saw ‘Failed - Download Error’ after clicking the file download button.
Here is the altered code that worked for me-
//Set Browser Capabilities.
String ProjectDirectory=RunConfiguration.getProjectDir()
String DownloadFolderPath1=ProjectDirectory+"/Downloads"
String DownloadFolderPath=DownloadFolderPath1.replace('/', '\\')
String AppURL=GlobalVariable.MyAppURL
Map<String, Object> chromePrefs = new HashMap<String, Object>()
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", DownloadFolderPath)
chromePrefs.put("download.prompt_for_download", false)
chromePrefs.put("plugins.plugins_disabled", "Chrome PDF Viewer");
ChromeOptions options=new ChromeOptions();
//options.addArguments("--headless")
//options.addArguments("--window-size=1920,1080")
options.addArguments("--test-type")
//options.addArguments("--disable-gpu")
options.addArguments("--no-sandbox")
//options.addArguments("--disable-dev-shm-usage")
options.addArguments("--disable-software-rasterizer")
options.addArguments("--disable-popup-blocking")
options.addArguments("--disable-extensions")
options.setExperimentalOption("prefs", chromePrefs)
DesiredCapabilities cap = DesiredCapabilities.chrome()
cap.setCapability(ChromeOptions.CAPABILITY, options)
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true)
System.setProperty("webdriver.chrome.driver", DriverFactory.getChromeDriverPath())
WebDriver driver = new ChromeDriver(cap);
driver.get(AppURL)
driver.manage().window().maximize()
DriverFactory.changeWebDriver(driver)
//After this perform the actions using functions available in "WebUI."
Thank you again for this help, much appreciated !!
Thank you Helene, I had already made the necessary changes (They are present in the code I posted in the reply to Timo_Kuisma2)
I was just highlighting the mistakes I did.
Hi Experts,
I fixed my code for customization in default download path and it worked fine so far, now i have bit different scenario where my file getting downloaded at default path for this case only. please help -
below is image , first i click on Tools and then go for Export, while click on export for fraction of sec new tab gets open in same browser which and forms url with few additional details , like file name and sessions along with mail url and then it download the file.
2020-07-14 13:32:01.503 ERROR k.k.c.m.CustomKeywordDelegatingMetaClass - No signature of method: com.pdf.reader.ReadPdfFromBrowser.setChromeOptions() is applicable for argument types: (java.lang.String) values:
Possible solutions: setChromeOptions(java.io.File)
2020-07-14 13:32:01.511 ERROR c.k.katalon.core.main.TestCaseExecutor - Test Cases/Creation of Quote Fnctionality/Create Domestic Quote - with PDF FAILED.
Reason:
org.codehaus.groovy.runtime.metaclass.MissingMethodExceptionNoStack: No signature of method: com.pdf.reader.ReadPdfFromBrowser.setChromeOptions() is applicable for argument types: (java.lang.String) values:
Possible solutions: setChromeOptions(java.io.File)
I have put my code on custom keyword @Keyword
public WebDriver setChromeOptions(File folder){