I'm trying to write a test case in robot framework to download an excel file automatically from a web-site. I want to set preferences for my browser using robot scripts to download files automatically in my desired destination directory without asking me!
I have tried this solution; but it didn't work.
I also tried to set an existing firefox profile as this says which works fine, but I want to be capable of automatically adjusting preferences.
Any idea?
As @Sachin said I wrote a python script to set preferences for FireFox as well:
from selenium import webdriver
class WebElement(object):
@staticmethod
def create_ff_profile(path):
fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList", 2)
fp.set_preference("browser.download.manager.showWhenStarting", False)
fp.set_preference("browser.download.dir", path)
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", 'application/csv')
fp.update_preferences()
return fp
And used it in Robot scenario:
*** Settings ***
Library Selenium2Library
Library Selenium2LibraryExtensions
Library OperatingSystem
Library ../../../Libraries/WebElement.py
*** Variables ***
${profileAddress} C:\\Users\\user\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\VdtJKHal.default
${destinationUrl} http://www.principlesofeconometrics.com/excel.htm
${browserType} firefox
${downloadDir} C:\\Users\\user\\Desktop
${acceptedTypes} text/csv/xls/xlsx
${itemXpath} //*[text()="airline"]
*** Test Cases ***
My Test Method
log to console Going to open browser with custome firefox profile!
${profile} = create_ff_profile ${downloadDir}
Open Browser ${destinationUrl} ${browserType} ff_profile_dir=${profile}
Maximize Browser Window
Click Element xpath=${itemXpath}
Sleep 10
Close Browser
But I got error TypeError: coercing to Unicode: need string or buffer, FirefoxProfile found
in method _make_browser
of library _browsermanagement.py
.
I edited the code and removed return fp
and then changed the Robot test case like this:
And used it in Robot scenario:
*** Test Cases ***
My Test Method
log to console Going to open browser with custome firefox profile!
create_ff_profile ${downloadDir}
Open Browser ${destinationUrl} ${browserType} ff_profile_dir=${profileAddress}
Maximize Browser Window
Click Element xpath=${itemXpath}
Sleep 10
Close Browser
It removed the exception and set my preferences as well, but I still need to pass the profile address.