Permalink
Browse files

Start Selenium Server: allow defining JVM options

Update issue 242
Status: Done
  • Loading branch information...
1 parent 69f822b commit 38e55d54c0c3e1e41171aeea5d900d7490e0970b Janne Härkönen committed Aug 28, 2012
Showing with 33 additions and 15 deletions.
  1. +16 −5 src/SeleniumLibrary/__init__.py
  2. +17 −10 test/unit/test_seleniumlibrary.py
@@ -86,8 +86,17 @@ def start_selenium_server(logfile=None, jarpath=None, *params):
def _server_startup_command(jarpath, *params):
if not jarpath:
jarpath = SELENIUM_SERVER_PATH
+ params = list(params)
+ jvm_opts, params = _extract_jvm_params(params)
params = _add_default_user_extension(jarpath, list(params))
- return ['java', '-jar', jarpath] + _server_startup_params(params)
+ return ['java'] + jvm_opts + ['-jar', jarpath] + _server_startup_params(params)
+
+def _extract_jvm_params(params):
+ for p in params[:]:
+ if p[:4].upper() == 'JVM=':
+ params.remove(p)
+ return p[4:].split(), params
+ return [], params
def _add_default_user_extension(jarpath, params):
extpath = os.path.join(os.path.dirname(jarpath), 'user-extensions.js')
@@ -317,22 +326,24 @@ def start_selenium_server(self, *params):
`-firefoxProfileTemplate` option. You can override this
profile with your own custom profile by using the same argument
in `params` yourself. To use the default profile on your machine,
- use this argument with `DEFAULT` value (case-sensitive). Using a
- custom Firefox profile automatically is a new feature in
- SeleniumLibrary 2.5. For more information see
- http://code.google.com/p/robotframework-seleniumlibrary/wiki/CustomFirefoxProfile
+ use this argument with `DEFAULT` value (case-sensitive).
3) Starting from SeleniumLibrary 2.6, if there is `user-extensions.js`
file in the same directory as Selenium Server jar, it is loaded using
the `-userExtensions` option. This is not done if the option is
defined in `params`. By default, such extension file providing Flex
testing support is loaded automatically.
+ Special syntax `JVM=some jvm opts` can be used to define options to
+ the java command itself used to start the selenium server. This
+ possibility was added in SeleniumLibrary 2.9.1.
+
Examples:
| Start Selenium Server | | | # Default settings. Uses the Firefox profile supplied with the library. |
| Start Selenium Server | -firefoxProfileTemplate | C:\\\\the\\\\path | # Uses custom Firefox profile. |
| Start Selenium Server | -firefoxProfileTemplate | DEFAULT | # Uses default Firefox profile on your machine. |
| Start Selenium Server | -avoidProxy | -ensureCleanSession | # Uses various Selenium Server settings. |
+ | Start Selenium Server | -JVM=-DserverName=somehost | # Define JVM options. |
All Selenium Server output is written into `selenium_server_log.txt`
file in the same directory as the Robot Framework log file.
@@ -2,9 +2,8 @@
import os
from SeleniumLibrary import (SeleniumLibrary, _server_startup_command,
- _server_startup_params,
- FIREFOX_TEMPLATE_ARG, FIREFOX_PROFILE_DIR,
- FIREFOX_DEFAULT_PROFILE, SELENIUM_SERVER_PATH)
+ _server_startup_params, FIREFOX_TEMPLATE_ARG, FIREFOX_PROFILE_DIR,
+ FIREFOX_DEFAULT_PROFILE, SELENIUM_SERVER_PATH)
class TestGetBrowser(unittest.TestCase):
@@ -21,8 +20,11 @@ def test_firefox_aliases(self):
self.assertEquals(self.lib._get_browser(alias), '*firefox')
def test_non_alias_is_not_modified(self):
- for non_alias in ['FIREFUX', 'i e 8', 'C:\\Program Files\\mybrowser\\brow.exe',
- '{"username": "user", "access-key": "7A9cea40-84f7-4d3b-8748-0e94fCd4dX4f"}']:
+ for non_alias in [
+ 'FIREFUX',
+ 'i e 8',
+ 'C:\\Program Files\\mybrowser\\brow.exe',
+ '{"username": "user", "access-key": "7A9cea40-84f7-4d3b-8748-0e94fCd4dX4f"}']:
self.assertEquals(self.lib._get_browser(non_alias), non_alias)
def test_patched_remote_control(self):
@@ -31,7 +33,6 @@ def test_patched_remote_control(self):
self.assertTrue('conn.close()' in open(rc_path).read())
-
class TestServerArguments(unittest.TestCase):
def test_default_jar_path_is_correctly_determined(self):
@@ -47,17 +48,23 @@ def test_selenium_lib_default_profile_is_used_when_no_profile_given(self):
[FIREFOX_TEMPLATE_ARG, FIREFOX_PROFILE_DIR])
def test_given_profile_is_not_overridden(self):
- self.assertEquals(_server_startup_params([FIREFOX_TEMPLATE_ARG, 'foo']),
- [FIREFOX_TEMPLATE_ARG, 'foo'])
+ params = _server_startup_params([FIREFOX_TEMPLATE_ARG, 'foo'])
+ self.assertEquals(params, [FIREFOX_TEMPLATE_ARG, 'foo'])
def test_real_default_profile_can_be_used(self):
- params = [FIREFOX_TEMPLATE_ARG,FIREFOX_DEFAULT_PROFILE]
+ params = [FIREFOX_TEMPLATE_ARG, FIREFOX_DEFAULT_PROFILE]
self.assertEquals(_server_startup_params(params), [])
def test_other_options_are_preserved(self):
params = ['-someOpt', 'value', '-otherOpt']
self.assertEquals(_server_startup_params(params),
- ['-someOpt', 'value', '-otherOpt', FIREFOX_TEMPLATE_ARG, FIREFOX_PROFILE_DIR])
+ params + [FIREFOX_TEMPLATE_ARG, FIREFOX_PROFILE_DIR])
+
+ def test_jvm_options(self):
+ params = ['-foo', 'bar', 'jvm=-DsysProp=bar -Dht.Tp=qx']
+ expected = ['java', '-DsysProp=bar', '-Dht.Tp=qx', '-jar',
+ SELENIUM_SERVER_PATH, '-foo', 'bar']
+ self.assertEquals(_server_startup_command(None, *params)[:7], expected)
class TestInitialization(unittest.TestCase):

0 comments on commit 38e55d5

Please sign in to comment.