Repository navigation
Modified how Travis CI is used with the project. - #716
Conversation
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.
|
Perhaps for time being we should test selenium 3 with Python 2. Because we are not yet Python 3 compatible and therefore the build for selenium 3 fails. |
HelioGuilherme66
left a comment
There was a problem hiding this comment.
The major issue is with run_tests.py.
I'll do more testing on it.
If possible amend the text for PR there are some typos.
| 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 ' |
There was a problem hiding this comment.
Typo. it should be:
'SauceLabs can be used only when running with cron and from '
| packages: | ||
| - google-chrome-stable | ||
| before_install: | ||
| - wget http://chromedriver.storage.googleapis.com/2.26/chromedriver_linux64.zip |
There was a problem hiding this comment.
CDVERSION=`curl http://chromedriver.storage.googleapis.com/LATEST_RELEASE`
wget http://chromedriver.storage.googleapis.com/$CDVERSION/chromedriver_linux64.zip
| '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 ' |
There was a problem hiding this comment.
Typo. it should be:
'Selenium2Library master branch, but your event type '
|
|
||
| run_tests.py python chrome | ||
| run_tests.py jython c:\\Python35\\python.exe --test "Click element" | ||
| run_tests.py jython firefox --suite list |
There was a problem hiding this comment.
There was a change in the argument passing (mentioned on doc), but the actual code does not look like it has been changed.
Example should be:
run_tests.py --interpreter jython firefox --suite list
There are more fixes like on some typos. I'll stop the review here, but will test this file run_tests.py for better review.
|
The way it is coded, we can never run tests locally with Firefox, it aborts execution by not being allowed to run in Sauce Labs. |
|
Ah, true. I know how to fix it. Thanks for pointing it out |
|
Updated |
| 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 |
There was a problem hiding this comment.
Better to have --suite at end because is a list.
run_tests.py --interpreter jython firefox --suite list
There was a problem hiding this comment.
The list was a bad example, because it refers to list.robot file and not to Python list. Changed to example to javascript
|
I still think you could merge my PR in your fork. There are some other minor improvements. |
| 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) |
There was a problem hiding this comment.
If these are only used by run_tests.py, we could consider moving all this there and could probably remove the whole env.py. Not really related to this PR, though.
There was a problem hiding this comment.
I agree. But the PR is getting big and perhaps doing it in a separate PR is better and cleaner.
| --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. |
There was a problem hiding this comment.
Doesn't argparse provide help text? No need to have it here in that case. The whole module docstring could be just a simple description of the script, possibly with few examples, that could then be passed to argparse as the general description. More comprehensive docs could then be moved to README.(rst|md) in this directory.
There was a problem hiding this comment.
Yes it does and it's actually quite good help system. Dividing this with readme file and argparse is good idea. At least the argparse help must be enhanced.
|
|
||
|
|
||
| def acceptance_tests(interpreter, browser, options): | ||
| def acceptance_tests(interpreter, browser, suite, sauceusername, saucekey): |
There was a problem hiding this comment.
As a style comment, I'd prefer sauce_username and sauce_key as argument names. If they have default values like None, it would be good to add them to the signature.
| options.extend(get_sauce_conf(browser, sauceusername, saucekey)) | ||
| command = runner | ||
| if suite: | ||
| command += ['-s', suite] |
There was a problem hiding this comment.
'--suite' would be a little more explicit than '-s'.
There was a problem hiding this comment.
Moved to use https://docs.python.org/2.7/library/argparse.html#partial-parsing which allows to keep the old functional to give random Robot Framework arguments from command line. Therefore this comment is not anymore valid one.
| log_start(command) | ||
| if sauceusername and saucekey: | ||
| options.extend(get_sauce_conf(browser, sauceusername, saucekey)) | ||
| command = runner |
There was a problem hiding this comment.
This looks strange. Could either just rename runner to command originally or use something like
command = runner + (['--suite', suite] if suite else [])There was a problem hiding this comment.
Moved to use https://docs.python.org/2.7/library/argparse.html#partial-parsing which allows to keep the old functional to give random Robot Framework arguments from command line. Therefore this comment is not anymore valid one.
|
|
||
|
|
||
| def log_start(command_list): | ||
| def log_start(command_list, sauceusername, saucekey): |
There was a problem hiding this comment.
Could just have the signature as command_list, *hidden and then later for item in hidden.
| def process_output(browser, cli_options): | ||
| def get_sauce_conf(browser, sauceusername, saucekey): | ||
| if browser == 'chrome' and env.TRAVIS: | ||
| conf = [] |
There was a problem hiding this comment.
Why not just return []? Would avoid the big else block below.
There was a problem hiding this comment.
Hmm, I am usually on favor for single return statement for each method. But perhaps this is clearer.
| robotstatuschecker.process_output(output, verbose=False) | ||
| options = [opt.format(browser=browser) for opt in REBOT_OPTIONS] | ||
| if suite: | ||
| options += ['-s', suite] |
There was a problem hiding this comment.
This shouldn't be needed at all. Enough to filter based on suite when starting execution.
There was a problem hiding this comment.
This might still valid, but the code has changed quite a look. Please take a new look and send comment if something is needed.
| else: | ||
| username = sauceusername | ||
| key = saucekey | ||
| return username, key |
There was a problem hiding this comment.
Getting configs from env and from the command line is really confusing. Also, wouldn't it be better for command line options to have higher precedence if given?
There was a problem hiding this comment.
Agree. Made a temporally change and will be fixed better when removing env.py file in separate fix.
| sys.exit(__doc__) | ||
| parser = argparse.ArgumentParser(description='Library test runner') | ||
| parser.add_argument( | ||
| '--interpreter', |
There was a problem hiding this comment.
Should add a short option like -I for such a commonly needed option.
| help='Selects the test suites by name.' | ||
| ) | ||
| parser.add_argument( | ||
| '--scusername', |
There was a problem hiding this comment.
--sauceusername would be a lot better name. Could add a short option like -U if needed.
| help='Username to order browser from SaucuLabs' | ||
| ) | ||
| parser.add_argument( | ||
| '--sckey', |
There was a problem hiding this comment.
--saucekey optionally with a short option like '-K` would be better.
| 'Can not run test with browser "{}" from SauceLabs\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) |
There was a problem hiding this comment.
Apparently only Chrome is supported here? Error should mention that too.
There was a problem hiding this comment.
Yes, when running tests with Travis against PR, then it is only possible to use Chrome. Improved text.
| default='python', | ||
| help='Interpreter used run the test' | ||
| ) | ||
| parser.add_argument('browser', help='Browser used in testing') |
There was a problem hiding this comment.
If we only can run tests on Travis with Chrome, having that as the default browser would probably be a good idea. Could then make this an option like --browser with a short option -B.
There was a problem hiding this comment.
I kind a liked to this way. For me it makes the travis matrix easier to read. Also it saves few letter for typing, now it can be used with:
run_tests.py chrome
instead of:
run_tests.py -B chrome
|
|
||
| def execute_tests(interpreter, browser, cli_options): | ||
| def execute_tests(interpreter, browser, suite, sauceusername, saucekey): | ||
| runner = [interpreter, '-m', 'robot.run'] |
There was a problem hiding this comment.
We should support also interpreter with spaces like py -3 that's very handy on Windows. I guess that can already be given from the command line like --interpreter "py -3" but this code won't handle it. Could just use interpreter.split() to split the command. shlex.split(interpreter) would be safer but I doubt we need it here.
There was a problem hiding this comment.
Not done. I agree that this is useful but did not have time to code this in today.
pekkaklarck
left a comment
There was a problem hiding this comment.
Code changes look good to me in general. I added some comments mainly related to the style. Few things I'd do related to this that aren't necessarily in the scope of this PR:
-
Get rid off the
env.pyscript entirely. Would be much cleaner to handle all configuration in runner scripts themselves. I doubt there's much acceptance and unit test runners share anyway. -
Add
README.(rst|md)into the test directory. -
Handle interpreter like
py -3(added separate comment about this).
|
I am busy with Xmas preparation, so making the changes will go after Xmas. Thanks from the comments (in a good way and not in a Finnish sartastic way) and happy holidays to all. |
Not it is possible to pass Robot Framework command line arguments as last argument to run_tests.py command.
|
|
But as @HelioGuilherme66 pointed out and was reminded by this robotframework/robotframework#2502, should we minimum supported Python 3 version by Robot Framework (Python 3.3), should we use something else or should we always live with the latest Python 3 available from Travis? Which, according to Travis documentation is is Python 3.5 (there is some support for Python 3.6 nightly builds, according the documentation)? |
|
Added
|
|
Decided to remove |
|
@pekkaklarck would you have time to take a look? |
pekkaklarck
left a comment
There was a problem hiding this comment.
Looks good to me in general. I mainly briefly looked at the docs, though. Check my comments and merge when you think this is ready.
| Unit and Acceptance Tests | ||
| ------------------------- | ||
| To run tests give command:: | ||
| python test/run_tests.py chomre |
There was a problem hiding this comment.
- chomre -> chrome
- If
run_tests.pyis executable, could just usetest/run_tests.py chrome - Should it rather be something generic like
<browser>instead ofchrome?
| To run just the unit tests, run:: | ||
|
|
||
| python test/run_unit_tests.py | ||
| More details in test/README.rst |
There was a problem hiding this comment.
Formatted like <test/README.rst>_ this would create a link to the README file when rendered as HTML on GitHub.
| Before running the test, install the dependencies:: | ||
|
|
||
| pip install requirements.txt | ||
| pip install requirements-dev.txt |
|
|
||
| To run unit and acceptance tests, run:: | ||
|
|
||
| python test/run_tests.py ff|ie|chrome |
There was a problem hiding this comment.
Perhaps just test/run_tests.py <browser>?
| 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 |
There was a problem hiding this comment.
- I'd remove
pythonandpy -3from the beginning altogether. - Using
--interpreterhasn't been explained.
| 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 |
There was a problem hiding this comment.
There probably should be an empty row after ::.
| 'run_tests.py --interpreter jython firefox --suite javascript\n' | ||
| 'python run_tests.py chrome --sauceusername your_username ' | ||
| '--saucekey account_key --suite javascript\n' | ||
| ' ' |
There was a problem hiding this comment.
Should definitely format this using Python's triplequoted strings. Alternatively could use __doc__ here.
There was a problem hiding this comment.
The argparse is making some things hard to present, but perhaps this is more clearer way. Although I do not like the back slash as line continuation, but it is the lesser evil this time.
| 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. |
There was a problem hiding this comment.
Do all RF's options work or can you only use some? Earlier versions had a restriction to use only some but is that fixed?
There was a problem hiding this comment.
In this version all goes, but that might not be always a good idea. Enhanced documentation to recommend few arguments.
pekkaklarck
left a comment
There was a problem hiding this comment.
I'd add module docstring to run_tests.py and then pass description and epilog to argparse as __doc__.spilitlines()[0] and '\n'.join(__doc__.splitlines()[2:]), respectively. Scripts having docstring is generally nice and it would be handy to reuse it with argparse.
Also the argperser is also using the module doc string.
|
Done |
| 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. |
There was a problem hiding this comment.
Verb and not name. It should be: "Other interpreters are not tested by the development team."
| -------------------------------------- | ||
|
|
||
| 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 |
There was a problem hiding this comment.
Remove single article. It should be: "... execution as a last arguments to the run_tests.py command."
| browser: Any browser supported by the library (e.g. `chrome`, `firefox`) | ||
| options: Additional command line options passed to Robot Framework | ||
| 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 |
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.