Browse files

use dict argument for backwards compatibility

  • Loading branch information...
1 parent 8e18026 commit 33e0517be7ef1b554cc09524d3b4b4a4dc87e416 @ombre42 ombre42 committed Nov 5, 2013
Showing with 36 additions and 33 deletions.
  1. +17 −17 src/Selenium2Library/keywords/_browsermanagement.py
  2. +19 −16 test/acceptance/create_webdriver.txt
View
34 src/Selenium2Library/keywords/_browsermanagement.py
@@ -114,7 +114,7 @@ def open_browser(self, url, browser='firefox', alias=None,remote_url=False,
% browser.session_id)
return self._cache.register(browser, alias)
- def create_webdriver(self, driver_name, alias=None, *name_value_pairs, **init_kwargs):
+ def create_webdriver(self, driver_name, alias=None, kwargs={}, **init_kwargs):
"""Creates an instance of a WebDriver.
Like `Open Browser`, but allows passing arguments to a WebDriver's
@@ -133,31 +133,31 @@ def create_webdriver(self, driver_name, alias=None, *name_value_pairs, **init_kw
Use keyword arguments to specify the arguments you want to pass to
the WebDriver's __init__. The values of the arguments are not
processed in any way before being passed on. For Robot Framework
- < 2.8, which does not support keyword arguments, use a list of
- argument names and value to specify the arguments instead . See the
+ < 2.8, which does not support keyword arguments, create a keyword
+ dictionary and pass it in as argument `kwargs`. See the
[http://selenium.googlecode.com/git/docs/api/py/api.html|Selenium API Documentation]
for information about argument names and appropriate argument values.
Examples:
- | # use proxy for Firefox | | | |
- | ${proxy}= | Evaluate | sys.modules['selenium.webdriver'].Proxy() | sys, selenium.webdriver |
- | ${proxy.http_proxy}= | Set Variable | localhost:8888 | |
- | Create Webdriver | Firefox | proxy=${proxy} | |
- | # debug IE driver | | | |
- | Create Webdriver | Ie | log_level=DEBUG | log_file=%{HOMEPATH}${/}ie.log |
+ | # use proxy for Firefox | | | |
+ | ${proxy}= | Evaluate | sys.modules['selenium.webdriver'].Proxy() | sys, selenium.webdriver |
+ | ${proxy.http_proxy}= | Set Variable | localhost:8888 | |
+ | Create Webdriver | Firefox | proxy=${proxy} | |
+ | # use a proxy for PhantomJS | | | |
+ | ${service args}= | Create List | --proxy=192.168.132.104:8888 | |
+ | Create Webdriver | PhantomJS | service_args=${service args} | |
Example for Robot Framework < 2.8:
- | # use a proxy for PhantomJS | | | | |
- | ${service args}= | Create List | --proxy=192.168.132.104:8888 | | |
- | Create Webdriver | PhantomJS | phantomjs | service_args | ${service args} |
+ | # debug IE driver | | | | | |
+ | ${kwargs}= | Create Dictionary | log_level | DEBUG | log_file | %{HOMEPATH}${/}ie.log |
+ | Create Webdriver | Ie | kwargs=${kwargs} | | | |
"""
- if len(name_value_pairs) % 2 != 0:
- raise RuntimeError("There should be an even number of argument name-value pairs.")
- for i in range(0, len(name_value_pairs), 2):
- arg_name = name_value_pairs[i].strip()
+ if not isinstance(kwargs, dict):
+ raise RuntimeError("kwargs must be a dictionary.")
+ for arg_name in kwargs:
if arg_name in init_kwargs:
raise RuntimeError("Got multiple values for argument '%s'." % arg_name)
- init_kwargs[arg_name] = name_value_pairs[i+1]
+ init_kwargs[arg_name] = kwargs[arg_name]
driver_name = driver_name.strip()
try:
creation_func = getattr(webdriver, driver_name)
View
35 test/acceptance/create_webdriver.txt
@@ -1,35 +1,30 @@
*Setting*
Suite Teardown Close All Browsers
Resource resource.txt
-
+Library Collections
*Test Cases*
-
Create Webdriver Creates Functioning WebDriver
[Documentation] LOG 1:1 INFO Creating an instance of the Firefox WebDriver LOG 1:3 DEBUG REGEXP: Created Firefox WebDriver instance with session id (\\w|-)+
- ${index}= Create Webdriver Firefox firefox
+ ${index}= Create Webdriver Firefox createwebdriver
Go To ${FRONT PAGE}
Page Should Contain needle
${index as int}= Convert To Integer ${index}
Should Be Equal ${index} ${index as int}
- Switch Browser firefox
+ Switch Browser createwebdriver
[Teardown] Close Browser
-Create Webdriver With Missing Value
- Run Keyword And Expect Error There should be an even number of argument name-value pairs. Create Webdriver Firefox firefox proxy
-
Create Webdriver With Keyword Argument
- ${proxy}= Evaluate sys.modules['selenium.webdriver'].Proxy() sys, selenium.webdriver
- ${proxy.http_proxy}= Set Variable localhost:7777
+ ${proxy}= Create Bad Proxy
Create Webdriver Firefox proxy=${proxy}
Go To ${FRONT PAGE}
Page Should Contain The proxy server is refusing connections
[Teardown] Close Browser
-Create Webdriver With List Argument
- ${proxy}= Evaluate sys.modules['selenium.webdriver'].Proxy() sys, selenium.webdriver
- ${proxy.http_proxy}= Set Variable localhost:7777
- Create Webdriver Firefox firefox proxy ${proxy}
+Create Webdriver With Keyword Argument Dictionary
+ ${proxy}= Create Bad Proxy
+ ${kwargs}= Create Dictionary proxy ${proxy}
+ Create Webdriver Firefox kwargs=${kwargs}
Go To ${FRONT PAGE}
Page Should Contain The proxy server is refusing connections
[Teardown] Close Browser
@@ -38,6 +33,14 @@ Create Webdriver With Bad Driver Name
Run Keyword And Expect Error 'Fireox' is not a valid WebDriver name Create Webdriver Fireox
Create Webdriver With Duplicate Arguments
- Run Keyword And Expect Error Got multiple values for argument 'arg'. Create Webdriver Firefox firefox arg 1 arg=2
- Run Keyword And Expect Error Got multiple values for argument 'arg'. Create Webdriver Firefox firefox arg 1 arg 2
-
+ ${kwargs}= Create Dictionary arg 1
+ Run Keyword And Expect Error Got multiple values for argument 'arg'. Create Webdriver Firefox kwargs=${kwargs} arg=2
+
+Create Webdriver With Bad Keyword Argument Dictionary
+ Run Keyword And Expect Error kwargs must be a dictionary. Create Webdriver Firefox kwargs={'spam': 'eggs'}
+
+*Keywords*
+Create Bad Proxy
+ ${proxy}= Evaluate sys.modules['selenium.webdriver'].Proxy() sys, selenium.webdriver
+ ${proxy.http_proxy}= Set Variable localhost:7777
+ [Return] ${proxy}

0 comments on commit 33e0517

Please sign in to comment.