From 25bd96e612ce4d56a3f90c739bc64cbee9f57cb4 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Sat, 17 Dec 2016 01:02:11 +0200 Subject: [PATCH 01/14] Modified how Travis CI is used with the project. Travis does not allow, for securirty reasons, PR buils to access encrypted data. Project stores the Sacuce Labs credentials in encrypted format in Travis settings and therefore builds from PR can not use the browsers from Sauce Labs. Changed CI configuration and run_tests.py to use Trvis Chrome browser for PR buils. Also configured Travis corn to test from master periodically and to use different browsers from the Sauce Labs. Did take Python argparse in use and therefore passing arbitary pybot and rebot arguments is not anymore possible. But now it is possible also to use Sauce Labs from when running test from local computer. --- .travis.yml | 65 ++++++++------------ test/env.py | 9 +-- test/run_tests.py | 151 +++++++++++++++++++++++++++++++--------------- 3 files changed, 133 insertions(+), 92 deletions(-) mode change 100755 => 100644 test/run_tests.py diff --git a/.travis.yml b/.travis.yml index 1c70079ce..ae1da16d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,52 +1,37 @@ -addons: - firefox: latest-esr language: python -sudo: false +sudo: required +dist: trusty +addons: + apt: + sources: + - google-chrome + packages: + - google-chrome-stable install: - pip install . - pip install -r requirements.txt - pip install -r requirements-dev.txt -before_script: - - "export DISPLAY=:99.0" - - "sh -e /etc/init.d/xvfb start" -script: - - "if [[ -n ${SELENIUM_VERSION+x} ]]; then pip install -U selenium==${SELENIUM_VERSION}; fi" - - "python test/run_tests.py python \"$BROWSER\"" -env: - global: - - secure: "QyY0j8C+hVhsGLv4YU0UMvLm5wBDg6xT5J0Ee77C/JAQ6vcdCMpTfWI8oDxTZb7pBhpDkYuNe747yCYF5PrdBYQbO08FilxctReuJfMXcH44rZC5q49mUmPamkvg1LkzIWuC1s9uKnjlvyDT5ojuPXZl2Vn0gIhSIg+yOyBkM1U=" - - secure: "HJaJTYauaBZODMDkbnRVsiCk+t2uVtztkkJ5V4dXSnE1uIBms2PVbufQwb+YNvzHkGheLtpnt/hLM1HhmSFgUtOCf+eumQ6kaLR2KRVEysXwWJzgZoLBidNBOy5rvAIsc9JJbDaIgYVGzyaJGTP9AMb8CyvIPE//lH10sf+GB7g=" matrix: include: - - os: linux - env: - - BROWSER=firefox - - SELENIUM_VERSION=2.53.6 - addons: - firefox: "47.0.1" - python: "2.7" - - os: linux + - python: "2.7" # For PR and cron env: - BROWSER=chrome - addons: - sauce_connect: true - python: "2.7" - - os: linux + - SELENIUM=2.53.6 + - python: "3.3" # For PR and cron env: - - BROWSER=firefox - - SELENIUM_VERSION=2.53.6 - addons: - sauce_connect: true - python: "3.4" - - os: linux + - BROWSER=chrome + - SELENIUM=2.53.6 + - python: "3.3" # For PR and cron env: - - BROWSER="internet explorer" - addons: - sauce_connect: true - python: "2.7" - - os: linux + - BROWSER=chrome + - SELENIUM=3.0.2 + - python: "3.3" # For cron only env: - - BROWSER=safari - addons: - sauce_connect: true - python: "2.7" \ No newline at end of file + - BROWSER=firefox + - SELENIUM=2.53.6 +before_script: + - "export DISPLAY=:99.0" + - "sh -e /etc/init.d/xvfb start" + - pip install selenium==$SELENIUM +script: + - python test/run_tests.py $BROWSER diff --git a/test/env.py b/test/env.py index 0c2218932..58372aebd 100755 --- a/test/env.py +++ b/test/env.py @@ -10,10 +10,11 @@ HTTP_SERVER_FILE = os.path.join(RESOURCES_DIR, "testserver", "testserver.py") SRC_DIR = os.path.join(ROOT_DIR, "..", "src") -TRAVIS = os.environ.get("TRAVIS", None) -TRAVIS_JOB_NUMBER = os.environ.get("TRAVIS_JOB_NUMBER") -SAUCE_USERNAME = os.environ.get("SAUCE_USERNAME") -SAUCE_ACCESS_KEY = os.environ.get("SAUCE_ACCESS_KEY") +TRAVIS = os.environ.get("TRAVIS", False) +TRAVIS_EVENT_TYPE = os.environ.get("TRAVIS_EVENT_TYPE", []) +TRAVIS_JOB_NUMBER = os.environ.get("TRAVIS_JOB_NUMBER", "localtunnel") +SAUCE_USERNAME = os.environ.get("SAUCE_USERNAME", None) +SAUCE_ACCESS_KEY = os.environ.get("SAUCE_ACCESS_KEY", None) sys.path.insert(0, SRC_DIR) diff --git a/test/run_tests.py b/test/run_tests.py old mode 100755 new mode 100644 index 72eb989c9..7ad073489 --- a/test/run_tests.py +++ b/test/run_tests.py @@ -10,19 +10,35 @@ Usage: - run_tests.py interpreter browser [options] + run_tests.py browser [options] Arguments: - interpreter: Any Python interpreter supported by the library (e.g. `python`, - `jython`, `c:\\Python27\\python.exe`) - browser: Any browser supported by the library (e.g. `chrome`, `firefox`) - options: Additional command line options passed to Robot Framework + browser: Any browser supported by the library (e.g. `chrome`or + `firefox`) + --interpreter: Any Python interpreter supported by the library (e.g. + `python`, `jython` or `c:\\Python27\\python.exe`). By + default set to `python`. + --suite: Selects the test suites by name. + --scusername: Username to access Sauce Labs to order browsers when + running test from local computer. + --sckey: Access key for Sauce Labs account. + +When running test by using browser from Sauce labs, it is required that +the Sauce Connect is used. The Sauce Connect allows the browser from Sauce Labs +reach the acceptance test webserver. The acceptance test uses tunnel with +name `localtunnel` and therefore when establishing the Sauce Connect tunnel +use the following command: +`bin/sc -u YOUR_USERNAME -k YOUR_ACCESS_KEY -i localtunnel` + +More details and to downlaod Sauce Connect visit: +https://wiki.saucelabs.com/display/DOCS/High+Availability+Sauce+Connect+Setup Examples: run_tests.py python chrome - run_tests.py jython c:\\Python35\\python.exe --test "Click element" + run_tests.py jython firefox --suite list + run_tests.py python chrome --scusername your_username --sckey account_key """ from __future__ import print_function @@ -30,6 +46,7 @@ from contextlib import contextmanager import os import sys +import argparse import subprocess from robot import rebot_cli @@ -42,6 +59,7 @@ import env from run_unit_tests import run_unit_tests +TRAVIS_PRS = ['push', 'pull_request', 'api'] ROBOT_OPTIONS = [ '--doc', 'Selenium2Library acceptance tests with {browser}', @@ -69,12 +87,12 @@ def unit_tests(): sys.exit(failures) -def acceptance_tests(interpreter, browser, options): +def acceptance_tests(interpreter, browser, suite, sauceusername, saucekey): if not os.path.exists(env.RESULTS_DIR): os.mkdir(env.RESULTS_DIR) with http_server(): - execute_tests(interpreter, browser, options) - failures = process_output(browser, options) + execute_tests(interpreter, browser, suite, sauceusername, saucekey) + failures = process_output(browser, suite) if failures: print('\n{} critical test{} failed.' .format(failures, 's' if failures != 1 else '')) @@ -96,46 +114,27 @@ def http_server(): serverlog.close() -def execute_tests(interpreter, browser, cli_options): +def execute_tests(interpreter, browser, suite, sauceusername, saucekey): runner = [interpreter, '-m', 'robot.run'] options = [opt.format(browser=browser, py_version=interpreter + sys.version[:3]) for opt in ROBOT_OPTIONS] - if env.TRAVIS: - options.extend(get_travis_conf(browser)) - command = runner + options + cli_options + [env.ACCEPTANCE_TEST_DIR] - log_start(command) + if sauceusername and saucekey: + options.extend(get_sauce_conf(browser, sauceusername, saucekey)) + command = runner + if suite: + command += ['-s', suite] + command += options + [env.ACCEPTANCE_TEST_DIR] + log_start(command, sauceusername, saucekey) syslog = os.path.join(env.RESULTS_DIR, 'syslog.txt') - # Running tests as an external process, not using `robot_cli`, to allow - # using different interpreter that is used for running this script. - subprocess.call(command, env=dict(os.environ, ROBOT_SYSLOG_FILE=syslog)) - - -def get_travis_conf(browser): - conf = [ - '--variable', 'SAUCE_USERNAME:{}'.format(env.SAUCE_USERNAME), - '--variable', 'SAUCE_ACCESS_KEY:{}'.format(env.SAUCE_ACCESS_KEY) - ] - if browser == 'firefox': - conf.extend([ - '--variable', - 'REMOTE_URL:http://{}:{}@ondemand.saucelabs.com:80/wd/hub'.format( - env.SAUCE_USERNAME, env.SAUCE_ACCESS_KEY - ) - ]) - else: - conf.extend([ - '--variable', - 'DESIRED_CAPABILITIES:build:{0}-{1},tunnel-identifier:{0}'.format( - env.TRAVIS_JOB_NUMBER, browser - ) - ]) - return conf + subprocess.call( + command, env=dict(os.environ, ROBOT_SYSLOG_FILE=syslog) + ) -def log_start(command_list): +def log_start(command_list, sauceusername, saucekey): command = subprocess.list2cmdline(command_list) - for hidden in [env.SAUCE_USERNAME, env.SAUCE_ACCESS_KEY]: + for hidden in [sauceusername, saucekey]: if hidden: command = command.replace(hidden, '*' * len(hidden)) print() @@ -143,21 +142,77 @@ def log_start(command_list): print(command) -def process_output(browser, cli_options): +def get_sauce_conf(browser, sauceusername, saucekey): + return [ + '--variable', 'SAUCE_USERNAME:{}'.format(sauceusername), + '--variable', 'SAUCE_ACCESS_KEY:{}'.format(saucekey), + '--variable', + 'REMOTE_URL:http://{}:{}@ondemand.saucelabs.com:80/wd/hub'.format( + sauceusername, saucekey + ), + '--variable', + 'DESIRED_CAPABILITIES:build:{0}-{1},tunnel-identifier:{0}'.format( + env.TRAVIS_JOB_NUMBER, browser + ) + ] + + +def process_output(browser, suite): print('Verifying results...') output = os.path.join(env.RESULTS_DIR, 'output.xml') robotstatuschecker.process_output(output, verbose=False) options = [opt.format(browser=browser) for opt in REBOT_OPTIONS] + if suite: + options += ['-s', suite] try: - rebot_cli(options + cli_options + [output]) + rebot_cli(options + [output]) except SystemExit as exit: return exit.code +def sauce_credentials(sauceusername, saucekey): + if env.TRAVIS: + username = env.SAUCE_USERNAME + key = env.SAUCE_ACCESS_KEY + else: + username = sauceusername + key = saucekey + return username, key + + if __name__ == '__main__': - if len(sys.argv) < 3 or '--help' in sys.argv: - sys.exit(__doc__) + parser = argparse.ArgumentParser(description='Library test runner') + parser.add_argument( + '--interpreter', + default='python', + help='Interpreter used run the test' + ) + parser.add_argument('browser', help='Browser used in testing') + parser.add_argument( + '--suite', + '-s', + help='Selects the test suites by name.' + ) + parser.add_argument( + '--scusername', + help='Username to order browser from SaucuLabs' + ) + parser.add_argument( + '--sckey', + help='Access key to order browser from SaucuLabs' + ) + + args = parser.parse_args() + browser = args.browser.lower() + if browser is not 'chrome' and env.TRAVIS_EVENT_TYPE in TRAVIS_PRS: + print( + 'Can not run test with browser {} from SauceLabs\n' + 'SauceLabs can be used only when running with corn and from ' + 'Selenium2Library master banch'.format(browser) + ) + sys.exit(0) + sauceusername, saucekey = sauce_credentials( + args.scusername, args.sckey) unit_tests() - acceptance_tests(interpreter=sys.argv[1], - browser=sys.argv[2].lower(), - options=sys.argv[3:]) + acceptance_tests(args.interpreter, browser, args.suite, + sauceusername, saucekey) From 5ec33ef84be7417aa6c8fb8a393c9cc7087a2c0a Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Sat, 17 Dec 2016 23:49:39 +0200 Subject: [PATCH 02/14] Changed selenium 3 run from Python 3 to Python 2. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ae1da16d5..0746dbdb8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ matrix: env: - BROWSER=chrome - SELENIUM=2.53.6 - - python: "3.3" # For PR and cron + - python: "2.7" # For PR and cron env: - BROWSER=chrome - SELENIUM=3.0.2 From 4cf81060a84524755cc49a043e8b883797f386dd Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Sun, 18 Dec 2016 01:26:56 +0200 Subject: [PATCH 03/14] Changed chrome browser always to run from Travis --- test/env.py | 2 +- test/run_tests.py | 39 +++++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/test/env.py b/test/env.py index 58372aebd..7649810fa 100755 --- a/test/env.py +++ b/test/env.py @@ -11,7 +11,7 @@ SRC_DIR = os.path.join(ROOT_DIR, "..", "src") TRAVIS = os.environ.get("TRAVIS", False) -TRAVIS_EVENT_TYPE = os.environ.get("TRAVIS_EVENT_TYPE", []) +TRAVIS_EVENT_TYPE = os.environ.get("TRAVIS_EVENT_TYPE", None) TRAVIS_JOB_NUMBER = os.environ.get("TRAVIS_JOB_NUMBER", "localtunnel") SAUCE_USERNAME = os.environ.get("SAUCE_USERNAME", None) SAUCE_ACCESS_KEY = os.environ.get("SAUCE_ACCESS_KEY", None) diff --git a/test/run_tests.py b/test/run_tests.py index 7ad073489..bdfac9ead 100644 --- a/test/run_tests.py +++ b/test/run_tests.py @@ -59,8 +59,6 @@ import env from run_unit_tests import run_unit_tests -TRAVIS_PRS = ['push', 'pull_request', 'api'] - ROBOT_OPTIONS = [ '--doc', 'Selenium2Library acceptance tests with {browser}', '--outputdir', env.RESULTS_DIR, @@ -143,18 +141,22 @@ def log_start(command_list, sauceusername, saucekey): def get_sauce_conf(browser, sauceusername, saucekey): - return [ - '--variable', 'SAUCE_USERNAME:{}'.format(sauceusername), - '--variable', 'SAUCE_ACCESS_KEY:{}'.format(saucekey), - '--variable', - 'REMOTE_URL:http://{}:{}@ondemand.saucelabs.com:80/wd/hub'.format( - sauceusername, saucekey - ), - '--variable', - 'DESIRED_CAPABILITIES:build:{0}-{1},tunnel-identifier:{0}'.format( - env.TRAVIS_JOB_NUMBER, browser - ) - ] + if browser == 'chrome' and env.TRAVIS: + conf = [] + else: + conf = [ + '--variable', 'SAUCE_USERNAME:{}'.format(sauceusername), + '--variable', 'SAUCE_ACCESS_KEY:{}'.format(saucekey), + '--variable', + 'REMOTE_URL:http://{}:{}@ondemand.saucelabs.com:80/wd/hub'.format( + sauceusername, saucekey + ), + '--variable', + 'DESIRED_CAPABILITIES:build:{0}-{1},version:54.0,tunnel-identifier:{0},platform:Windows 10'.format( + env.TRAVIS_JOB_NUMBER, browser + ) + ] + return conf def process_output(browser, suite): @@ -203,12 +205,13 @@ def sauce_credentials(sauceusername, saucekey): ) args = parser.parse_args() - browser = args.browser.lower() - if browser is not 'chrome' and env.TRAVIS_EVENT_TYPE in TRAVIS_PRS: + browser = args.browser.lower().strip() + if browser != 'chrome' and env.TRAVIS_EVENT_TYPE != 'cron': print( - 'Can not run test with browser {} from SauceLabs\n' + 'Can not run test with browser "{}" from SauceLabs\n' 'SauceLabs can be used only when running with corn and from ' - 'Selenium2Library master banch'.format(browser) + 'Selenium2Library master banch, but your event type ' + 'was "{}"'.format(browser, env.TRAVIS_EVENT_TYPE) ) sys.exit(0) sauceusername, saucekey = sauce_credentials( From 22b4c55a3febdb7efb5f3830264f1fa62114e7db Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Sun, 18 Dec 2016 01:38:25 +0200 Subject: [PATCH 04/14] Downloading chrome driver and putting it to path --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 0746dbdb8..10a4eb78a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,11 @@ addons: - google-chrome packages: - google-chrome-stable +before_install: + - wget http://chromedriver.storage.googleapis.com/2.26/chromedriver_linux64.zip + - unzip chromedriver_linux64.zip + - sudo chmod u+x chromedriver + - sudo mv chromedriver /usr/bin/ install: - pip install . - pip install -r requirements.txt From adf2b06d0fa435d7904cb5d63d85aca0be404ceb Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Sun, 18 Dec 2016 22:39:55 +0200 Subject: [PATCH 05/14] Allowing Sauce Labs to choose chrome version and the OS --- test/run_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/run_tests.py b/test/run_tests.py index bdfac9ead..062b5c773 100644 --- a/test/run_tests.py +++ b/test/run_tests.py @@ -152,7 +152,7 @@ def get_sauce_conf(browser, sauceusername, saucekey): sauceusername, saucekey ), '--variable', - 'DESIRED_CAPABILITIES:build:{0}-{1},version:54.0,tunnel-identifier:{0},platform:Windows 10'.format( + 'DESIRED_CAPABILITIES:build:{0}-{1},tunnel-identifier:{0}'.format( env.TRAVIS_JOB_NUMBER, browser ) ] From a175b0b84bad82947d2f3187fc7e363ad841fb40 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 20 Dec 2016 22:48:34 +0200 Subject: [PATCH 06/14] Updated based on review --- .travis.yml | 3 ++- test/run_tests.py | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 10a4eb78a..da748274e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,8 @@ addons: packages: - google-chrome-stable before_install: - - wget http://chromedriver.storage.googleapis.com/2.26/chromedriver_linux64.zip + - CDVERSION=`curl http://chromedriver.storage.googleapis.com/LATEST_RELEASE` + - wget http://chromedriver.storage.googleapis.com/$CDVERSION/chromedriver_linux64.zip - unzip chromedriver_linux64.zip - sudo chmod u+x chromedriver - sudo mv chromedriver /usr/bin/ diff --git a/test/run_tests.py b/test/run_tests.py index 062b5c773..4f7bc2dc4 100644 --- a/test/run_tests.py +++ b/test/run_tests.py @@ -36,9 +36,9 @@ Examples: - run_tests.py python chrome - run_tests.py jython firefox --suite list - run_tests.py python chrome --scusername your_username --sckey account_key + run_tests.py chrome + run_tests.py --suite list --interpreter jython firefox + run_tests.py chrome --scusername your_username --sckey account_key """ from __future__ import print_function @@ -206,11 +206,11 @@ def sauce_credentials(sauceusername, saucekey): args = parser.parse_args() browser = args.browser.lower().strip() - if browser != 'chrome' and env.TRAVIS_EVENT_TYPE != 'cron': + if env.TRAVIS and browser != 'chrome' and env.TRAVIS_EVENT_TYPE != 'cron': print( 'Can not run test with browser "{}" from SauceLabs\n' - 'SauceLabs can be used only when running with corn and from ' - 'Selenium2Library master banch, but your event type ' + 'SauceLabs can be used only when running with cron and from ' + 'Selenium2Library master branch, but your event type ' 'was "{}"'.format(browser, env.TRAVIS_EVENT_TYPE) ) sys.exit(0) From 5edfe7dd112ace5e8a786e3adf3b369d552c002d Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Sun, 25 Dec 2016 17:30:15 +0200 Subject: [PATCH 07/14] Enhanced documation and Robot Framework command line args Not it is possible to pass Robot Framework command line arguments as last argument to run_tests.py command. --- test/run_tests.py | 195 +++++++++++++++++++++++----------------------- 1 file changed, 98 insertions(+), 97 deletions(-) diff --git a/test/run_tests.py b/test/run_tests.py index 4f7bc2dc4..fee02f018 100644 --- a/test/run_tests.py +++ b/test/run_tests.py @@ -1,46 +1,4 @@ #!/usr/bin/env python - -"""Script to run Selenium2Library acceptance tests. - -Tests are executed using Robot Framework and results verified automatically -afterwards using `robotstatuschecker` tool. The tool can be installed using -`pip install robotstatuschecker` and more information about it can be found -from https://github.com/robotframework/statuschecker/. Notice that initially -some tests fail. - -Usage: - - run_tests.py browser [options] - -Arguments: - - browser: Any browser supported by the library (e.g. `chrome`or - `firefox`) - --interpreter: Any Python interpreter supported by the library (e.g. - `python`, `jython` or `c:\\Python27\\python.exe`). By - default set to `python`. - --suite: Selects the test suites by name. - --scusername: Username to access Sauce Labs to order browsers when - running test from local computer. - --sckey: Access key for Sauce Labs account. - -When running test by using browser from Sauce labs, it is required that -the Sauce Connect is used. The Sauce Connect allows the browser from Sauce Labs -reach the acceptance test webserver. The acceptance test uses tunnel with -name `localtunnel` and therefore when establishing the Sauce Connect tunnel -use the following command: -`bin/sc -u YOUR_USERNAME -k YOUR_ACCESS_KEY -i localtunnel` - -More details and to downlaod Sauce Connect visit: -https://wiki.saucelabs.com/display/DOCS/High+Availability+Sauce+Connect+Setup - -Examples: - - run_tests.py chrome - run_tests.py --suite list --interpreter jython firefox - run_tests.py chrome --scusername your_username --sckey account_key -""" - from __future__ import print_function from contextlib import contextmanager @@ -85,12 +43,14 @@ def unit_tests(): sys.exit(failures) -def acceptance_tests(interpreter, browser, suite, sauceusername, saucekey): +def acceptance_tests(interpreter, browser, rf_options=[], + sauce_username=None, sauce_key=None): if not os.path.exists(env.RESULTS_DIR): os.mkdir(env.RESULTS_DIR) with http_server(): - execute_tests(interpreter, browser, suite, sauceusername, saucekey) - failures = process_output(browser, suite) + execute_tests(interpreter, browser, rf_options, + sauce_username, sauce_key) + failures = process_output(browser, rf_options) if failures: print('\n{} critical test{} failed.' .format(failures, 's' if failures != 1 else '')) @@ -112,27 +72,29 @@ def http_server(): serverlog.close() -def execute_tests(interpreter, browser, suite, sauceusername, saucekey): +def execute_tests(interpreter, browser, rf_options, sauce_username, sauce_key): + options = [] runner = [interpreter, '-m', 'robot.run'] - options = [opt.format(browser=browser, - py_version=interpreter + sys.version[:3]) - for opt in ROBOT_OPTIONS] - if sauceusername and saucekey: - options.extend(get_sauce_conf(browser, sauceusername, saucekey)) + options.extend( + [opt.format(browser=browser, + py_version=interpreter + sys.version[:3]) + for opt in ROBOT_OPTIONS] + ) + options += rf_options + if sauce_username and sauce_key: + options.extend(get_sauce_conf(browser, sauce_username, sauce_key)) command = runner - if suite: - command += ['-s', suite] command += options + [env.ACCEPTANCE_TEST_DIR] - log_start(command, sauceusername, saucekey) + log_start(command, sauce_username, sauce_key) syslog = os.path.join(env.RESULTS_DIR, 'syslog.txt') subprocess.call( command, env=dict(os.environ, ROBOT_SYSLOG_FILE=syslog) ) -def log_start(command_list, sauceusername, saucekey): +def log_start(command_list, *hiddens): command = subprocess.list2cmdline(command_list) - for hidden in [sauceusername, saucekey]: + for hidden in hiddens: if hidden: command = command.replace(hidden, '*' * len(hidden)) print() @@ -140,82 +102,121 @@ def log_start(command_list, sauceusername, saucekey): print(command) -def get_sauce_conf(browser, sauceusername, saucekey): +def get_sauce_conf(browser, sauce_username, sauce_key): if browser == 'chrome' and env.TRAVIS: - conf = [] - else: - conf = [ - '--variable', 'SAUCE_USERNAME:{}'.format(sauceusername), - '--variable', 'SAUCE_ACCESS_KEY:{}'.format(saucekey), - '--variable', - 'REMOTE_URL:http://{}:{}@ondemand.saucelabs.com:80/wd/hub'.format( - sauceusername, saucekey - ), - '--variable', - 'DESIRED_CAPABILITIES:build:{0}-{1},tunnel-identifier:{0}'.format( - env.TRAVIS_JOB_NUMBER, browser - ) - ] - return conf - - -def process_output(browser, suite): + return [] + return [ + '--variable', 'SAUCE_USERNAME:{}'.format(sauce_username), + '--variable', 'SAUCE_ACCESS_KEY:{}'.format(sauce_key), + '--variable', + 'REMOTE_URL:http://{}:{}@ondemand.saucelabs.com:80/wd/hub'.format( + sauce_username, sauce_key + ), + '--variable', + 'DESIRED_CAPABILITIES:build:{0}-{1},tunnel-identifier:{0}'.format( + env.TRAVIS_JOB_NUMBER, browser + ) + ] + + +def process_output(browser, rf_options): print('Verifying results...') + options = [] output = os.path.join(env.RESULTS_DIR, 'output.xml') robotstatuschecker.process_output(output, verbose=False) - options = [opt.format(browser=browser) for opt in REBOT_OPTIONS] - if suite: - options += ['-s', suite] + options.extend([opt.format(browser=browser) for opt in REBOT_OPTIONS]) + options += rf_options try: rebot_cli(options + [output]) except SystemExit as exit: return exit.code -def sauce_credentials(sauceusername, saucekey): - if env.TRAVIS: +def sauce_credentials(sauce_username, sauce_key): + # Refactor method when removing env.py file + if env.TRAVIS and not sauce_username and sauce_key: username = env.SAUCE_USERNAME key = env.SAUCE_ACCESS_KEY else: - username = sauceusername - key = saucekey + username = sauce_username + key = sauce_key return username, key if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Library test runner') + parser = argparse.ArgumentParser( + description='Script to run Selenium2Library acceptance tests.', + formatter_class=argparse.RawDescriptionHelpFormatter, + epilog=( + 'Tests are executed using Robot Framework and results verified ' + 'automatically afterwards using `robotstatuschecker` tool. The ' + 'tool can be installed using `pip install robotstatuschecker` ' + 'and more information about it can be found from: ' + 'https://github.com/robotframework/statuschecker/. Notice that ' + 'initially some tests fail.\n\n' + 'When running test by using browser from Sauce labs, it is ' + 'required that the Sauce Connect is used. The Sauce Connect ' + 'allows the browser from Sauce Labs reach the acceptance test ' + 'webserver. The acceptance test uses tunnel with name ' + '`localtunnel` and therefore when establishing the Sauce Connect ' + 'tunnel use the following command:\n' + '`bin/sc -u YOUR_USERNAME -k YOUR_ACCESS_KEY -i localtunnel`\n\n' + 'More details and to downlaod Sauce Connect visit: ' + 'https://wiki.saucelabs.com/display/DOCS/High+Availability+Sauce+Connect+Setup\n\n' + 'It is posisble to pass Robot Framework command line arguments to ' + 'the test exection as a last arguments to the `run_tests.py`' + 'command. Example arguments like --test, --suite, --include and ' + '--exclude may be used to configure acceptance test execution. ' + 'The Robot Framework command line arguments are not displayed in ' + 'the optional arguments list in the help.\n\n' + 'Examples:\n\n' + 'python run_tests.py chrome\n' + 'run_tests.py --interpreter jython firefox --suite javascript\n' + 'python run_tests.py chrome --sauceusername your_username ' + '--saucekey account_key --suite javascript\n' + ' ' + ) + ) parser.add_argument( '--interpreter', + '-I', default='python', - help='Interpreter used run the test' + help=( + 'Any Python interpreter supported by the library (e.g. `python`, ' + '`jython` or `c:\\Python27\\python.exe`). By default set to ' + '`python`.)' + ) ) - parser.add_argument('browser', help='Browser used in testing') parser.add_argument( - '--suite', - '-s', - help='Selects the test suites by name.' + 'browser', + help='Any browser supported by the library (e.g. `chrome`or `firefox`)' ) parser.add_argument( - '--scusername', + '--sauceusername', + '-U', help='Username to order browser from SaucuLabs' ) parser.add_argument( - '--sckey', + '--saucekey', + '-K', help='Access key to order browser from SaucuLabs' ) - args = parser.parse_args() + args, rf_options = parser.parse_known_args() + print(rf_options) + browser = args.browser.lower().strip() if env.TRAVIS and browser != 'chrome' and env.TRAVIS_EVENT_TYPE != 'cron': print( - 'Can not run test with browser "{}" from SauceLabs\n' + 'Can not run test with browser "{}" from SauceLabs with PR.\n' 'SauceLabs can be used only when running with cron and from ' 'Selenium2Library master branch, but your event type ' - 'was "{}"'.format(browser, env.TRAVIS_EVENT_TYPE) + 'was "{}". Only Chrome is suported with PR and when using ' + 'Travis'.format(browser, env.TRAVIS_EVENT_TYPE) ) sys.exit(0) - sauceusername, saucekey = sauce_credentials( - args.scusername, args.sckey) + sauce_username, sauce_key = sauce_credentials( + args.sauceusername, args.saucekey) unit_tests() - acceptance_tests(args.interpreter, browser, args.suite, - sauceusername, saucekey) + acceptance_tests(args.interpreter, browser, rf_options, + sauce_username, sauce_key) From 60b2cc3532d9b7e0e504719a7d1fffb655b92428 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Mon, 2 Jan 2017 22:31:04 +0200 Subject: [PATCH 08/14] Added support for "py -2" for windows and test/README.rst --- BUILD.rst | 40 +++-------------------------- test/README.rst | 64 +++++++++++++++++++++++++++++++++++++++++++++++ test/run_tests.py | 5 +--- 3 files changed, 68 insertions(+), 41 deletions(-) create mode 100644 test/README.rst diff --git a/BUILD.rst b/BUILD.rst index 497e74a48..7456e56a5 100644 --- a/BUILD.rst +++ b/BUILD.rst @@ -26,44 +26,10 @@ test/ Unit and Acceptance Tests ------------------------- +To run tests give command:: + python test/run_tests.py chomre -The test directory contains everything needed to run Selenium2Library -tests with Robot Framework. This includes: - -- Unit tests under `unit` directory. -- Acceptance tests written with Robot Framework under `acceptance` - directory -- A very simple httpserver.py which is used to serve the html for tests in - `resources/testserver` -- A collection of simple html files under 'resources/html' directory -- Start-up scripts for executing the tests -- A copy of statuschecker.py for checking logged messages after the - execution, which requires the tests to run with log level DEBUG - -To run unit and acceptance tests, run:: - - python test/run_tests.py python|jython ff|ie|chrome [options] - -The first argument to the script defines the interpreter to be used -to run Robot. The second argument defines the browser to be used, -using the same browser tokens that you would use in your Robot -tests. - -Due to the structure of the tests, the directory containg the test -case files (`acceptance`) is always given to Robot as test data path. -To run only a subset of test cases, Robot command line arguments ---test, --suite, --include and --exclude may be used. - -Examples:: - - # Run all tests with Python and Firefox - python test/run_tests.py python ff - # Run only test suite `javascript` with Jython and Internet Explorer - python test/run_tests.py jython ie -s javascript - -To run just the unit tests, run:: - - python test/run_unit_tests.py +More details in test/README.rst Debugging Selenium2Library diff --git a/test/README.rst b/test/README.rst new file mode 100644 index 000000000..6a644bf7c --- /dev/null +++ b/test/README.rst @@ -0,0 +1,64 @@ +Testing and debugging +===================== +Requirements +------------ +Before running the test, install the dependecies:: + + pip install requirements.txt + pip install requirements-dev.txt + + +Unit and Acceptance Tests +------------------------- + +The test directory contains everything needed to run Selenium2Library +tests with Robot Framework. This includes: + +- Unit tests under `unit` directory. +- Acceptance tests written with Robot Framework under `acceptance` + directory +- A very simple `httpserver.py` which is used to serve the html for tests in + `resources/testserver` +- A collection of simple html files under `resources/html` directory +- Start-up scripts for executing the tests: `run_tests.py` and + `run_unit_tests.py` + +To run unit and acceptance tests, run:: + + python test/run_tests.py ff|ie|chrome + +Tests are executed using Robot Framework and results verified automatically +afterwards using `robotstatuschecker` tool. The tool can be installed using +`pip install robotstatuschecker` and more information about it can be found +from: https://github.com/robotframework/statuschecker/. Notice that initially +some tests fail. + + +It is posisble to pass Robot Framework command line arguments to the test +exection as a last arguments to the `run_tests.py` command. Example arguments +like --test, --suite, --include and --exclude may be used to configure +acceptance test execution. + +Examples:: + + python run_tests.py chrome + python run_tests.py --interpreter jython firefox --suite javascript + python run_tests.py chrome --sauceusername your_username --saucekey account_key --suite javascript + py -3 run_tests.py --interpreter "py -2" chrome --suite javascript + +To run just the unit tests, run:: + + python test/run_unit_tests.py + +Using Sauce Labs for acceptance tests +------------------------------------- + +When running test by using browser from Sauce labs, it is required that the +Sauce Connect is used. The Sauce Connect allows the browser from Sauce Labs +reach the acceptance test webserver. The acceptance test uses tunnel with +name `localtunnel` and therefore when establishing the Sauce Connect tunnel +use the following command:: + bin/sc -u YOUR_USERNAME -k YOUR_ACCESS_KEY -i localtunnel + +More details and to downlaod Sauce Connect visit: +https://wiki.saucelabs.com/display/DOCS/High+Availability+Sauce+Connect+Setup diff --git a/test/run_tests.py b/test/run_tests.py index fee02f018..db71e546c 100644 --- a/test/run_tests.py +++ b/test/run_tests.py @@ -74,7 +74,7 @@ def http_server(): def execute_tests(interpreter, browser, rf_options, sauce_username, sauce_key): options = [] - runner = [interpreter, '-m', 'robot.run'] + runner = interpreter.split() + ['-m', 'robot.run'] options.extend( [opt.format(browser=browser, py_version=interpreter + sys.version[:3]) @@ -201,10 +201,7 @@ def sauce_credentials(sauce_username, sauce_key): '-K', help='Access key to order browser from SaucuLabs' ) - args, rf_options = parser.parse_known_args() - print(rf_options) - browser = args.browser.lower().strip() if env.TRAVIS and browser != 'chrome' and env.TRAVIS_EVENT_TYPE != 'cron': print( From 377adf611b54b29d3c0b78ceb90baa3590fb4d5e Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 3 Jan 2017 00:46:50 +0200 Subject: [PATCH 09/14] Removed env.py --- test/env.py | 21 ------------------- test/run_tests.py | 53 +++++++++++++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 41 deletions(-) delete mode 100755 test/env.py diff --git a/test/env.py b/test/env.py deleted file mode 100755 index 7649810fa..000000000 --- a/test/env.py +++ /dev/null @@ -1,21 +0,0 @@ -import os -import sys - -ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) -UNIT_TEST_DIR = os.path.join(ROOT_DIR, "unit") -ACCEPTANCE_TEST_DIR = os.path.join(ROOT_DIR, "acceptance") -RESOURCES_DIR = os.path.join(ROOT_DIR, "resources") -TEST_LIBS_DIR = os.path.join(RESOURCES_DIR, "testlibs") -RESULTS_DIR = os.path.join(ROOT_DIR, "results") -HTTP_SERVER_FILE = os.path.join(RESOURCES_DIR, "testserver", "testserver.py") -SRC_DIR = os.path.join(ROOT_DIR, "..", "src") - -TRAVIS = os.environ.get("TRAVIS", False) -TRAVIS_EVENT_TYPE = os.environ.get("TRAVIS_EVENT_TYPE", None) -TRAVIS_JOB_NUMBER = os.environ.get("TRAVIS_JOB_NUMBER", "localtunnel") -SAUCE_USERNAME = os.environ.get("SAUCE_USERNAME", None) -SAUCE_ACCESS_KEY = os.environ.get("SAUCE_ACCESS_KEY", None) - - -sys.path.insert(0, SRC_DIR) -sys.path.append(UNIT_TEST_DIR) diff --git a/test/run_tests.py b/test/run_tests.py index db71e546c..45590a4fb 100644 --- a/test/run_tests.py +++ b/test/run_tests.py @@ -14,21 +14,35 @@ sys.exit('Required `robotstatuschecker` not installed.\n' 'Install it with `pip install robotstatuschecker`.') -import env from run_unit_tests import run_unit_tests +# Folder settings +ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) +ACCEPTANCE_TEST_DIR = os.path.join(ROOT_DIR, "acceptance") +RESOURCES_DIR = os.path.join(ROOT_DIR, "resources") +RESULTS_DIR = os.path.join(ROOT_DIR, "results") +SRC_DIR = os.path.normpath(os.path.join(ROOT_DIR, "..", "src")) +TEST_LIBS_DIR = os.path.join(RESOURCES_DIR, "testlibs") +HTTP_SERVER_FILE = os.path.join(RESOURCES_DIR, "testserver", "testserver.py") +# Travis settins for pull request +TRAVIS = os.environ.get("TRAVIS", False) +TRAVIS_EVENT_TYPE = os.environ.get("TRAVIS_EVENT_TYPE", None) +TRAVIS_JOB_NUMBER = os.environ.get("TRAVIS_JOB_NUMBER", "localtunnel") +SAUCE_USERNAME = os.environ.get("SAUCE_USERNAME", None) +SAUCE_ACCESS_KEY = os.environ.get("SAUCE_ACCESS_KEY", None) + ROBOT_OPTIONS = [ '--doc', 'Selenium2Library acceptance tests with {browser}', - '--outputdir', env.RESULTS_DIR, + '--outputdir', RESULTS_DIR, '--variable', 'BROWSER:{browser}', '--variable', 'PY_VERSION:{py_version}', '--report', 'NONE', '--log', 'NONE', '--loglevel', 'DEBUG', - '--pythonpath', os.pathsep.join([env.SRC_DIR, env.TEST_LIBS_DIR]), + '--pythonpath', os.pathsep.join([SRC_DIR, TEST_LIBS_DIR]), ] REBOT_OPTIONS = [ - '--outputdir', env.RESULTS_DIR, + '--outputdir', RESULTS_DIR, '--critical', 'regression', '--noncritical', 'inprogress', '--noncritical', 'known issue {browser}', @@ -45,8 +59,8 @@ def unit_tests(): def acceptance_tests(interpreter, browser, rf_options=[], sauce_username=None, sauce_key=None): - if not os.path.exists(env.RESULTS_DIR): - os.mkdir(env.RESULTS_DIR) + if not os.path.exists(RESULTS_DIR): + os.mkdir(RESULTS_DIR) with http_server(): execute_tests(interpreter, browser, rf_options, sauce_username, sauce_key) @@ -61,13 +75,13 @@ def acceptance_tests(interpreter, browser, rf_options=[], @contextmanager def http_server(): - serverlog = open(os.path.join(env.RESULTS_DIR, 'serverlog.txt'), 'w') - process = subprocess.Popen(['python', env.HTTP_SERVER_FILE, 'start'], + serverlog = open(os.path.join(RESULTS_DIR, 'serverlog.txt'), 'w') + process = subprocess.Popen(['python', HTTP_SERVER_FILE, 'start'], stdout=serverlog, stderr=subprocess.STDOUT) try: yield finally: - subprocess.call(['python', env.HTTP_SERVER_FILE, 'stop']) + subprocess.call(['python', HTTP_SERVER_FILE, 'stop']) process.wait() serverlog.close() @@ -84,9 +98,9 @@ def execute_tests(interpreter, browser, rf_options, sauce_username, sauce_key): if sauce_username and sauce_key: options.extend(get_sauce_conf(browser, sauce_username, sauce_key)) command = runner - command += options + [env.ACCEPTANCE_TEST_DIR] + command += options + [ACCEPTANCE_TEST_DIR] log_start(command, sauce_username, sauce_key) - syslog = os.path.join(env.RESULTS_DIR, 'syslog.txt') + syslog = os.path.join(RESULTS_DIR, 'syslog.txt') subprocess.call( command, env=dict(os.environ, ROBOT_SYSLOG_FILE=syslog) ) @@ -103,7 +117,7 @@ def log_start(command_list, *hiddens): def get_sauce_conf(browser, sauce_username, sauce_key): - if browser == 'chrome' and env.TRAVIS: + if browser == 'chrome' and TRAVIS: return [] return [ '--variable', 'SAUCE_USERNAME:{}'.format(sauce_username), @@ -114,7 +128,7 @@ def get_sauce_conf(browser, sauce_username, sauce_key): ), '--variable', 'DESIRED_CAPABILITIES:build:{0}-{1},tunnel-identifier:{0}'.format( - env.TRAVIS_JOB_NUMBER, browser + TRAVIS_JOB_NUMBER, browser ) ] @@ -122,7 +136,7 @@ def get_sauce_conf(browser, sauce_username, sauce_key): def process_output(browser, rf_options): print('Verifying results...') options = [] - output = os.path.join(env.RESULTS_DIR, 'output.xml') + output = os.path.join(RESULTS_DIR, 'output.xml') robotstatuschecker.process_output(output, verbose=False) options.extend([opt.format(browser=browser) for opt in REBOT_OPTIONS]) options += rf_options @@ -133,10 +147,9 @@ def process_output(browser, rf_options): def sauce_credentials(sauce_username, sauce_key): - # Refactor method when removing env.py file - if env.TRAVIS and not sauce_username and sauce_key: - username = env.SAUCE_USERNAME - key = env.SAUCE_ACCESS_KEY + if TRAVIS and not sauce_username and not sauce_key: + username = SAUCE_USERNAME + key = SAUCE_ACCESS_KEY else: username = sauce_username key = sauce_key @@ -203,13 +216,13 @@ def sauce_credentials(sauce_username, sauce_key): ) args, rf_options = parser.parse_known_args() browser = args.browser.lower().strip() - if env.TRAVIS and browser != 'chrome' and env.TRAVIS_EVENT_TYPE != 'cron': + if TRAVIS and browser != 'chrome' and TRAVIS_EVENT_TYPE != 'cron': print( 'Can not run test with browser "{}" from SauceLabs with PR.\n' 'SauceLabs can be used only when running with cron and from ' 'Selenium2Library master branch, but your event type ' 'was "{}". Only Chrome is suported with PR and when using ' - 'Travis'.format(browser, env.TRAVIS_EVENT_TYPE) + 'Travis'.format(browser, TRAVIS_EVENT_TYPE) ) sys.exit(0) sauce_username, sauce_key = sauce_credentials( From 50fc8da038a4c2025f3d1a6b1837d50f6a02e326 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 3 Jan 2017 23:34:42 +0200 Subject: [PATCH 10/14] Spell checks performed --- test/README.rst | 10 +++++----- test/run_tests.py | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/README.rst b/test/README.rst index 6a644bf7c..af2d9de38 100644 --- a/test/README.rst +++ b/test/README.rst @@ -2,7 +2,7 @@ Testing and debugging ===================== Requirements ------------ -Before running the test, install the dependecies:: +Before running the test, install the dependencies:: pip install requirements.txt pip install requirements-dev.txt @@ -34,8 +34,8 @@ from: https://github.com/robotframework/statuschecker/. Notice that initially some tests fail. -It is posisble to pass Robot Framework command line arguments to the test -exection as a last arguments to the `run_tests.py` command. Example arguments +It is possible to pass Robot Framework command line arguments to the test +execution as a last arguments to the `run_tests.py` command. Example arguments like --test, --suite, --include and --exclude may be used to configure acceptance test execution. @@ -55,10 +55,10 @@ Using Sauce Labs for acceptance tests When running test by using browser from Sauce labs, it is required that the Sauce Connect is used. The Sauce Connect allows the browser from Sauce Labs -reach the acceptance test webserver. The acceptance test uses tunnel with +reach the acceptance test web server. The acceptance test uses tunnel with name `localtunnel` and therefore when establishing the Sauce Connect tunnel use the following command:: bin/sc -u YOUR_USERNAME -k YOUR_ACCESS_KEY -i localtunnel -More details and to downlaod Sauce Connect visit: +More details and to download Sauce Connect visit: https://wiki.saucelabs.com/display/DOCS/High+Availability+Sauce+Connect+Setup diff --git a/test/run_tests.py b/test/run_tests.py index 45590a4fb..3ade1c8be 100644 --- a/test/run_tests.py +++ b/test/run_tests.py @@ -170,14 +170,14 @@ def sauce_credentials(sauce_username, sauce_key): 'When running test by using browser from Sauce labs, it is ' 'required that the Sauce Connect is used. The Sauce Connect ' 'allows the browser from Sauce Labs reach the acceptance test ' - 'webserver. The acceptance test uses tunnel with name ' + 'web server. The acceptance test uses tunnel with name ' '`localtunnel` and therefore when establishing the Sauce Connect ' 'tunnel use the following command:\n' '`bin/sc -u YOUR_USERNAME -k YOUR_ACCESS_KEY -i localtunnel`\n\n' 'More details and to downlaod Sauce Connect visit: ' 'https://wiki.saucelabs.com/display/DOCS/High+Availability+Sauce+Connect+Setup\n\n' - 'It is posisble to pass Robot Framework command line arguments to ' - 'the test exection as a last arguments to the `run_tests.py`' + 'It is possible to pass Robot Framework command line arguments to ' + 'the test execution as a last arguments to the `run_tests.py`' 'command. Example arguments like --test, --suite, --include and ' '--exclude may be used to configure acceptance test execution. ' 'The Robot Framework command line arguments are not displayed in ' From 2475ba34b7bf9ce63ccb79aeee5039b4b2b01aa8 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Sun, 8 Jan 2017 01:11:30 +0200 Subject: [PATCH 11/14] Fixed documentation based on comments --- BUILD.rst | 5 ++-- test/README.rst | 49 +++++++++++++++++++++++++----------- test/run_tests.py | 64 +++++++++++++++++++++++++---------------------- 3 files changed, 72 insertions(+), 46 deletions(-) mode change 100644 => 100755 test/run_tests.py diff --git a/BUILD.rst b/BUILD.rst index 7456e56a5..069ab03b8 100644 --- a/BUILD.rst +++ b/BUILD.rst @@ -27,9 +27,10 @@ test/ Unit and Acceptance Tests ------------------------- To run tests give command:: - python test/run_tests.py chomre -More details in test/README.rst + python test/run_tests.py + +More details in ``__ Debugging Selenium2Library diff --git a/test/README.rst b/test/README.rst index af2d9de38..78ae79b48 100644 --- a/test/README.rst +++ b/test/README.rst @@ -4,8 +4,8 @@ Requirements ------------ Before running the test, install the dependencies:: - pip install requirements.txt - pip install requirements-dev.txt + pip install -r requirements.txt + pip install -r requirements-dev.txt Unit and Acceptance Tests @@ -25,7 +25,7 @@ tests with Robot Framework. This includes: To run unit and acceptance tests, run:: - python test/run_tests.py ff|ie|chrome + python test/run_tests.py Tests are executed using Robot Framework and results verified automatically afterwards using `robotstatuschecker` tool. The tool can be installed using @@ -33,22 +33,27 @@ afterwards using `robotstatuschecker` tool. The tool can be installed using from: https://github.com/robotframework/statuschecker/. Notice that initially some tests fail. +Running test with different interpreter +--------------------------------------- -It is possible to pass Robot Framework command line arguments to the test -execution as a last arguments to the `run_tests.py` command. Example arguments -like --test, --suite, --include and --exclude may be used to configure -acceptance test execution. +By default the interpreter is set to `python` and it depends on the operating +system settings, which python is used by default. It is possible to run test +by using different interpreter by using the `--interpreter` command line +argument. -Examples:: +Starting from version 2.0 onwards the Selenium2Library is tested by using +Python 2 and 3. Other interpreters are not test by the development team. - python run_tests.py chrome - python run_tests.py --interpreter jython firefox --suite javascript - python run_tests.py chrome --sauceusername your_username --saucekey account_key --suite javascript - py -3 run_tests.py --interpreter "py -2" chrome --suite javascript -To run just the unit tests, run:: +Robot Framework command line arguments +-------------------------------------- + +It is possible to pass Robot Framework command line arguments to the test +execution as a last arguments to the `run_tests.py` command. It is recommended +to use arguments to select required suite or test for the execution when +developing new functionality for the library. Example like --test, --suite, +--include and --exclude. - python test/run_unit_tests.py Using Sauce Labs for acceptance tests ------------------------------------- @@ -58,7 +63,23 @@ Sauce Connect is used. The Sauce Connect allows the browser from Sauce Labs reach the acceptance test web server. The acceptance test uses tunnel with name `localtunnel` and therefore when establishing the Sauce Connect tunnel use the following command:: + bin/sc -u YOUR_USERNAME -k YOUR_ACCESS_KEY -i localtunnel More details and to download Sauce Connect visit: https://wiki.saucelabs.com/display/DOCS/High+Availability+Sauce+Connect+Setup + + +Examples +-------- + +Examples:: + + run_tests.py chrome + run_tests.py --interpreter jython firefox --suite javascript + run_tests.py chrome --sauceusername your_username --saucekey account_key --suite javascript + run_tests.py --interpreter "py -2" chrome --suite javascript + +To run just the unit tests, run:: + + python test/run_unit_tests.py diff --git a/test/run_tests.py b/test/run_tests.py old mode 100644 new mode 100755 index 3ade1c8be..b4156763a --- a/test/run_tests.py +++ b/test/run_tests.py @@ -159,36 +159,40 @@ def sauce_credentials(sauce_username, sauce_key): if __name__ == '__main__': parser = argparse.ArgumentParser( description='Script to run Selenium2Library acceptance tests.', - formatter_class=argparse.RawDescriptionHelpFormatter, - epilog=( - 'Tests are executed using Robot Framework and results verified ' - 'automatically afterwards using `robotstatuschecker` tool. The ' - 'tool can be installed using `pip install robotstatuschecker` ' - 'and more information about it can be found from: ' - 'https://github.com/robotframework/statuschecker/. Notice that ' - 'initially some tests fail.\n\n' - 'When running test by using browser from Sauce labs, it is ' - 'required that the Sauce Connect is used. The Sauce Connect ' - 'allows the browser from Sauce Labs reach the acceptance test ' - 'web server. The acceptance test uses tunnel with name ' - '`localtunnel` and therefore when establishing the Sauce Connect ' - 'tunnel use the following command:\n' - '`bin/sc -u YOUR_USERNAME -k YOUR_ACCESS_KEY -i localtunnel`\n\n' - 'More details and to downlaod Sauce Connect visit: ' - 'https://wiki.saucelabs.com/display/DOCS/High+Availability+Sauce+Connect+Setup\n\n' - 'It is possible to pass Robot Framework command line arguments to ' - 'the test execution as a last arguments to the `run_tests.py`' - 'command. Example arguments like --test, --suite, --include and ' - '--exclude may be used to configure acceptance test execution. ' - 'The Robot Framework command line arguments are not displayed in ' - 'the optional arguments list in the help.\n\n' - 'Examples:\n\n' - 'python run_tests.py chrome\n' - 'run_tests.py --interpreter jython firefox --suite javascript\n' - 'python run_tests.py chrome --sauceusername your_username ' - '--saucekey account_key --suite javascript\n' - ' ' - ) + formatter_class=argparse.RawTextHelpFormatter, + epilog=("""\ +Tests are executed using Robot Framework and results verified automatically \ +afterwards using `robotstatuschecker` tool. The tool can be installed using \ +`pip install robotstatuschecker` and more information about it can be found \ +from: \ +https://github.com/robotframework/statuschecker/. Notice that initially some \ +tests fail. + +When running test by using browser from Sauce labs, it is required that the \ +Sauce Connect is used. The Sauce Connect allows the browser from Sauce Labs \ +reach the acceptance test web server. The acceptance test uses tunnel with \ +name `localtunnel` and therefore when establishing the Sauce Connect tunnel \ +use the following command: + `bin/sc -u YOUR_USERNAME -k YOUR_ACCESS_KEY -i localtunnel` + +More details and to downlaod Sauce Connect visit: \ +https://wiki.saucelabs.com/display/DOCS/High+Availability+Sauce+Connect+Setup + +It is possible to pass Robot Framework command line arguments to the test \ +execution as a last arguments to the `run_tests.py` command. It is \ +recommended to use arguments to select required suite or test for the \ +execution when developing new functionality for the library. Example like \ +--test, --suite, --include and --exclude. + + +Examples: + + run_tests.py chrome + run_tests.py --interpreter jython firefox --suite javascript + run_tests.py chrome --sauceusername your_username --saucekey account_key \ +--suite javascript + +""") ) parser.add_argument( '--interpreter', From 6bdbbb0f9b9c7969341b83b6c629716dffe32d35 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Mon, 9 Jan 2017 22:43:57 +0200 Subject: [PATCH 12/14] Added doc string to the module Also the argperser is also using the module doc string. --- test/run_tests.py | 79 ++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/test/run_tests.py b/test/run_tests.py index b4156763a..8430a41e0 100755 --- a/test/run_tests.py +++ b/test/run_tests.py @@ -1,10 +1,43 @@ #!/usr/bin/env python +"""Script to run Selenium2Library acceptance tests. + +Tests are executed using Robot Framework and results verified automatically +afterwards using `robotstatuschecker` tool. The tool can be installed using +`pip install robotstatuschecker` and more information about it can be found +from: https://github.com/robotframework/statuschecker/. Notice that initially +some tests may fail. + +When running test by using browser from Sauce labs, it is required that the +Sauce Connect is used. The Sauce Connect allows the browser from Sauce Labs +reach the acceptance test web server. The acceptance test uses tunnel with +name `localtunnel` and therefore when establishing the Sauce Connect tunnel +use the following command: + `bin/sc -u YOUR_USERNAME -k YOUR_ACCESS_KEY -i localtunnel` + +More details and to downlaod Sauce Connect visit: +https://wiki.saucelabs.com/display/DOCS/High+Availability+Sauce+Connect+Setup + +It is possible to pass Robot Framework command line arguments to the test +execution as a last arguments to the `run_tests.py` command. It is +recommended to use arguments to select required suite or test for the +execution when developing new functionality for the library. Example like +--test, --suite, --include and --exclude. + +Examples: + + run_tests.py chrome + run_tests.py --interpreter jython firefox --suite javascript + run_tests.py chrome --sauceusername your_username --saucekey account_key \ +--suite javascript + +""" from __future__ import print_function from contextlib import contextmanager import os import sys import argparse +import textwrap import subprocess from robot import rebot_cli @@ -158,51 +191,19 @@ def sauce_credentials(sauce_username, sauce_key): if __name__ == '__main__': parser = argparse.ArgumentParser( - description='Script to run Selenium2Library acceptance tests.', + description=__doc__.splitlines()[0], formatter_class=argparse.RawTextHelpFormatter, - epilog=("""\ -Tests are executed using Robot Framework and results verified automatically \ -afterwards using `robotstatuschecker` tool. The tool can be installed using \ -`pip install robotstatuschecker` and more information about it can be found \ -from: \ -https://github.com/robotframework/statuschecker/. Notice that initially some \ -tests fail. - -When running test by using browser from Sauce labs, it is required that the \ -Sauce Connect is used. The Sauce Connect allows the browser from Sauce Labs \ -reach the acceptance test web server. The acceptance test uses tunnel with \ -name `localtunnel` and therefore when establishing the Sauce Connect tunnel \ -use the following command: - `bin/sc -u YOUR_USERNAME -k YOUR_ACCESS_KEY -i localtunnel` - -More details and to downlaod Sauce Connect visit: \ -https://wiki.saucelabs.com/display/DOCS/High+Availability+Sauce+Connect+Setup - -It is possible to pass Robot Framework command line arguments to the test \ -execution as a last arguments to the `run_tests.py` command. It is \ -recommended to use arguments to select required suite or test for the \ -execution when developing new functionality for the library. Example like \ ---test, --suite, --include and --exclude. - - -Examples: - - run_tests.py chrome - run_tests.py --interpreter jython firefox --suite javascript - run_tests.py chrome --sauceusername your_username --saucekey account_key \ ---suite javascript - -""") + epilog='\n'.join(__doc__.splitlines()[2:]) ) parser.add_argument( '--interpreter', '-I', default='python', - help=( - 'Any Python interpreter supported by the library (e.g. `python`, ' - '`jython` or `c:\\Python27\\python.exe`). By default set to ' - '`python`.)' - ) + help=textwrap.dedent("""\ + Any Python interpreter supported by the library. + E.g. `python`, `jython` or `c:\\Python27\\python.exe`. + By default set to `python`. + """) ) parser.add_argument( 'browser', From fe5e179710f941766097dfaa5062b790f8983484 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Mon, 9 Jan 2017 23:59:26 +0200 Subject: [PATCH 13/14] Fixed based on comments --- test/run_tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/run_tests.py b/test/run_tests.py index 8430a41e0..845031dcc 100755 --- a/test/run_tests.py +++ b/test/run_tests.py @@ -27,10 +27,10 @@ run_tests.py chrome run_tests.py --interpreter jython firefox --suite javascript - run_tests.py chrome --sauceusername your_username --saucekey account_key \ ---suite javascript + run_tests.py chrome --sauceusername your_username --saucekey account_key --suite javascript """ + from __future__ import print_function from contextlib import contextmanager From f19b194fd57082320e9bd72bceed98d0798d7ea8 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 10 Jan 2017 22:34:54 +0200 Subject: [PATCH 14/14] Fixed based on comments --- test/README.rst | 4 ++-- test/run_tests.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/README.rst b/test/README.rst index 78ae79b48..74f6924dc 100644 --- a/test/README.rst +++ b/test/README.rst @@ -42,14 +42,14 @@ by using different interpreter by using the `--interpreter` command line argument. Starting from version 2.0 onwards the Selenium2Library is tested by using -Python 2 and 3. Other interpreters are not test by the development team. +Python 2 and 3. Other interpreters are not tested by the development team. Robot Framework command line arguments -------------------------------------- It is possible to pass Robot Framework command line arguments to the test -execution as a last arguments to the `run_tests.py` command. It is recommended +execution as last arguments to the `run_tests.py` command. It is recommended to use arguments to select required suite or test for the execution when developing new functionality for the library. Example like --test, --suite, --include and --exclude. diff --git a/test/run_tests.py b/test/run_tests.py index 845031dcc..ca7f3ba45 100755 --- a/test/run_tests.py +++ b/test/run_tests.py @@ -18,7 +18,7 @@ https://wiki.saucelabs.com/display/DOCS/High+Availability+Sauce+Connect+Setup It is possible to pass Robot Framework command line arguments to the test -execution as a last arguments to the `run_tests.py` command. It is +execution as last arguments to the `run_tests.py` command. It is recommended to use arguments to select required suite or test for the execution when developing new functionality for the library. Example like --test, --suite, --include and --exclude.