From 0b040d1b1c4a53ffb193e537180466feed6da4d0 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Thu, 12 Jul 2018 23:46:15 +0300 Subject: [PATCH 1/8] Added approvaltests as dependency for development --- requirements-dev.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements-dev.txt b/requirements-dev.txt index bddcaaa75..a7c6f73b3 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,6 +3,7 @@ mockito >= 1.0.0 robotstatuschecker +approvaltests >= 0.2.2 # Include normal dependencies from requirements.txt. Makes it possible to use # requirements-dev.txt as a single requirement file in PyCharm and other IDEs. From 59f01dbd6fd191005e46f38586908f94dc1e90a3 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 13 Jul 2018 00:35:38 +0300 Subject: [PATCH 2/8] Approval reporter for diffuse --- utest/test/approvals_reporters.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 utest/test/approvals_reporters.json diff --git a/utest/test/approvals_reporters.json b/utest/test/approvals_reporters.json new file mode 100644 index 000000000..3ac5beb63 --- /dev/null +++ b/utest/test/approvals_reporters.json @@ -0,0 +1,6 @@ +[ + [ + "Diffuse", + "/usr/bin/diffuse" + ] +] \ No newline at end of file From f5add3f312562d1b3c6ff7d019502ca356f8d61b Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 13 Jul 2018 00:36:29 +0300 Subject: [PATCH 3/8] First approval test --- utest/test/keywords/approvaltests_config.json | 3 +++ ...wordsTest.test_get_javascript.approved.txt | 1 + utest/test/keywords/test_javascript.py | 23 +++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 utest/test/keywords/approvaltests_config.json create mode 100644 utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript.approved.txt create mode 100644 utest/test/keywords/test_javascript.py diff --git a/utest/test/keywords/approvaltests_config.json b/utest/test/keywords/approvaltests_config.json new file mode 100644 index 000000000..1ceea7eb0 --- /dev/null +++ b/utest/test/keywords/approvaltests_config.json @@ -0,0 +1,3 @@ +{ + "subdirectory": "approved_files" +} \ No newline at end of file diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript.approved.txt new file mode 100644 index 000000000..140a65a11 --- /dev/null +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript.approved.txt @@ -0,0 +1 @@ +code here \ No newline at end of file diff --git a/utest/test/keywords/test_javascript.py b/utest/test/keywords/test_javascript.py new file mode 100644 index 000000000..6ede666b3 --- /dev/null +++ b/utest/test/keywords/test_javascript.py @@ -0,0 +1,23 @@ +import os +import unittest + +from approvaltests.approvals import verify +from approvaltests.reporters.generic_diff_reporter_factory import GenericDiffReporterFactory + +from SeleniumLibrary.keywords import JavaScriptKeywords + + +class JavaScriptKeywordsTest(unittest.TestCase): + + @classmethod + 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() + + def test_get_javascript(self): + code = self.javascript._get_javascript_to_execute('code here') + verify(code, self.reporter) \ No newline at end of file From 15de1f52883ed47a93bfa2c260f2de67febafbcd Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 10 Aug 2018 21:34:39 +0300 Subject: [PATCH 4/8] Update approvaltests to 0.2.3 --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index a7c6f73b3..21f70296d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,7 +3,7 @@ mockito >= 1.0.0 robotstatuschecker -approvaltests >= 0.2.2 +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. From 8e800bc0b37d17c708c3a9a027f339c728833050 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 10 Aug 2018 22:20:17 +0300 Subject: [PATCH 5/8] Adding skip for Jython --- utest/test/keywords/test_javascript.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/utest/test/keywords/test_javascript.py b/utest/test/keywords/test_javascript.py index 6ede666b3..11c1c4fdc 100644 --- a/utest/test/keywords/test_javascript.py +++ b/utest/test/keywords/test_javascript.py @@ -1,8 +1,16 @@ import os import unittest -from approvaltests.approvals import verify -from approvaltests.reporters.generic_diff_reporter_factory import GenericDiffReporterFactory +from robot.utils 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 @@ -10,6 +18,7 @@ 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__) @@ -18,6 +27,7 @@ def setUpClass(cls): 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) \ No newline at end of file From 5660ce932117123700da68a740ada37c0e49df2e Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 10 Aug 2018 23:19:38 +0300 Subject: [PATCH 6/8] Added ApprovalTests to utest README --- utest/README.rst | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/utest/README.rst b/utest/README.rst index c40c482bb..fdc46b683 100644 --- a/utest/README.rst +++ b/utest/README.rst @@ -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/ From 6815eabdedcf8de5766be92e34e49cd3cb001973 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 10 Aug 2018 23:38:06 +0300 Subject: [PATCH 7/8] Do not install ApprovalTests with Jython --- .travis.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b14a6b4a7..3cb04d5e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: From e2d9a492d5fb67400f794abdd0e3688e24c18425 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Sat, 11 Aug 2018 00:11:23 +0300 Subject: [PATCH 8/8] Add JYTHON to SL --- src/SeleniumLibrary/utils/platform.py | 4 ++++ utest/test/keywords/test_javascript.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 src/SeleniumLibrary/utils/platform.py diff --git a/src/SeleniumLibrary/utils/platform.py b/src/SeleniumLibrary/utils/platform.py new file mode 100644 index 000000000..6a6dbe981 --- /dev/null +++ b/src/SeleniumLibrary/utils/platform.py @@ -0,0 +1,4 @@ +import sys + +# Can be removed when Robot Framework 2.8.4 is not supported. +JYTHON = sys.platform.startswith('java') diff --git a/utest/test/keywords/test_javascript.py b/utest/test/keywords/test_javascript.py index 11c1c4fdc..32bac4ed4 100644 --- a/utest/test/keywords/test_javascript.py +++ b/utest/test/keywords/test_javascript.py @@ -1,7 +1,7 @@ import os import unittest -from robot.utils import JYTHON +from SeleniumLibrary.utils.platform import JYTHON try: from approvaltests.approvals import verify from approvaltests.reporters.generic_diff_reporter_factory import GenericDiffReporterFactory