You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add support for specifying user-data-directory or Chrome Options when opening Chrome with *Open Browser* Keyword #225
While attempting to write some tests regarding the correct population of text fields as part of some internationalization testing, we encountered some difficulty in setting the language preferences in Google Chrome.
We have written our own keyword that allows us to specify the Chrome Options, enabling us to select the language and the user-data-directory, however as this is happening outside BrowserManagement we are then unable to interface with the browser after that, as it is not added to the common browser cache.
Our proposed solution would be to change the Open Browser keyword to accept a Chrome Options argument, or a Chrome user-data-directory (similar to the way that it currently supports firefox profiles).
Below is the keyword we have implemented, as an example of what we are trying to achieve.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from sys import exit
def set_language_in_chrome(locale):
acc_lang_desired = locale
chrome_option = Options()
chrome_option._experimental_options['prefs'] = {'intl.accept_languages': acc_lang_desired}
chrome_option.add_argument("user-data-dir=/Users/SPeilow/AppData/Local/Google/Chrome/User Data/");
driver = webdriver.Chrome(chrome_options=chrome_option)
driver.get(url);
driver.quit()
Yes I can see the need for this. Unfortunately I think the various web driver teams have all stated to diverge and it's going to mean our open browser functionality will have to take it a separate parameter for every web driver type. i.e. ChromOptions, Firefox Profile, PhantomJS cmd line args, etc... etc...
I don't think we have any other choice but to do that. As this will also be needed for #215#90#204#208 and probably a couple of others. So I think we should go ahead and do it. But at the same time we should all bitch and complain to the Selenium team for creating this mess int he first place...
@j1z0 I have thought a lot about this and do not like any solution I come up with. Maybe we should add an extra_arguments argument to open browser that is just a kwarg pass-through.
I like how the Java bindings for PhantomJS use the DesiredCapability phantomjs.cli.args, but I think that is the only WebDriver to do that :(
@speilow-navi Until there are changes, you can put your manually constructed browser into the cache by adding code like this to your existing keyword:
from robot.libraries.BuiltIn import BuiltIn
...
s2l = BuiltIn().get_library_instance('Selenium2Library')
logger.debug('Opened browser with session id %s'
% driver.session_id)
return s2l._cache.register(driver, alias)
I like how the Java bindings for PhantomJS use the DesiredCapability phantomjs.cli.args, but I think that is the
only WebDriver to do that :(
@ombre42 I've just suggested to the selenium team that they add basically this functionality for all webdrivers. If they say it's OK I'll go ahead and implement it and send the pull request and then we won't need to do anything on the S2L side as it will be fixed upstream.
Otherwise we implement the desired_capabilities parsing in S2L or as you suggested the extra_arguments argument is also a good way to go. Let's see what the selenium team says first and then take it from there.
Activity
j1z0 commentedon Aug 1, 2013
Yes I can see the need for this. Unfortunately I think the various web driver teams have all stated to diverge and it's going to mean our open browser functionality will have to take it a separate parameter for every web driver type. i.e. ChromOptions, Firefox Profile, PhantomJS cmd line args, etc... etc...
I don't think we have any other choice but to do that. As this will also be needed for #215 #90 #204 #208 and probably a couple of others. So I think we should go ahead and do it. But at the same time we should all bitch and complain to the Selenium team for creating this mess int he first place...
j1z0 commentedon Aug 1, 2013
OK I've also raised an associated issue with the core Selenium Team.
https://code.google.com/p/selenium/issues/detail?id=6026
Please up vote the issue so hopefully it gets some love.
ombre42 commentedon Aug 1, 2013
@j1z0 I have thought a lot about this and do not like any solution I come up with. Maybe we should add an extra_arguments argument to open browser that is just a kwarg pass-through.
I like how the Java bindings for PhantomJS use the DesiredCapability phantomjs.cli.args, but I think that is the only WebDriver to do that :(
@speilow-navi Until there are changes, you can put your manually constructed browser into the cache by adding code like this to your existing keyword:
A full example can be found on the user group.
j1z0 commentedon Aug 1, 2013
@ombre42 I've just suggested to the selenium team that they add basically this functionality for all webdrivers. If they say it's OK I'll go ahead and implement it and send the pull request and then we won't need to do anything on the S2L side as it will be fixed upstream.
Otherwise we implement the desired_capabilities parsing in S2L or as you suggested the extra_arguments argument is also a good way to go. Let's see what the selenium team says first and then take it from there.
speilow-navi commentedon Aug 2, 2013
Thanks all for the quick replys. ombre42, thanks for that code for the cache, that should allow us to get our tests working for the time being!
emanlove commentedon Dec 26, 2013
With newly implemented keyword 'Create Webdriver' you should be able to accomplish this with some lines like
JackLoveCat commentedon Mar 31, 2017
If you want to change the userdata config ,you need to do like below in windows: