From 95cca6d5af45aefd5865bd73599f43c45af9a9d6 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Thu, 16 Aug 2018 23:00:12 +0300 Subject: [PATCH 01/27] JavaScript parser improvement --- src/SeleniumLibrary/keywords/javascript.py | 31 +++++++++++++- ...t.test_separate_code_and_args.approved.txt | 8 ++++ ...separate_code_and_args_errors.approved.txt | 7 ++++ utest/test/keywords/test_javascript.py | 42 +++++++++++++++++-- 4 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args.approved.txt create mode 100644 utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index 27d4d24bf..09bc96ad5 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -77,13 +77,40 @@ def execute_async_javascript(self, *code): self.info("Executing Asynchronous JavaScript:\n%s" % js) return self.driver.execute_async_script(js) - def _get_javascript_to_execute(self, lines): - code = ''.join(lines) + def _get_javascript_to_execute(self, code): + code = ''.join(code) path = code.replace('/', os.sep) if os.path.isabs(path) and os.path.isfile(path): code = self._read_javascript_from_file(path) return code + def _separate_code_and_args(self, code): + if not code: + raise ValueError('There must be at least one JavaScript line defined.') + js_code = [] + js_args = [] + get_code = True + get_args = False + found_code, found_args = False, False + for item in code: + if item == 'JAVASCRIPT': + if found_code: + raise ValueError('JAVASCRIPT found two times in code.') + get_code, found_code = True, True + get_args = False + continue + if item == 'ARGUMENTS': + if found_args: + raise ValueError('ARGUMENTS found two times in code.') + get_code = False + get_args, found_args = True, True + continue + if get_code: + js_code.append(item) + if get_args: + js_args.append(item) + return js_code, js_args + def _read_javascript_from_file(self, path): self.info('Reading JavaScript from file %s.' .format(path.replace(os.sep, '/'), path), html=True) diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args.approved.txt new file mode 100644 index 000000000..7f7df4b43 --- /dev/null +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args.approved.txt @@ -0,0 +1,8 @@ +code and args + +0) (['code1'], []) +1) (['code1', 'code2'], []) +2) (['code1', 'code2'], []) +3) (['code1', 'code2'], []) +4) (['code1', 'code2'], ['arg1', 'arg2']) +5) (['code1', 'code2'], ['arg1', 'arg2']) diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt new file mode 100644 index 000000000..045097050 --- /dev/null +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt @@ -0,0 +1,7 @@ +error + +6) There must be at least one JavaScript line defined. +7) ARGUMENTS found two times in code. +8) JAVASCRIPT found two times in code. +9) ARGUMENTS found two times in code. +10) ARGUMENTS found two times in code. diff --git a/utest/test/keywords/test_javascript.py b/utest/test/keywords/test_javascript.py index 32bac4ed4..80cbe6d6b 100644 --- a/utest/test/keywords/test_javascript.py +++ b/utest/test/keywords/test_javascript.py @@ -1,9 +1,10 @@ +import itertools import os import unittest from SeleniumLibrary.utils.platform import JYTHON try: - from approvaltests.approvals import verify + from approvaltests.approvals import verify, verify_all from approvaltests.reporters.generic_diff_reporter_factory import GenericDiffReporterFactory except ImportError: if JYTHON: @@ -20,7 +21,7 @@ class JavaScriptKeywordsTest(unittest.TestCase): @classmethod @unittest.skipIf(JYTHON, 'ApprovalTest does not work with Jython') def setUpClass(cls): - cls.javascript = JavaScriptKeywords(None) + cls.js = JavaScriptKeywords(None) path = os.path.dirname(__file__) reporter_json = os.path.abspath(os.path.join(path, '..', 'approvals_reporters.json')) factory = GenericDiffReporterFactory() @@ -29,5 +30,38 @@ def setUpClass(cls): @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 + code = self.js._get_javascript_to_execute('code here') + verify(code, self.reporter) + + @unittest.skipIf(JYTHON, 'ApprovalTest does not work with Jython') + def test_separate_code_and_args(self): + all_results = [] + code_examples = [ + ('code1',), ('code1', 'code2'), + ('JAVASCRIPT', 'code1', 'code2'), + ('JAVASCRIPT', 'code1', 'code2', 'ARGUMENTS'), + ('JAVASCRIPT', 'code1', 'code2', 'ARGUMENTS', 'arg1', 'arg2'), + ('ARGUMENTS', 'arg1', 'arg2', 'JAVASCRIPT', 'code1', 'code2')] + for code in code_examples: + code_and_args = self.js._separate_code_and_args(code) + all_results.append(code_and_args) + verify_all('code and args', all_results, reporter=self.reporter) + + @unittest.skipIf(JYTHON, 'ApprovalTest does not work with Jython') + def test_separate_code_and_args_errors(self): + code_examples = [ + (), + ('ARGUMENTS', 'arg1', 'ARGUMENTS', 'arg1', 'JAVASCRIPT', + 'code1', 'JAVASCRIPT', 'code2'), + ('JAVASCRIPT', 'code1', 'JAVASCRIPT', 'code2'), + ('JAVASCRIPT', 'code1', 'ARGUMENTS', 'arg1', 'ARGUMENTS', 'arg1'), + ('ARGUMENTS', 'arg1', 'ARGUMENTS', 'arg1', 'JAVASCRIPT', 'code1') + ] + all_results = [] + for code in code_examples: + try: + self.js._separate_code_and_args(code) + raise AssertionError('Method should fail, but it did not') + except Exception as error: + all_results.append(error) + verify_all('error', all_results, reporter=self.reporter) \ No newline at end of file From c0f14c86195aca86a0c12a6e6ea24f5fc962f4ef Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 21 Aug 2018 22:32:00 +0300 Subject: [PATCH 02/27] Better error message --- src/SeleniumLibrary/keywords/javascript.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index 09bc96ad5..ea17a5451 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -87,21 +87,19 @@ def _get_javascript_to_execute(self, code): def _separate_code_and_args(self, code): if not code: raise ValueError('There must be at least one JavaScript line defined.') - js_code = [] - js_args = [] - get_code = True - get_args = False + js_code, js_args = [], [] + get_code, get_args = False, False found_code, found_args = False, False for item in code: if item == 'JAVASCRIPT': if found_code: - raise ValueError('JAVASCRIPT found two times in code.') + raise ValueError('JAVASCRIPT marker was found two times in code.') get_code, found_code = True, True get_args = False continue if item == 'ARGUMENTS': if found_args: - raise ValueError('ARGUMENTS found two times in code.') + raise ValueError('ARGUMENTS marker was found two times in code.') get_code = False get_args, found_args = True, True continue From ce78b7c71bc8544cd0997c3ce814dbb6bd2be357 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 21 Aug 2018 22:33:48 +0300 Subject: [PATCH 03/27] Also code JAVASCRIPT code raises error --- src/SeleniumLibrary/keywords/javascript.py | 2 ++ ...sTest.test_separate_code_and_args_errors.approved.txt | 9 +++++---- utest/test/keywords/test_javascript.py | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index ea17a5451..21760b1ae 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -103,6 +103,8 @@ def _separate_code_and_args(self, code): get_code = False get_args, found_args = True, True continue + if not get_code and not get_args: + get_code, found_code = True, True if get_code: js_code.append(item) if get_args: diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt index 045097050..4b298667d 100644 --- a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt @@ -1,7 +1,8 @@ error 6) There must be at least one JavaScript line defined. -7) ARGUMENTS found two times in code. -8) JAVASCRIPT found two times in code. -9) ARGUMENTS found two times in code. -10) ARGUMENTS found two times in code. +7) ARGUMENTS marker was found two times in code. +8) JAVASCRIPT marker was found two times in code. +9) ARGUMENTS marker was found two times in code. +10) JAVASCRIPT marker was found two times in code. +11) ARGUMENTS marker was found two times in code. diff --git a/utest/test/keywords/test_javascript.py b/utest/test/keywords/test_javascript.py index 80cbe6d6b..22389b76b 100644 --- a/utest/test/keywords/test_javascript.py +++ b/utest/test/keywords/test_javascript.py @@ -55,6 +55,7 @@ def test_separate_code_and_args_errors(self): 'code1', 'JAVASCRIPT', 'code2'), ('JAVASCRIPT', 'code1', 'JAVASCRIPT', 'code2'), ('JAVASCRIPT', 'code1', 'ARGUMENTS', 'arg1', 'ARGUMENTS', 'arg1'), + ('code1', 'JAVASCRIPT', 'code1' 'ARGUMENTS', 'arg1',), ('ARGUMENTS', 'arg1', 'ARGUMENTS', 'arg1', 'JAVASCRIPT', 'code1') ] all_results = [] From 175120a9ef090d2570c4155849729473062872b8 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 21 Aug 2018 22:48:18 +0300 Subject: [PATCH 04/27] Taking code and arg separator in use --- src/SeleniumLibrary/keywords/javascript.py | 35 ++++++++++--------- ...wordsTest.test_get_javascript.approved.txt | 2 +- utest/test/keywords/test_javascript.py | 5 +-- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index 21760b1ae..fddcc0014 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -48,9 +48,10 @@ def execute_javascript(self, *code): | ${sum} = | `Execute JavaScript` | return 1 + 1; | | `Should Be Equal` | ${sum} | ${2} | """ - js = self._get_javascript_to_execute(code) - self.info("Executing JavaScript:\n%s" % js) - return self.driver.execute_script(js) + js_code, js_args = self._get_javascript_to_execute(code) + self.info("Executing JavaScript:\n%s\nBy using arguments %s" + % (js_code, js_args)) + return self.driver.execute_script(js_code, *js_args) @keyword def execute_async_javascript(self, *code): @@ -73,16 +74,18 @@ def execute_async_javascript(self, *code): | ... | window.setTimeout(answer, 2000); | | `Should Be Equal` | ${result} | text | """ - js = self._get_javascript_to_execute(code) - self.info("Executing Asynchronous JavaScript:\n%s" % js) - return self.driver.execute_async_script(js) + js_code, js_args = self._get_javascript_to_execute(code) + self.info("Executing Asynchronous JavaScript:\n%s\nBy using arguments %s" + % (js_code, js_args)) + return self.driver.execute_async_script(js_code, *js_args) def _get_javascript_to_execute(self, code): - code = ''.join(code) - path = code.replace('/', os.sep) - if os.path.isabs(path) and os.path.isfile(path): - code = self._read_javascript_from_file(path) - return code + js_code, js_args = self._separate_code_and_args(code) + js_code = ''.join(js_code) + path = js_code.replace('/', os.sep) + if os.path.isfile(path): + js_code = self._read_javascript_from_file(path) + return js_code, js_args def _separate_code_and_args(self, code): if not code: @@ -90,14 +93,14 @@ def _separate_code_and_args(self, code): js_code, js_args = [], [] get_code, get_args = False, False found_code, found_args = False, False - for item in code: - if item == 'JAVASCRIPT': + for line in code: + if line == 'JAVASCRIPT': if found_code: raise ValueError('JAVASCRIPT marker was found two times in code.') get_code, found_code = True, True get_args = False continue - if item == 'ARGUMENTS': + if line == 'ARGUMENTS': if found_args: raise ValueError('ARGUMENTS marker was found two times in code.') get_code = False @@ -106,9 +109,9 @@ def _separate_code_and_args(self, code): if not get_code and not get_args: get_code, found_code = True, True if get_code: - js_code.append(item) + js_code.append(line) if get_args: - js_args.append(item) + js_args.append(line) return js_code, js_args def _read_javascript_from_file(self, path): 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 index 140a65a11..7f2c07d4c 100644 --- a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript.approved.txt +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript.approved.txt @@ -1 +1 @@ -code here \ No newline at end of file +codehere + [] \ No newline at end of file diff --git a/utest/test/keywords/test_javascript.py b/utest/test/keywords/test_javascript.py index 22389b76b..16f6f2ffd 100644 --- a/utest/test/keywords/test_javascript.py +++ b/utest/test/keywords/test_javascript.py @@ -30,8 +30,9 @@ def setUpClass(cls): @unittest.skipIf(JYTHON, 'ApprovalTest does not work with Jython') def test_get_javascript(self): - code = self.js._get_javascript_to_execute('code here') - verify(code, self.reporter) + code, args = self.js._get_javascript_to_execute(('code', 'here')) + result = '%s + %s' % (code, args) + verify(result, self.reporter) @unittest.skipIf(JYTHON, 'ApprovalTest does not work with Jython') def test_separate_code_and_args(self): From c942c59836aaf637e2ad9ed7c05125f2904d453c Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 21 Aug 2018 23:00:39 +0300 Subject: [PATCH 05/27] Fixed acceptance tests --- atest/acceptance/keywords/javascript.robot | 2 ++ 1 file changed, 2 insertions(+) diff --git a/atest/acceptance/keywords/javascript.robot b/atest/acceptance/keywords/javascript.robot index 3e248ecd1..8bcf6a006 100644 --- a/atest/acceptance/keywords/javascript.robot +++ b/atest/acceptance/keywords/javascript.robot @@ -22,6 +22,7 @@ Mouse Down On Link Execute Javascript [Documentation] LOG 2 Executing JavaScript: ... window.add_content('button_target', 'Inserted directly') + ... By using arguments [] Execute Javascript window.add_content('button_target', 'Inserted directly') Page Should Contain Inserted directly @@ -29,6 +30,7 @@ Execute Javascript from File [Documentation] LOG 2:1 REGEXP: Reading JavaScript from file .* ... LOG 2:2 Executing JavaScript: ... window.add_content('button_target', 'Inserted via file') + ... By using arguments [] Execute Javascript ${CURDIR}/executed_by_execute_javascript.js Page Should Contain Inserted via file From 177d67af26848ff6dec98dd6fa31b50cb0345d77 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 21 Aug 2018 23:42:22 +0300 Subject: [PATCH 06/27] Adding tests --- atest/acceptance/keywords/javascript.robot | 36 +++++++++++++++++++--- src/SeleniumLibrary/keywords/javascript.py | 10 +++--- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/atest/acceptance/keywords/javascript.robot b/atest/acceptance/keywords/javascript.robot index 8bcf6a006..b84864f31 100644 --- a/atest/acceptance/keywords/javascript.robot +++ b/atest/acceptance/keywords/javascript.robot @@ -20,17 +20,45 @@ Mouse Down On Link Mouse Up link_mousedown Execute Javascript - [Documentation] LOG 2 Executing JavaScript: + [Documentation] + ... LOG 2 Executing JavaScript: ... window.add_content('button_target', 'Inserted directly') - ... By using arguments [] + ... By using argument(s): + ... "" Execute Javascript window.add_content('button_target', 'Inserted directly') Page Should Contain Inserted directly +Execute Javascript With ARGUMENTS and JAVASCRIPT Marker + [Documentation] + Execute Javascript + ... ARGUMENTS + ... 123 + ... JAVASCRIPT + ... alert(arguments[0]); + Alert Should Be Present 123 timeout=10 s + +Execute Javascript With JAVASCRIPT and ARGUMENTS Marker + Execute Javascript + ... JAVASCRIPT + ... alert(arguments[0]); + ... ARGUMENTS + ... 123 + Alert Should Be Present 123 timeout=10 s + +Execute Javascript With ARGUMENTS Marker Only + Execute Javascript + ... alert(arguments[0]); + ... ARGUMENTS + ... 123 + Alert Should Be Present 123 timeout=10 s + Execute Javascript from File - [Documentation] LOG 2:1 REGEXP: Reading JavaScript from file .* + [Documentation] + ... LOG 2:1 REGEXP: Reading JavaScript from file .*executed_by_execute_javascript.* ... LOG 2:2 Executing JavaScript: ... window.add_content('button_target', 'Inserted via file') - ... By using arguments [] + ... By using argument(s): + ... "" Execute Javascript ${CURDIR}/executed_by_execute_javascript.js Page Should Contain Inserted via file diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index fddcc0014..30b940608 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -49,8 +49,8 @@ def execute_javascript(self, *code): | `Should Be Equal` | ${sum} | ${2} | """ js_code, js_args = self._get_javascript_to_execute(code) - self.info("Executing JavaScript:\n%s\nBy using arguments %s" - % (js_code, js_args)) + self.info('Executing JavaScript:\n%s\nBy using argument(s):\n"%s"' + % (js_code, ', '.join(js_args))) return self.driver.execute_script(js_code, *js_args) @keyword @@ -75,8 +75,8 @@ def execute_async_javascript(self, *code): | `Should Be Equal` | ${result} | text | """ js_code, js_args = self._get_javascript_to_execute(code) - self.info("Executing Asynchronous JavaScript:\n%s\nBy using arguments %s" - % (js_code, js_args)) + self.info('Executing Asynchronous JavaScript:\n%s\nBy using argument(s):\n"%s"' + % (js_code, ', '.join(js_args))) return self.driver.execute_async_script(js_code, *js_args) def _get_javascript_to_execute(self, code): @@ -116,6 +116,6 @@ def _separate_code_and_args(self, code): def _read_javascript_from_file(self, path): self.info('Reading JavaScript from file %s.' - .format(path.replace(os.sep, '/'), path), html=True) + % (path.replace(os.sep, '/'), path), html=True) with open(path) as file: return file.read().strip() From 105edfc827e092e20082be738da4b029035dfc92 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 21 Aug 2018 23:46:59 +0300 Subject: [PATCH 07/27] Tuning unit tests --- utest/test/keywords/test_javascript.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/utest/test/keywords/test_javascript.py b/utest/test/keywords/test_javascript.py index 16f6f2ffd..d552b2c45 100644 --- a/utest/test/keywords/test_javascript.py +++ b/utest/test/keywords/test_javascript.py @@ -44,8 +44,7 @@ def test_separate_code_and_args(self): ('JAVASCRIPT', 'code1', 'code2', 'ARGUMENTS', 'arg1', 'arg2'), ('ARGUMENTS', 'arg1', 'arg2', 'JAVASCRIPT', 'code1', 'code2')] for code in code_examples: - code_and_args = self.js._separate_code_and_args(code) - all_results.append(code_and_args) + all_results.append(self.js_reporter(code)) verify_all('code and args', all_results, reporter=self.reporter) @unittest.skipIf(JYTHON, 'ApprovalTest does not work with Jython') @@ -61,9 +60,11 @@ def test_separate_code_and_args_errors(self): ] all_results = [] for code in code_examples: - try: - self.js._separate_code_and_args(code) - raise AssertionError('Method should fail, but it did not') - except Exception as error: - all_results.append(error) - verify_all('error', all_results, reporter=self.reporter) \ No newline at end of file + all_results.append(self.js_reporter(code)) + verify_all('error', all_results, reporter=self.reporter) + + def js_reporter(self, code): + try: + return self.js._separate_code_and_args(code) + except Exception as error: + return error From b09e17147f894d2ba978f44179b719c68b992a2d Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Mon, 27 Aug 2018 22:08:08 +0300 Subject: [PATCH 08/27] Updated approvaltests to 0.2.4 --- requirements-dev.txt | 2 +- ...t.test_separate_code_and_args_errors.approved.txt | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 21f70296d..af2ac9005 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,7 +3,7 @@ mockito >= 1.0.0 robotstatuschecker -approvaltests >= 0.2.3 +approvaltests >= 0.2.4 # Include normal dependencies from requirements.txt. Makes it possible to use # requirements-dev.txt as a single requirement file in PyCharm and other IDEs. diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt index 4b298667d..28b3d3292 100644 --- a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt @@ -1,8 +1,8 @@ error -6) There must be at least one JavaScript line defined. -7) ARGUMENTS marker was found two times in code. -8) JAVASCRIPT marker was found two times in code. -9) ARGUMENTS marker was found two times in code. -10) JAVASCRIPT marker was found two times in code. -11) ARGUMENTS marker was found two times in code. +0) There must be at least one JavaScript line defined. +1) ARGUMENTS marker was found two times in code. +2) JAVASCRIPT marker was found two times in code. +3) ARGUMENTS marker was found two times in code. +4) JAVASCRIPT marker was found two times in code. +5) ARGUMENTS marker was found two times in code. From 9ce0b72d44b8181a21b2f13cec37618017cc5e38 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Mon, 27 Aug 2018 22:14:10 +0300 Subject: [PATCH 09/27] Fixed missing new line --- utest/test/keywords/approvaltests_config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utest/test/keywords/approvaltests_config.json b/utest/test/keywords/approvaltests_config.json index 1ceea7eb0..550e66434 100644 --- a/utest/test/keywords/approvaltests_config.json +++ b/utest/test/keywords/approvaltests_config.json @@ -1,3 +1,3 @@ { "subdirectory": "approved_files" -} \ No newline at end of file +} From 8410ef7a6fc1c74130f3bf80e27378d6afd8eeb9 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Mon, 27 Aug 2018 22:14:50 +0300 Subject: [PATCH 10/27] Adding logging check --- atest/acceptance/keywords/javascript.robot | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/atest/acceptance/keywords/javascript.robot b/atest/acceptance/keywords/javascript.robot index b84864f31..43762748c 100644 --- a/atest/acceptance/keywords/javascript.robot +++ b/atest/acceptance/keywords/javascript.robot @@ -46,10 +46,16 @@ Execute Javascript With JAVASCRIPT and ARGUMENTS Marker Alert Should Be Present 123 timeout=10 s Execute Javascript With ARGUMENTS Marker Only + [Documentation] + ... LOG 2 Executing JavaScript: + ... alert(arguments[0]); + ... By using argument(s): + ... "123, 0987" Execute Javascript ... alert(arguments[0]); ... ARGUMENTS ... 123 + ... 0987 Alert Should Be Present 123 timeout=10 s Execute Javascript from File From dc4fc2f1431f79193f5189d2525a49bf61f9e033 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Mon, 27 Aug 2018 23:01:39 +0300 Subject: [PATCH 11/27] Fixed keyword documentation --- src/SeleniumLibrary/keywords/javascript.py | 30 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index 30b940608..4d7f9ab67 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -23,7 +23,7 @@ class JavaScriptKeywords(LibraryComponent): @keyword def execute_javascript(self, *code): - """Executes the given JavaScript code. + """Executes the given JavaScript code with possible arguments. ``code`` may contain multiple lines of code and may be divided into multiple cells in the test data. In that case, the parts are @@ -42,11 +42,22 @@ def execute_javascript(self, *code): This keyword returns whatever the executed JavaScript code returns. Return values are converted to the appropriate Python types. + Starting from SeleniumLibrary 3.2 it is possible to provide JavaScript + [https://seleniumhq.github.io/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html#selenium.webdriver.remote.webdriver.WebDriver.execute_script| + arguments] as part of ``code`` argument. The JavaScript code and + arguments must be separated with `JAVASCRIPT` and `ARGUMENTS` statements + and must used exactly with this format. If the Javascript code is + first, then the `JAVASCRIPT` statement is optional. The order of + `JAVASCRIPT` and `ARGUMENTS` statements can swapped, but if `ARGUMENTS` + is first statement, then `JAVASCRIPT` statement is mandatory. It is only + allowed to use `JAVASCRIPT` and `ARGUMENTS` statements one time in the + ``code`` argument. + Examples: | `Execute JavaScript` | window.myFunc('arg1', 'arg2') | | `Execute JavaScript` | ${CURDIR}/js_to_execute.js | - | ${sum} = | `Execute JavaScript` | return 1 + 1; | - | `Should Be Equal` | ${sum} | ${2} | + | `Execute JavaScript` | alert(arguments[0]); | ARGUMENTS | 123 | + | `Execute JavaScript` | ARGUMENTS | 123 | JAVASCRIPT | alert(arguments[0]); | """ js_code, js_args = self._get_javascript_to_execute(code) self.info('Executing JavaScript:\n%s\nBy using argument(s):\n"%s"' @@ -55,7 +66,7 @@ def execute_javascript(self, *code): @keyword def execute_async_javascript(self, *code): - """Executes asynchronous JavaScript code. + """Executes asynchronous JavaScript code with possible arguments. Similar to `Execute Javascript` except that scripts executed with this keyword must explicitly signal they are finished by invoking the @@ -65,6 +76,17 @@ def execute_async_javascript(self, *code): Scripts must complete within the script timeout or this keyword will fail. See the `Timeouts` section for more information. + Starting from SeleniumLibrary 3.2 it is possible to provide JavaScript + [https://seleniumhq.github.io/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html#selenium.webdriver.remote.webdriver.WebDriver.execute_async_script| + arguments] as part of ``code`` argument. The JavaScript code and + and must used exactly with this format. If the Javascript code is + and must use exactly the previous format. If the Javascript code is + first, then the `JAVASCRIPT` statement is optional. The order of + `JAVASCRIPT` and `ARGUMENTS` statements can swapped, but if `ARGUMENTS` + is first statement, then `JAVASCRIPT` statement is mandatory. It is only + allowed to use `JAVASCRIPT` and `ARGUMENTS` statements one time in the + ``code`` argument. + Examples: | `Execute Async JavaScript` | var callback = arguments[arguments.length - 1]; window.setTimeout(callback, 2000); | | `Execute Async JavaScript` | ${CURDIR}/async_js_to_execute.js | From eae867dcd3269632003ef680f321d8f5895eb916 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Mon, 27 Aug 2018 23:13:02 +0300 Subject: [PATCH 12/27] Refactoring tests --- atest/acceptance/keywords/async_javascript.robot | 12 +++++++++++- atest/acceptance/keywords/javascript.robot | 1 - 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/atest/acceptance/keywords/async_javascript.robot b/atest/acceptance/keywords/async_javascript.robot index 69d78fdea..2a9f8fcbd 100644 --- a/atest/acceptance/keywords/async_javascript.robot +++ b/atest/acceptance/keywords/async_javascript.robot @@ -6,9 +6,19 @@ Resource ../resource.robot *** Test Cases *** Should Not Timeout If Callback Invoked Immediately - ${result} = Execute Async Javascript arguments[arguments.length - 1](123); + ${result} = Execute Async Javascript + ... JAVASCRIPT + ... arguments[arguments.length - 1](123); Should Be Equal ${result} ${123} +Execute Async Javascript With ARGUMENTS and JAVASCRIPT Marker + Execute Async Javascript + ... ARGUMENTS + ... 123 + ... JAVASCRIPT + ... alert(arguments[0]); + Alert Should Be Present 123 timeout=10 s + Should Be Able To Return Javascript Primitives From Async Scripts Neither None Nor Undefined ${result} = Execute Async Javascript arguments[arguments.length - 1](123); Should Be Equal ${result} ${123} diff --git a/atest/acceptance/keywords/javascript.robot b/atest/acceptance/keywords/javascript.robot index 43762748c..8385a9ba8 100644 --- a/atest/acceptance/keywords/javascript.robot +++ b/atest/acceptance/keywords/javascript.robot @@ -29,7 +29,6 @@ Execute Javascript Page Should Contain Inserted directly Execute Javascript With ARGUMENTS and JAVASCRIPT Marker - [Documentation] Execute Javascript ... ARGUMENTS ... 123 From 1296c3e0f226b6c206f4093a79770f3f6c655615 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Mon, 27 Aug 2018 23:18:44 +0300 Subject: [PATCH 13/27] Removed unused import --- utest/test/keywords/test_javascript.py | 1 - 1 file changed, 1 deletion(-) diff --git a/utest/test/keywords/test_javascript.py b/utest/test/keywords/test_javascript.py index d552b2c45..598c9651a 100644 --- a/utest/test/keywords/test_javascript.py +++ b/utest/test/keywords/test_javascript.py @@ -1,4 +1,3 @@ -import itertools import os import unittest From 8f9f12e313026697ded3287af598ae27d74843ab Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Mon, 27 Aug 2018 23:48:27 +0300 Subject: [PATCH 14/27] Improving unit tests --- src/SeleniumLibrary/keywords/javascript.py | 2 ++ ...st.test_get_javascript_no_code.approved.txt | 1 + ...st.test_separate_code_and_args.approved.txt | 10 +++++++--- ..._separate_code_and_args_errors.approved.txt | 1 + utest/test/keywords/test_javascript.py | 18 ++++++++++++++++-- 5 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code.approved.txt diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index 4d7f9ab67..342c71073 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -103,6 +103,8 @@ def execute_async_javascript(self, *code): def _get_javascript_to_execute(self, code): js_code, js_args = self._separate_code_and_args(code) + if not js_code: + raise ValueError('JavaScript code was found not found in `code` argument.') js_code = ''.join(js_code) path = js_code.replace('/', os.sep) if os.path.isfile(path): diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code.approved.txt new file mode 100644 index 000000000..b2cc112b3 --- /dev/null +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code.approved.txt @@ -0,0 +1 @@ +JavaScript code was found not found in `code` argument. \ No newline at end of file diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args.approved.txt index 7f7df4b43..76d990ed4 100644 --- a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args.approved.txt +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args.approved.txt @@ -3,6 +3,10 @@ code and args 0) (['code1'], []) 1) (['code1', 'code2'], []) 2) (['code1', 'code2'], []) -3) (['code1', 'code2'], []) -4) (['code1', 'code2'], ['arg1', 'arg2']) -5) (['code1', 'code2'], ['arg1', 'arg2']) +3) (['javascript', 'code1', 'code2'], []) +4) (['code1', 'code2'], []) +5) (['code1', 'code2', 'argUMENTs'], []) +6) (['code1', 'code2'], []) +7) (['code1', 'code2'], ['arg1', 'arg2']) +8) (['code1', 'code2'], ['arg1', 'arg2']) +9) (['aRGUMENTS', 'arg1', 'arg2', 'jAVASCRIPT', 'code1', 'code2'], []) diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt index 28b3d3292..bb9979137 100644 --- a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt @@ -6,3 +6,4 @@ error 3) ARGUMENTS marker was found two times in code. 4) JAVASCRIPT marker was found two times in code. 5) ARGUMENTS marker was found two times in code. +6) JAVASCRIPT marker was found two times in code. diff --git a/utest/test/keywords/test_javascript.py b/utest/test/keywords/test_javascript.py index 598c9651a..60556fbe8 100644 --- a/utest/test/keywords/test_javascript.py +++ b/utest/test/keywords/test_javascript.py @@ -33,15 +33,28 @@ def test_get_javascript(self): result = '%s + %s' % (code, args) verify(result, self.reporter) + @unittest.skipIf(JYTHON, 'ApprovalTest does not work with Jython') + def test_get_javascript_no_code(self): + code = ('ARGUMENTS', 'arg1', 'arg1') + try: + self.js._get_javascript_to_execute(code) + except Exception as error: + pass + verify(str(error), self.reporter) + @unittest.skipIf(JYTHON, 'ApprovalTest does not work with Jython') def test_separate_code_and_args(self): all_results = [] code_examples = [ ('code1',), ('code1', 'code2'), ('JAVASCRIPT', 'code1', 'code2'), + ('javascript', 'code1', 'code2'), ('JAVASCRIPT', 'code1', 'code2', 'ARGUMENTS'), + ('JAVASCRIPT', 'code1', 'code2', 'argUMENTs'), + ('ARGUMENTS', 'JAVASCRIPT', 'code1', 'code2'), ('JAVASCRIPT', 'code1', 'code2', 'ARGUMENTS', 'arg1', 'arg2'), - ('ARGUMENTS', 'arg1', 'arg2', 'JAVASCRIPT', 'code1', 'code2')] + ('ARGUMENTS', 'arg1', 'arg2', 'JAVASCRIPT', 'code1', 'code2'), + ('aRGUMENTS', 'arg1', 'arg2', 'jAVASCRIPT', 'code1', 'code2'),] for code in code_examples: all_results.append(self.js_reporter(code)) verify_all('code and args', all_results, reporter=self.reporter) @@ -55,7 +68,8 @@ def test_separate_code_and_args_errors(self): ('JAVASCRIPT', 'code1', 'JAVASCRIPT', 'code2'), ('JAVASCRIPT', 'code1', 'ARGUMENTS', 'arg1', 'ARGUMENTS', 'arg1'), ('code1', 'JAVASCRIPT', 'code1' 'ARGUMENTS', 'arg1',), - ('ARGUMENTS', 'arg1', 'ARGUMENTS', 'arg1', 'JAVASCRIPT', 'code1') + ('ARGUMENTS', 'arg1', 'ARGUMENTS', 'arg1', 'JAVASCRIPT', 'code1'), + ('aRGUMENtS', 'arg1', 'arg2', 'JAVASCRIPT', 'code1', 'code2'), ] all_results = [] for code in code_examples: From 64d7904dc4af172be0a7d0c1057d13477689c17e Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 28 Aug 2018 00:01:54 +0300 Subject: [PATCH 15/27] Fixing error in unit test for Py3 --- utest/test/keywords/test_javascript.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utest/test/keywords/test_javascript.py b/utest/test/keywords/test_javascript.py index 60556fbe8..67386b921 100644 --- a/utest/test/keywords/test_javascript.py +++ b/utest/test/keywords/test_javascript.py @@ -39,8 +39,8 @@ def test_get_javascript_no_code(self): try: self.js._get_javascript_to_execute(code) except Exception as error: - pass - verify(str(error), self.reporter) + result = str(error) + verify(str(result), self.reporter) @unittest.skipIf(JYTHON, 'ApprovalTest does not work with Jython') def test_separate_code_and_args(self): From 90a2a76eb48883d768b5aeff423bb6d9e7a46536 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 28 Aug 2018 17:03:05 +0300 Subject: [PATCH 16/27] Improved docs and error --- src/SeleniumLibrary/keywords/javascript.py | 37 ++++++++++------------ 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index 342c71073..18f8dc7ae 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -25,11 +25,12 @@ class JavaScriptKeywords(LibraryComponent): def execute_javascript(self, *code): """Executes the given JavaScript code with possible arguments. - ``code`` may contain multiple lines of code and may be divided into - multiple cells in the test data. In that case, the parts are - concatenated together without adding spaces. + ``code`` may be divided into multiple cells in the test data and + ``code`` may contain multiple lines of code and arguments. In that case, + the JavaScript code parts are concatenated together without adding + spaces and optional arguments are separated from ``code``. - If ``code`` is an absolute path to an existing file, the JavaScript + If ``code`` is a path to an existing file, the JavaScript to execute will be read from that file. Forward slashes work as a path separator on all operating systems. @@ -45,12 +46,12 @@ def execute_javascript(self, *code): Starting from SeleniumLibrary 3.2 it is possible to provide JavaScript [https://seleniumhq.github.io/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html#selenium.webdriver.remote.webdriver.WebDriver.execute_script| arguments] as part of ``code`` argument. The JavaScript code and - arguments must be separated with `JAVASCRIPT` and `ARGUMENTS` statements + arguments must be separated with `JAVASCRIPT` and `ARGUMENTS` markers and must used exactly with this format. If the Javascript code is - first, then the `JAVASCRIPT` statement is optional. The order of - `JAVASCRIPT` and `ARGUMENTS` statements can swapped, but if `ARGUMENTS` - is first statement, then `JAVASCRIPT` statement is mandatory. It is only - allowed to use `JAVASCRIPT` and `ARGUMENTS` statements one time in the + first, then the `JAVASCRIPT` marker is optional. The order of + `JAVASCRIPT` and `ARGUMENTS` markers can swapped, but if `ARGUMENTS` + is first marker, then `JAVASCRIPT` marker is mandatory. It is only + allowed to use `JAVASCRIPT` and `ARGUMENTS` markers only one time in the ``code`` argument. Examples: @@ -78,16 +79,9 @@ def execute_async_javascript(self, *code): Starting from SeleniumLibrary 3.2 it is possible to provide JavaScript [https://seleniumhq.github.io/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html#selenium.webdriver.remote.webdriver.WebDriver.execute_async_script| - arguments] as part of ``code`` argument. The JavaScript code and - and must used exactly with this format. If the Javascript code is - and must use exactly the previous format. If the Javascript code is - first, then the `JAVASCRIPT` statement is optional. The order of - `JAVASCRIPT` and `ARGUMENTS` statements can swapped, but if `ARGUMENTS` - is first statement, then `JAVASCRIPT` statement is mandatory. It is only - allowed to use `JAVASCRIPT` and `ARGUMENTS` statements one time in the - ``code`` argument. + arguments] as part of ``code`` argument. See `Execute Javascript` for + more details. - Examples: | `Execute Async JavaScript` | var callback = arguments[arguments.length - 1]; window.setTimeout(callback, 2000); | | `Execute Async JavaScript` | ${CURDIR}/async_js_to_execute.js | | ${result} = | `Execute Async JavaScript` | @@ -104,7 +98,7 @@ def execute_async_javascript(self, *code): def _get_javascript_to_execute(self, code): js_code, js_args = self._separate_code_and_args(code) if not js_code: - raise ValueError('JavaScript code was found not found in `code` argument.') + raise ValueError('JavaScript code was not found from code argument.') js_code = ''.join(js_code) path = js_code.replace('/', os.sep) if os.path.isfile(path): @@ -113,14 +107,15 @@ def _get_javascript_to_execute(self, code): def _separate_code_and_args(self, code): if not code: - raise ValueError('There must be at least one JavaScript line defined.') + raise ValueError('There must be at least one argument defined.') js_code, js_args = [], [] get_code, get_args = False, False found_code, found_args = False, False for line in code: if line == 'JAVASCRIPT': if found_code: - raise ValueError('JAVASCRIPT marker was found two times in code.') + message = 'JAVASCRIPT marker was found two times in code.' + raise ValueError(message) get_code, found_code = True, True get_args = False continue From 6258d38fd089f5ad280c5e5924da0d4ca1c6059f Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 28 Aug 2018 17:03:41 +0300 Subject: [PATCH 17/27] Test reading js from file with arguments --- atest/acceptance/keywords/javascript.robot | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/atest/acceptance/keywords/javascript.robot b/atest/acceptance/keywords/javascript.robot index 8385a9ba8..ebb2fdcc2 100644 --- a/atest/acceptance/keywords/javascript.robot +++ b/atest/acceptance/keywords/javascript.robot @@ -67,6 +67,13 @@ Execute Javascript from File Execute Javascript ${CURDIR}/executed_by_execute_javascript.js Page Should Contain Inserted via file +Execute Javascript from File With ARGUMENTS Marker + Execute Javascript + ... ${CURDIR}/javascript_alert.js + ... ARGUMENTS + ... 123 + Alert Should Be Present 123 timeout=10 s + Open Context Menu [Tags] Known Issue Safari Go To Page "javascript/context_menu.html" From 693977d1758a22fff05cd093397ccf9eebdae0ce Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 28 Aug 2018 17:04:11 +0300 Subject: [PATCH 18/27] Small fix to unit test --- utest/test/keywords/test_javascript.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utest/test/keywords/test_javascript.py b/utest/test/keywords/test_javascript.py index 67386b921..9be5404d0 100644 --- a/utest/test/keywords/test_javascript.py +++ b/utest/test/keywords/test_javascript.py @@ -40,7 +40,7 @@ def test_get_javascript_no_code(self): self.js._get_javascript_to_execute(code) except Exception as error: result = str(error) - verify(str(result), self.reporter) + verify(result, self.reporter) @unittest.skipIf(JYTHON, 'ApprovalTest does not work with Jython') def test_separate_code_and_args(self): From af1dd1d5e7c2d0b95f7ecec8b64798283683ba01 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 28 Aug 2018 17:04:45 +0300 Subject: [PATCH 19/27] New approved files for fixing error messages --- ...aScriptKeywordsTest.test_get_javascript_no_code.approved.txt | 2 +- ...KeywordsTest.test_separate_code_and_args_errors.approved.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code.approved.txt index b2cc112b3..5936febda 100644 --- a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code.approved.txt +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code.approved.txt @@ -1 +1 @@ -JavaScript code was found not found in `code` argument. \ No newline at end of file +JavaScript code was not found from code argument. \ No newline at end of file diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt index bb9979137..cac098a94 100644 --- a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt @@ -1,6 +1,6 @@ error -0) There must be at least one JavaScript line defined. +0) There must be at least one argument defined. 1) ARGUMENTS marker was found two times in code. 2) JAVASCRIPT marker was found two times in code. 3) ARGUMENTS marker was found two times in code. From a5bb24741654ccf7a29bca274f6cba86d6e71ee5 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 28 Aug 2018 17:29:30 +0300 Subject: [PATCH 20/27] Refactoring code and arg separator --- src/SeleniumLibrary/keywords/javascript.py | 15 ++++++++------- ...est_separate_code_and_args_errors.approved.txt | 12 ++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index 18f8dc7ae..98a432c88 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -112,16 +112,17 @@ def _separate_code_and_args(self, code): get_code, get_args = False, False found_code, found_args = False, False for line in code: - if line == 'JAVASCRIPT': - if found_code: - message = 'JAVASCRIPT marker was found two times in code.' - raise ValueError(message) + if line == 'JAVASCRIPT' and found_code: + message = 'JAVASCRIPT marker was found two times in the code.' + raise ValueError(message) + if line == 'JAVASCRIPT' and not found_code: get_code, found_code = True, True get_args = False continue - if line == 'ARGUMENTS': - if found_args: - raise ValueError('ARGUMENTS marker was found two times in code.') + if line == 'ARGUMENTS' and found_args: + message = 'ARGUMENTS marker was found two times in the code.' + raise ValueError(message) + if line == 'ARGUMENTS' and not found_args: get_code = False get_args, found_args = True, True continue diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt index cac098a94..a873de4c6 100644 --- a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt @@ -1,9 +1,9 @@ error 0) There must be at least one argument defined. -1) ARGUMENTS marker was found two times in code. -2) JAVASCRIPT marker was found two times in code. -3) ARGUMENTS marker was found two times in code. -4) JAVASCRIPT marker was found two times in code. -5) ARGUMENTS marker was found two times in code. -6) JAVASCRIPT marker was found two times in code. +1) ARGUMENTS marker was found two times in the code. +2) JAVASCRIPT marker was found two times in the code. +3) ARGUMENTS marker was found two times in the code. +4) JAVASCRIPT marker was found two times in the code. +5) ARGUMENTS marker was found two times in the code. +6) JAVASCRIPT marker was found two times in the code. From 594c035e50fd5cac3700c986dcf9634d072f0cb8 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 28 Aug 2018 17:36:42 +0300 Subject: [PATCH 21/27] Fixing small error in doc --- src/SeleniumLibrary/keywords/javascript.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index 98a432c88..3d2e59992 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -82,6 +82,7 @@ def execute_async_javascript(self, *code): arguments] as part of ``code`` argument. See `Execute Javascript` for more details. + Examples: | `Execute Async JavaScript` | var callback = arguments[arguments.length - 1]; window.setTimeout(callback, 2000); | | `Execute Async JavaScript` | ${CURDIR}/async_js_to_execute.js | | ${result} = | `Execute Async JavaScript` | From 945a67f7f212fc5a0d73b7ff7dde50427f7963d0 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 28 Aug 2018 21:20:24 +0300 Subject: [PATCH 22/27] Added missing file from acceptance tests --- atest/acceptance/keywords/javascript_alert.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 atest/acceptance/keywords/javascript_alert.js diff --git a/atest/acceptance/keywords/javascript_alert.js b/atest/acceptance/keywords/javascript_alert.js new file mode 100644 index 000000000..8de98bdd7 --- /dev/null +++ b/atest/acceptance/keywords/javascript_alert.js @@ -0,0 +1 @@ +alert(arguments[0]); \ No newline at end of file From 29f33a68a59005be1fb58d2b49ba7c6db507d424 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Sun, 2 Sep 2018 01:47:23 +0300 Subject: [PATCH 23/27] Refactored _separate_code_and_args method --- src/SeleniumLibrary/keywords/javascript.py | 66 ++++++++++++------- ...Test.test_check_marker_error.approved.txt} | 13 ++++ ...iptKeywordsTest.test_indexing.approved.txt | 15 +++++ ...t.test_separate_code_and_args.approved.txt | 21 +++--- utest/test/keywords/test_javascript.py | 46 ++++++++----- 5 files changed, 112 insertions(+), 49 deletions(-) rename utest/test/keywords/approved_files/{JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt => JavaScriptKeywordsTest.test_check_marker_error.approved.txt} (70%) create mode 100644 utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_indexing.approved.txt diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index 3d2e59992..68def5607 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -15,12 +15,16 @@ # limitations under the License. import os +from collections import namedtuple from SeleniumLibrary.base import LibraryComponent, keyword class JavaScriptKeywords(LibraryComponent): + js_marker = 'JAVASCRIPT' + arg_marker = 'ARGUMENTS' + @keyword def execute_javascript(self, *code): """Executes the given JavaScript code with possible arguments. @@ -107,33 +111,45 @@ def _get_javascript_to_execute(self, code): return js_code, js_args def _separate_code_and_args(self, code): + code = list(code) + self._check_marker_error(code) + index = self._get_marker_index(code) + if self.arg_marker not in code: + return code[index.js + 1:], [] + if self.js_marker not in code: + return code[0:index.arg], code[index.arg + 1:] + else: + if index.js == 0: + return code[index.js + 1:index.arg], code[index.arg + 1:] + else: + return code[index.js + 1:], code[index.arg + 1:index.js] + + def _check_marker_error(self, code): if not code: raise ValueError('There must be at least one argument defined.') - js_code, js_args = [], [] - get_code, get_args = False, False - found_code, found_args = False, False - for line in code: - if line == 'JAVASCRIPT' and found_code: - message = 'JAVASCRIPT marker was found two times in the code.' - raise ValueError(message) - if line == 'JAVASCRIPT' and not found_code: - get_code, found_code = True, True - get_args = False - continue - if line == 'ARGUMENTS' and found_args: - message = 'ARGUMENTS marker was found two times in the code.' - raise ValueError(message) - if line == 'ARGUMENTS' and not found_args: - get_code = False - get_args, found_args = True, True - continue - if not get_code and not get_args: - get_code, found_code = True, True - if get_code: - js_code.append(line) - if get_args: - js_args.append(line) - return js_code, js_args + message = None + template = '%s marker was found two times in the code.' + if code.count(self.js_marker) > 1: + message = template % self.js_marker + if code.count(self.arg_marker) > 1: + message = template % self.arg_marker + index = self._get_marker_index(code) + if index.js > 0 and index.arg != 0: + message = template % self.js_marker + if message: + raise ValueError(message) + + def _get_marker_index(self, code): + Index = namedtuple('Index', 'js arg') + if self.js_marker in code: + js = code.index(self.js_marker) + else: + js = -1 + if self.arg_marker in code: + arg = code.index(self.arg_marker) + else: + arg = -1 + return Index(js=js, arg=arg) def _read_javascript_from_file(self, path): self.info('Reading JavaScript from file %s.' diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_check_marker_error.approved.txt similarity index 70% rename from utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt rename to utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_check_marker_error.approved.txt index a873de4c6..14a34025c 100644 --- a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args_errors.approved.txt +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_check_marker_error.approved.txt @@ -7,3 +7,16 @@ error 4) JAVASCRIPT marker was found two times in the code. 5) ARGUMENTS marker was found two times in the code. 6) JAVASCRIPT marker was found two times in the code. +7) There must be at least one argument defined. +8) None +9) None +10) None +11) None +12) None +13) None +14) None +15) None +16) None +17) None +18) None +19) None diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_indexing.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_indexing.approved.txt new file mode 100644 index 000000000..288dc562b --- /dev/null +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_indexing.approved.txt @@ -0,0 +1,15 @@ +index + +0) Index(js=-1, arg=-1) +1) Index(js=-1, arg=-1) +2) Index(js=-1, arg=-1) +3) Index(js=0, arg=-1) +4) Index(js=-1, arg=2) +5) Index(js=-1, arg=-1) +6) Index(js=-1, arg=-1) +7) Index(js=0, arg=3) +8) Index(js=0, arg=-1) +9) Index(js=1, arg=0) +10) Index(js=0, arg=3) +11) Index(js=3, arg=0) +12) Index(js=-1, arg=-1) diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args.approved.txt index 76d990ed4..9c40a61a0 100644 --- a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args.approved.txt +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args.approved.txt @@ -1,12 +1,15 @@ code and args -0) (['code1'], []) -1) (['code1', 'code2'], []) +0) There must be at least one argument defined. +1) (['code1'], []) 2) (['code1', 'code2'], []) -3) (['javascript', 'code1', 'code2'], []) -4) (['code1', 'code2'], []) -5) (['code1', 'code2', 'argUMENTs'], []) -6) (['code1', 'code2'], []) -7) (['code1', 'code2'], ['arg1', 'arg2']) -8) (['code1', 'code2'], ['arg1', 'arg2']) -9) (['aRGUMENTS', 'arg1', 'arg2', 'jAVASCRIPT', 'code1', 'code2'], []) +3) (['code1', 'code2'], []) +4) (['code1', 'code2'], ['arg1', 'arg2']) +5) (['code1', 'code2', 'arguments', 'arg1', 'arg2'], []) +6) (['javascript', 'code1', 'code2'], []) +7) (['code1', 'code2'], []) +8) (['code1', 'code2', 'argUMENTs'], []) +9) (['code1', 'code2'], []) +10) (['code1', 'code2'], ['arg1', 'arg2']) +11) (['code1', 'code2'], ['arg1', 'arg2']) +12) (['aRGUMENTS', 'arg1', 'arg2', 'jAVASCRIPT', 'code1', 'code2'], []) diff --git a/utest/test/keywords/test_javascript.py b/utest/test/keywords/test_javascript.py index 9be5404d0..1ef98aa49 100644 --- a/utest/test/keywords/test_javascript.py +++ b/utest/test/keywords/test_javascript.py @@ -20,6 +20,18 @@ class JavaScriptKeywordsTest(unittest.TestCase): @classmethod @unittest.skipIf(JYTHON, 'ApprovalTest does not work with Jython') def setUpClass(cls): + cls.code_examples = [(), + ('code1',), ('code1', 'code2'), + ('JAVASCRIPT', 'code1', 'code2'), + ('code1', 'code2', 'ARGUMENTS', 'arg1', 'arg2'), + ('code1', 'code2', 'arguments', 'arg1', 'arg2'), + ('javascript', 'code1', 'code2'), + ('JAVASCRIPT', 'code1', 'code2', 'ARGUMENTS'), + ('JAVASCRIPT', 'code1', 'code2', 'argUMENTs'), + ('ARGUMENTS', 'JAVASCRIPT', 'code1', 'code2'), + ('JAVASCRIPT', 'code1', 'code2', 'ARGUMENTS', 'arg1', 'arg2'), + ('ARGUMENTS', 'arg1', 'arg2', 'JAVASCRIPT', 'code1', 'code2'), + ('aRGUMENTS', 'arg1', 'arg2', 'jAVASCRIPT', 'code1', 'code2')] cls.js = JavaScriptKeywords(None) path = os.path.dirname(__file__) reporter_json = os.path.abspath(os.path.join(path, '..', 'approvals_reporters.json')) @@ -45,23 +57,20 @@ def test_get_javascript_no_code(self): @unittest.skipIf(JYTHON, 'ApprovalTest does not work with Jython') def test_separate_code_and_args(self): all_results = [] - code_examples = [ - ('code1',), ('code1', 'code2'), - ('JAVASCRIPT', 'code1', 'code2'), - ('javascript', 'code1', 'code2'), - ('JAVASCRIPT', 'code1', 'code2', 'ARGUMENTS'), - ('JAVASCRIPT', 'code1', 'code2', 'argUMENTs'), - ('ARGUMENTS', 'JAVASCRIPT', 'code1', 'code2'), - ('JAVASCRIPT', 'code1', 'code2', 'ARGUMENTS', 'arg1', 'arg2'), - ('ARGUMENTS', 'arg1', 'arg2', 'JAVASCRIPT', 'code1', 'code2'), - ('aRGUMENTS', 'arg1', 'arg2', 'jAVASCRIPT', 'code1', 'code2'),] - for code in code_examples: + for code in self.code_examples: all_results.append(self.js_reporter(code)) verify_all('code and args', all_results, reporter=self.reporter) @unittest.skipIf(JYTHON, 'ApprovalTest does not work with Jython') - def test_separate_code_and_args_errors(self): - code_examples = [ + def test_indexing(self): + all_results = [] + for code in self.code_examples: + all_results.append(self.js._get_marker_index(code)) + verify_all('index', all_results, reporter=self.reporter) + + @unittest.skipIf(JYTHON, 'ApprovalTest does not work with Jython') + def test_check_marker_error(self): + examples = [ (), ('ARGUMENTS', 'arg1', 'ARGUMENTS', 'arg1', 'JAVASCRIPT', 'code1', 'JAVASCRIPT', 'code2'), @@ -71,11 +80,18 @@ def test_separate_code_and_args_errors(self): ('ARGUMENTS', 'arg1', 'ARGUMENTS', 'arg1', 'JAVASCRIPT', 'code1'), ('aRGUMENtS', 'arg1', 'arg2', 'JAVASCRIPT', 'code1', 'code2'), ] + examples = examples + self.code_examples all_results = [] - for code in code_examples: - all_results.append(self.js_reporter(code)) + for code in examples: + all_results.append(self.js_marker_error(code)) verify_all('error', all_results, reporter=self.reporter) + def js_marker_error(self, code): + try: + return self.js._check_marker_error(code) + except Exception as error: + return error + def js_reporter(self, code): try: return self.js._separate_code_and_args(code) From f990e01308bc8ae3b6d5b5435b35f898f9742bb5 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Sun, 2 Sep 2018 01:51:05 +0300 Subject: [PATCH 24/27] Added missing new line --- atest/acceptance/keywords/javascript_alert.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atest/acceptance/keywords/javascript_alert.js b/atest/acceptance/keywords/javascript_alert.js index 8de98bdd7..b42d042cd 100644 --- a/atest/acceptance/keywords/javascript_alert.js +++ b/atest/acceptance/keywords/javascript_alert.js @@ -1 +1 @@ -alert(arguments[0]); \ No newline at end of file +alert(arguments[0]); From e134565a2720bb4ca6f2f7955c413893ca863e7c Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Sun, 2 Sep 2018 02:15:49 +0300 Subject: [PATCH 25/27] Improved logging --- atest/acceptance/keywords/javascript.robot | 15 +++++++++------ src/SeleniumLibrary/keywords/javascript.py | 17 +++++++++++++---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/atest/acceptance/keywords/javascript.robot b/atest/acceptance/keywords/javascript.robot index ebb2fdcc2..03e71da46 100644 --- a/atest/acceptance/keywords/javascript.robot +++ b/atest/acceptance/keywords/javascript.robot @@ -23,8 +23,7 @@ Execute Javascript [Documentation] ... LOG 2 Executing JavaScript: ... window.add_content('button_target', 'Inserted directly') - ... By using argument(s): - ... "" + ... Without any arguments. Execute Javascript window.add_content('button_target', 'Inserted directly') Page Should Contain Inserted directly @@ -37,6 +36,11 @@ Execute Javascript With ARGUMENTS and JAVASCRIPT Marker Alert Should Be Present 123 timeout=10 s Execute Javascript With JAVASCRIPT and ARGUMENTS Marker + [Documentation] + ... LOG 2 Executing JavaScript: + ... alert(arguments[0]); + ... By using argument: + ... '123' Execute Javascript ... JAVASCRIPT ... alert(arguments[0]); @@ -48,8 +52,8 @@ Execute Javascript With ARGUMENTS Marker Only [Documentation] ... LOG 2 Executing JavaScript: ... alert(arguments[0]); - ... By using argument(s): - ... "123, 0987" + ... By using arguments: + ... '123' and '0987' Execute Javascript ... alert(arguments[0]); ... ARGUMENTS @@ -62,8 +66,7 @@ Execute Javascript from File ... LOG 2:1 REGEXP: Reading JavaScript from file .*executed_by_execute_javascript.* ... LOG 2:2 Executing JavaScript: ... window.add_content('button_target', 'Inserted via file') - ... By using argument(s): - ... "" + ... Without any arguments. Execute Javascript ${CURDIR}/executed_by_execute_javascript.js Page Should Contain Inserted via file diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index 68def5607..5ddc77919 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -17,6 +17,8 @@ import os from collections import namedtuple +from robot.utils import plural_or_not, seq2str + from SeleniumLibrary.base import LibraryComponent, keyword @@ -65,8 +67,7 @@ def execute_javascript(self, *code): | `Execute JavaScript` | ARGUMENTS | 123 | JAVASCRIPT | alert(arguments[0]); | """ js_code, js_args = self._get_javascript_to_execute(code) - self.info('Executing JavaScript:\n%s\nBy using argument(s):\n"%s"' - % (js_code, ', '.join(js_args))) + self._js_logger('JavaScript', js_code, js_args) return self.driver.execute_script(js_code, *js_args) @keyword @@ -96,10 +97,18 @@ def execute_async_javascript(self, *code): | `Should Be Equal` | ${result} | text | """ js_code, js_args = self._get_javascript_to_execute(code) - self.info('Executing Asynchronous JavaScript:\n%s\nBy using argument(s):\n"%s"' - % (js_code, ', '.join(js_args))) + self._js_logger('Execute Async JavaScript', js_code, js_args) return self.driver.execute_async_script(js_code, *js_args) + def _js_logger(self, kw, code, args): + message = 'Executing %s:\n%s\n' % (kw, code) + if args: + message = ('%sBy using argument%s:\n%s' + % (message, plural_or_not(args), seq2str(args))) + else: + message = '%sWithout any arguments.' % message + self.info(message) + def _get_javascript_to_execute(self, code): js_code, js_args = self._separate_code_and_args(code) if not js_code: From 4496cd78b75ae97d73f5680e48e40c77b83be0f3 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 4 Sep 2018 14:59:50 +0300 Subject: [PATCH 26/27] Improved logging. --- src/SeleniumLibrary/keywords/javascript.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index 5ddc77919..3ca2fdb86 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -67,7 +67,7 @@ def execute_javascript(self, *code): | `Execute JavaScript` | ARGUMENTS | 123 | JAVASCRIPT | alert(arguments[0]); | """ js_code, js_args = self._get_javascript_to_execute(code) - self._js_logger('JavaScript', js_code, js_args) + self._js_logger('Executing JavaScript', js_code, js_args) return self.driver.execute_script(js_code, *js_args) @keyword @@ -97,11 +97,11 @@ def execute_async_javascript(self, *code): | `Should Be Equal` | ${result} | text | """ js_code, js_args = self._get_javascript_to_execute(code) - self._js_logger('Execute Async JavaScript', js_code, js_args) + self._js_logger('Executing Asynchronous JavaScript', js_code, js_args) return self.driver.execute_async_script(js_code, *js_args) - def _js_logger(self, kw, code, args): - message = 'Executing %s:\n%s\n' % (kw, code) + def _js_logger(self, base, code, args): + message = '%s:\n%s\n' % (base, code) if args: message = ('%sBy using argument%s:\n%s' % (message, plural_or_not(args), seq2str(args))) From 6258baf52f20fcc707d8ed9e862efd5aed15b6da Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Sun, 9 Sep 2018 23:30:15 +0300 Subject: [PATCH 27/27] More unit tests --- ...avaScriptKeywordsTest.test_check_marker_error.approved.txt | 2 ++ .../JavaScriptKeywordsTest.test_indexing.approved.txt | 2 ++ ...criptKeywordsTest.test_separate_code_and_args.approved.txt | 2 ++ utest/test/keywords/test_javascript.py | 4 +++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_check_marker_error.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_check_marker_error.approved.txt index 14a34025c..b8a0d70fe 100644 --- a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_check_marker_error.approved.txt +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_check_marker_error.approved.txt @@ -20,3 +20,5 @@ error 17) None 18) None 19) None +20) None +21) None diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_indexing.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_indexing.approved.txt index 288dc562b..39d0c38c8 100644 --- a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_indexing.approved.txt +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_indexing.approved.txt @@ -13,3 +13,5 @@ index 10) Index(js=0, arg=3) 11) Index(js=3, arg=0) 12) Index(js=-1, arg=-1) +13) Index(js=-1, arg=-1) +14) Index(js=0, arg=-1) diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args.approved.txt index 9c40a61a0..59112862d 100644 --- a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args.approved.txt +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_separate_code_and_args.approved.txt @@ -13,3 +13,5 @@ code and args 10) (['code1', 'code2'], ['arg1', 'arg2']) 11) (['code1', 'code2'], ['arg1', 'arg2']) 12) (['aRGUMENTS', 'arg1', 'arg2', 'jAVASCRIPT', 'code1', 'code2'], []) +13) (['JAVASCRIPTCODE', 'code1', 'code2'], []) +14) (['code1', 'code2', 'ARGUMENTS ARG2', 'arg3'], []) diff --git a/utest/test/keywords/test_javascript.py b/utest/test/keywords/test_javascript.py index 1ef98aa49..c53d7b6d9 100644 --- a/utest/test/keywords/test_javascript.py +++ b/utest/test/keywords/test_javascript.py @@ -31,7 +31,9 @@ def setUpClass(cls): ('ARGUMENTS', 'JAVASCRIPT', 'code1', 'code2'), ('JAVASCRIPT', 'code1', 'code2', 'ARGUMENTS', 'arg1', 'arg2'), ('ARGUMENTS', 'arg1', 'arg2', 'JAVASCRIPT', 'code1', 'code2'), - ('aRGUMENTS', 'arg1', 'arg2', 'jAVASCRIPT', 'code1', 'code2')] + ('aRGUMENTS', 'arg1', 'arg2', 'jAVASCRIPT', 'code1', 'code2'), + ('JAVASCRIPTCODE', 'code1', 'code2'), + ('JAVASCRIPT', 'code1', 'code2', 'ARGUMENTS ARG2', 'arg3')] cls.js = JavaScriptKeywords(None) path = os.path.dirname(__file__) reporter_json = os.path.abspath(os.path.join(path, '..', 'approvals_reporters.json'))