Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ before_script:
- echo $INTERPRETER
- $INTERPRETER --version
- $INTERPRETER -m pip install .
- $INTERPRETER -m pip install -r requirements-dev.txt
- if [ "$JYTHON" == "true" ]; then
$INTERPRETER -m pip install mockito;
$INTERPRETER -m pip install robotstatuschecker;
$INTERPRETER -m pip install -r requirements.txt;
else
$INTERPRETER -m pip install -r requirements-dev.txt;
fi
- $INTERPRETER -m pip install selenium==$SELENIUM
- $INTERPRETER -m pip install robotframework==$ROBOTFRAMEWORK
script:
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

mockito >= 1.0.0
robotstatuschecker
approvaltests >= 0.2.3

# Include normal dependencies from requirements.txt. Makes it possible to use
# requirements-dev.txt as a single requirement file in PyCharm and other IDEs.
Expand Down
4 changes: 4 additions & 0 deletions src/SeleniumLibrary/utils/platform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import sys

# Can be removed when Robot Framework 2.8.4 is not supported.
JYTHON = sys.platform.startswith('java')
20 changes: 18 additions & 2 deletions utest/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,25 @@ Unit test can be executed by running::

The utest directory contains everything needed to run SeleniumLibrary unit tests.
This includes:
- Unit test in `test` folder.
- Unit test runner: `run.py`

- Unit test in `test` folder.
- Unit test runner: `run.py`

Unit test are executed using the interpreter which starts the `run.py` script.

ApprovalTests
-------------
For unit test, it is possible to use `ApprovalTests`_ framework. ApprovalTests
provides an easy and visual way to compare strings in unit tests. For more
details, please read `ApprovalTests`_ documentation and `ApprovalTests blog post`_.
The downside of ApprovalTests is that it does not work when using `Jython`_
as an interpreter. Therefore all unit tests using ApprovalTests imports
must handled with `try/except ImportError:` and skipped with:
`@unittest.skipIf(JYTHON, 'ApprovalTest does not work with Jython')`. The `JYTHON` is
imported from `from robot.utils import JYTHON`


.. _unittest: https://docs.python.org/3/library/unittest.html
.. _ApprovalTests: https://github.com/approvals/ApprovalTests.Python
.. _ApprovalTests blog post: http://blog.approvaltests.com/
.. _Jython: http://www.jython.org/
6 changes: 6 additions & 0 deletions utest/test/approvals_reporters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
[
"Diffuse",
"/usr/bin/diffuse"
]
]
3 changes: 3 additions & 0 deletions utest/test/keywords/approvaltests_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"subdirectory": "approved_files"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
code here
33 changes: 33 additions & 0 deletions utest/test/keywords/test_javascript.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
import unittest

from SeleniumLibrary.utils.platform import JYTHON
try:
from approvaltests.approvals import verify
from approvaltests.reporters.generic_diff_reporter_factory import GenericDiffReporterFactory
except ImportError:
if JYTHON:
verify = None
GenericDiffReporterFactory = None
else:
raise

from SeleniumLibrary.keywords import JavaScriptKeywords


class JavaScriptKeywordsTest(unittest.TestCase):

@classmethod
@unittest.skipIf(JYTHON, 'ApprovalTest does not work with Jython')
def setUpClass(cls):
cls.javascript = JavaScriptKeywords(None)
path = os.path.dirname(__file__)
reporter_json = os.path.abspath(os.path.join(path, '..', 'approvals_reporters.json'))
factory = GenericDiffReporterFactory()
factory.load(reporter_json)
cls.reporter = factory.get_first_working()

@unittest.skipIf(JYTHON, 'ApprovalTest does not work with Jython')
def test_get_javascript(self):
code = self.javascript._get_javascript_to_execute('code here')
verify(code, self.reporter)