From f9daed58130fb795281dda9d412f9a91c236e25e Mon Sep 17 00:00:00 2001 From: arnewohletz1 Date: Tue, 26 Jun 2018 20:51:07 +0200 Subject: [PATCH 01/39] Added execute_javascript_with_arguments keyword --- src/SeleniumLibrary/keywords/javascript.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index 27d4d24bf..dd9ab1be9 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -77,6 +77,13 @@ def execute_async_javascript(self, *code): self.info("Executing Asynchronous JavaScript:\n%s" % js) return self.driver.execute_async_script(js) + @keyword + def execute_javascript_with_arguments(self, code, *arguments): + js = self._get_javascript_to_execute(code) + self.info("Executing JavaScript \n%s with arguments \n%s" % ( + js, str(*arguments))) + return self.driver.execute_script(js, *arguments) + def _get_javascript_to_execute(self, lines): code = ''.join(lines) path = code.replace('/', os.sep) From aeb3dd5bbfd11ec93dbfa43953a57815470429e5 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 22 Jun 2018 13:07:29 +0300 Subject: [PATCH 02/39] Fix typo --- utest/test/locators/test_elementfinder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utest/test/locators/test_elementfinder.py b/utest/test/locators/test_elementfinder.py index f6bb5cc2c..82c3f1d55 100644 --- a/utest/test/locators/test_elementfinder.py +++ b/utest/test/locators/test_elementfinder.py @@ -199,7 +199,7 @@ def setUp(self): def tearDown(self): unstub() - def test_non_exisisting_prefix(self): + def test_non_existing_prefix(self): with self.assertRaises(ElementNotFound): self.finder.find("something=test1") with self.assertRaises(ElementNotFound): From 47b0317b170d60f0b30079d8ac3b174a1a30f3c6 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Sun, 1 Jul 2018 01:37:45 +0300 Subject: [PATCH 03/39] Remove Selenium 2.53.6 from Travis --- .travis.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index c322f6af0..c2b514e80 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,7 @@ matrix: - ROBOTFRAMEWORK=3.0.4 - ROBOT_OPTIONS=--dotted - INTERPRETER=pypy3 - - python: "3.6" + - python: "3.4" env: - BROWSER=headlesschrome - SELENIUM=3.12.0 @@ -51,7 +51,7 @@ matrix: - python: "2.7" env: - BROWSER=chrome - - SELENIUM=2.53.6 + - SELENIUM=3.12.0 - ROBOTFRAMEWORK=2.9.2 - ROBOT_OPTIONS=--dotted - INTERPRETER=python2 @@ -62,13 +62,6 @@ matrix: - ROBOTFRAMEWORK=2.8.7 - ROBOT_OPTIONS= - INTERPRETER=python2 - - python: "3.4" - env: - - BROWSER=chrome - - SELENIUM=2.53.6 - - ROBOTFRAMEWORK=3.0.4 - - ROBOT_OPTIONS=--dotted - - INTERPRETER=python3 before_script: - "export DISPLAY=:99.0" - "sh -e /etc/init.d/xvfb start" From 658528a1a282402394354f066dd6e0cfe810bdf0 Mon Sep 17 00:00:00 2001 From: arnewohletz1 Date: Sun, 1 Jul 2018 22:12:27 +0200 Subject: [PATCH 04/39] Added execute_asyncrhonous_javascript_with_arguments keyword --- src/SeleniumLibrary/keywords/javascript.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index dd9ab1be9..d01f7eb96 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -79,11 +79,26 @@ def execute_async_javascript(self, *code): @keyword def execute_javascript_with_arguments(self, code, *arguments): + """ Executes the JavaScript code with the given arguments + + """ js = self._get_javascript_to_execute(code) self.info("Executing JavaScript \n%s with arguments \n%s" % ( js, str(*arguments))) return self.driver.execute_script(js, *arguments) + @keyword + def execute_javascript_with_arguments(self, code, *arguments): + """ Executes asynchronous JavaScript code with the given arguments + + + """ + + js = self._get_javascript_to_execute(code) + self.info("Executing Asynchronous JavaScript \n%s with arguments \n%s" + % (js, str(*arguments))) + return self.driver.execute_async_script(js, *arguments) + def _get_javascript_to_execute(self, lines): code = ''.join(lines) path = code.replace('/', os.sep) From 2fe9d9caaef5aa58919732048b28eca2a8ea2de2 Mon Sep 17 00:00:00 2001 From: Arne Wohletz Date: Mon, 2 Jul 2018 13:24:33 +0200 Subject: [PATCH 05/39] added acceptance test execute_javascript_with_arguments keyword --- atest/acceptance/keywords/javascript.robot | 17 +++++++++++++++++ src/SeleniumLibrary/keywords/javascript.py | 10 ++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/atest/acceptance/keywords/javascript.robot b/atest/acceptance/keywords/javascript.robot index 3e248ecd1..0c0ad856a 100644 --- a/atest/acceptance/keywords/javascript.robot +++ b/atest/acceptance/keywords/javascript.robot @@ -2,6 +2,9 @@ Test Setup Go To Page "javascript/dynamic_content.html" Resource ../resource.robot +*** Variables *** +${TEXT}= You scrolled in div. + *** Test Cases *** Clicking Elements Should Activate Javascript Title Should Be Original @@ -52,3 +55,17 @@ Drag and Drop by Offset Element Text Should Be id=droppable Drop here Drag and Drop by Offset id=draggable ${100} ${20} Element Text Should Be id=droppable Dropped! + +Scroll to Element via Javascript + [Documentation] Scroll to element by executing javascript with target web + ... element as argument + [Tags] javascript_with_args + Go To Page "scroll/index.html" + ${initial_position}= Get Vertical Position css:#target + ${element}= Get WebElement css:#target + set test variable ${script} return arguments[0].scrollIntoView(); + Execute Javascript with arguments ${script} ${element} + ${position}= Get Vertical Position css:#target + Should Be True ${initial_position} > ${position} + Element Should Contain css:#result ${TEXT} + diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index d01f7eb96..e0a718a22 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -79,8 +79,8 @@ def execute_async_javascript(self, *code): @keyword def execute_javascript_with_arguments(self, code, *arguments): - """ Executes the JavaScript code with the given arguments - + """ Executes the given JavaScript code with the given arguments + #TODO: Add docstring """ js = self._get_javascript_to_execute(code) self.info("Executing JavaScript \n%s with arguments \n%s" % ( @@ -88,12 +88,10 @@ def execute_javascript_with_arguments(self, code, *arguments): return self.driver.execute_script(js, *arguments) @keyword - def execute_javascript_with_arguments(self, code, *arguments): + def execute_async_javascript_with_arguments(self, code, *arguments): """ Executes asynchronous JavaScript code with the given arguments - - + #TODO: Add docstring """ - js = self._get_javascript_to_execute(code) self.info("Executing Asynchronous JavaScript \n%s with arguments \n%s" % (js, str(*arguments))) From 7f62759e944b836e7bd7e62dd3d0e15e6a1f915b Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 22 Jun 2018 13:07:29 +0300 Subject: [PATCH 06/39] Fix typo --- utest/test/locators/test_elementfinder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utest/test/locators/test_elementfinder.py b/utest/test/locators/test_elementfinder.py index f6bb5cc2c..82c3f1d55 100644 --- a/utest/test/locators/test_elementfinder.py +++ b/utest/test/locators/test_elementfinder.py @@ -199,7 +199,7 @@ def setUp(self): def tearDown(self): unstub() - def test_non_exisisting_prefix(self): + def test_non_existing_prefix(self): with self.assertRaises(ElementNotFound): self.finder.find("something=test1") with self.assertRaises(ElementNotFound): From d4d24b3ebd9202055e6a0837262f4edabf9d3652 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Sun, 1 Jul 2018 01:37:45 +0300 Subject: [PATCH 07/39] Remove Selenium 2.53.6 from Travis --- .travis.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index c322f6af0..c2b514e80 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,7 @@ matrix: - ROBOTFRAMEWORK=3.0.4 - ROBOT_OPTIONS=--dotted - INTERPRETER=pypy3 - - python: "3.6" + - python: "3.4" env: - BROWSER=headlesschrome - SELENIUM=3.12.0 @@ -51,7 +51,7 @@ matrix: - python: "2.7" env: - BROWSER=chrome - - SELENIUM=2.53.6 + - SELENIUM=3.12.0 - ROBOTFRAMEWORK=2.9.2 - ROBOT_OPTIONS=--dotted - INTERPRETER=python2 @@ -62,13 +62,6 @@ matrix: - ROBOTFRAMEWORK=2.8.7 - ROBOT_OPTIONS= - INTERPRETER=python2 - - python: "3.4" - env: - - BROWSER=chrome - - SELENIUM=2.53.6 - - ROBOTFRAMEWORK=3.0.4 - - ROBOT_OPTIONS=--dotted - - INTERPRETER=python3 before_script: - "export DISPLAY=:99.0" - "sh -e /etc/init.d/xvfb start" From 84e1c3b43c9ebb3e8f2d102803f513968989e7a7 Mon Sep 17 00:00:00 2001 From: Arne Wohletz Date: Mon, 2 Jul 2018 14:46:35 +0200 Subject: [PATCH 08/39] try to resolve merge conflict in javascript.py --- src/SeleniumLibrary/keywords/javascript.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index e0a718a22..27d4d24bf 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -77,26 +77,6 @@ def execute_async_javascript(self, *code): self.info("Executing Asynchronous JavaScript:\n%s" % js) return self.driver.execute_async_script(js) - @keyword - def execute_javascript_with_arguments(self, code, *arguments): - """ Executes the given JavaScript code with the given arguments - #TODO: Add docstring - """ - js = self._get_javascript_to_execute(code) - self.info("Executing JavaScript \n%s with arguments \n%s" % ( - js, str(*arguments))) - return self.driver.execute_script(js, *arguments) - - @keyword - def execute_async_javascript_with_arguments(self, code, *arguments): - """ Executes asynchronous JavaScript code with the given arguments - #TODO: Add docstring - """ - js = self._get_javascript_to_execute(code) - self.info("Executing Asynchronous JavaScript \n%s with arguments \n%s" - % (js, str(*arguments))) - return self.driver.execute_async_script(js, *arguments) - def _get_javascript_to_execute(self, lines): code = ''.join(lines) path = code.replace('/', os.sep) From eb83fbed3503f1ab99080d8e50916b8215a843ae Mon Sep 17 00:00:00 2001 From: Arne Wohletz Date: Mon, 2 Jul 2018 15:08:00 +0200 Subject: [PATCH 09/39] added execute_async_javscript_with_arguments keyword --- src/SeleniumLibrary/keywords/javascript.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index 27d4d24bf..e0a718a22 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -77,6 +77,26 @@ def execute_async_javascript(self, *code): self.info("Executing Asynchronous JavaScript:\n%s" % js) return self.driver.execute_async_script(js) + @keyword + def execute_javascript_with_arguments(self, code, *arguments): + """ Executes the given JavaScript code with the given arguments + #TODO: Add docstring + """ + js = self._get_javascript_to_execute(code) + self.info("Executing JavaScript \n%s with arguments \n%s" % ( + js, str(*arguments))) + return self.driver.execute_script(js, *arguments) + + @keyword + def execute_async_javascript_with_arguments(self, code, *arguments): + """ Executes asynchronous JavaScript code with the given arguments + #TODO: Add docstring + """ + js = self._get_javascript_to_execute(code) + self.info("Executing Asynchronous JavaScript \n%s with arguments \n%s" + % (js, str(*arguments))) + return self.driver.execute_async_script(js, *arguments) + def _get_javascript_to_execute(self, lines): code = ''.join(lines) path = code.replace('/', os.sep) From b6c8f3b636855a9f21b64679d4582ca6a04a4fd4 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Wed, 4 Jul 2018 16:18:32 +0300 Subject: [PATCH 10/39] Update requirements.txt for minimum selenium version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index f9a28fdf8..ebb0d76f2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -selenium >= 2.53.6 +selenium >= 3.4.0 robotframework >= 2.8.7 From 58509b4e306fa80980aa5ff87d2070b2f659927f Mon Sep 17 00:00:00 2001 From: Arne Wohletz Date: Mon, 9 Jul 2018 16:46:49 +0200 Subject: [PATCH 11/39] added support for ARGUMENTS and JAVASCRIPT markers in execute_javascript_with_arguments keyword (will eventually be copied to execute_javascript keyword) added proper acceptance tests --- atest/acceptance/keywords/javascript.robot | 44 ++++++++++++++++++++++ src/SeleniumLibrary/keywords/javascript.py | 37 ++++++++++++++++-- 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/atest/acceptance/keywords/javascript.robot b/atest/acceptance/keywords/javascript.robot index 0c0ad856a..f5015aa76 100644 --- a/atest/acceptance/keywords/javascript.robot +++ b/atest/acceptance/keywords/javascript.robot @@ -69,3 +69,47 @@ Scroll to Element via Javascript Should Be True ${initial_position} > ${position} Element Should Contain css:#result ${TEXT} +# test multiline +Execute JavaScript test +# [Tags] test_only + Go To Page "scroll/index.html" + ${useless_variable}= Set Variable 123 + Execute Javascript with arguments + ... ARGUMENTS + ... ${useless_variable} + ... JAVASCRIPT + ... alert('Hello, world!'); + ... alert('This is me!'); + ... alert(arguments[0]); + +# python atest/run.py firefox --suite javascript --include test_only +Show WebElement type + [Tags] test_only + Go To Page "tables/tables.html" + ${element}= get WebElement xpath://*[@id="mergedRows"] + ${useless_variable}= Set Variable 123 + Execute Javascript with arguments + ... ARGUMENTS + ... ${element} + ... ${useless_variable} + ... JAVASCRIPT +# ... alert(typeof arguments[0]); +# ... element = document.evaluate("//*[@id='mergedRows']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; +# ... alert(typeof element); + ... return arguments[0].scrollIntoView(); +# ... element = arguments[0] +# ... element.scrollIntoView(); + +Highlight background +# [Tags] test_only + Go to Page "tables/tables.html" + ${element}= get WebElement xpath://*[@id="mixed-th-td"] + Execute Javascript with arguments + ... ARGUMENTS + ... ${element} + ... JAVASCRIPT + ... element_outside = arguments[0]; + ... element_inside = document.getElementById('mergedCols'); + ... console.log(typeof element_outside); + ... console.log(typeof element_inside); + ... return element_outside.scrollIntoView(behavior="auto"); diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index e0a718a22..9e0d1d79c 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -78,14 +78,22 @@ def execute_async_javascript(self, *code): return self.driver.execute_async_script(js) @keyword - def execute_javascript_with_arguments(self, code, *arguments): + def execute_javascript_with_arguments(self, *code): """ Executes the given JavaScript code with the given arguments #TODO: Add docstring """ + + code, args = self._parse_javascript_and_arguments(code) js = self._get_javascript_to_execute(code) - self.info("Executing JavaScript \n%s with arguments \n%s" % ( - js, str(*arguments))) - return self.driver.execute_script(js, *arguments) + + if len(args) == 0: + self.info("Executing JavaScript \n%s" % ( + js)) + return self.driver.execute_script(js) + else: + self.info("Executing JavaScript \n%s\nwith arguments \n%s" % ( + code, args)) + return self.driver.execute_script(code, args) @keyword def execute_async_javascript_with_arguments(self, code, *arguments): @@ -104,8 +112,29 @@ def _get_javascript_to_execute(self, lines): code = self._read_javascript_from_file(path) return code + def _parse_javascript_and_arguments(self, code): + is_arg = False + is_code = True + self.codelines = '' + self.args = [] + + for exp in code: + if str(exp).strip() == "JAVASCRIPT": + is_code = True + is_arg = False + elif str(exp).strip() == "ARGUMENTS": + is_arg = True + is_code = False + elif is_code: + self.codelines = self.codelines.__add__(exp + '\n') + elif is_arg: + self.args.append(exp) + + return self.codelines, self.args + def _read_javascript_from_file(self, path): self.info('Reading JavaScript from file %s.' .format(path.replace(os.sep, '/'), path), html=True) with open(path) as file: return file.read().strip() + From 5d26fd5a6530f8746863abc2503332365aa7853e Mon Sep 17 00:00:00 2001 From: Arne Wohletz Date: Wed, 11 Jul 2018 15:42:53 +0200 Subject: [PATCH 12/39] FIX: javascript files can now be read with 'execute (async) javascript with arguments' keyword ADD: a few more atests for above keyword --- atest/acceptance/keywords/javascript.robot | 100 +++++++++++---------- src/SeleniumLibrary/keywords/javascript.py | 58 ++++++++---- 2 files changed, 97 insertions(+), 61 deletions(-) diff --git a/atest/acceptance/keywords/javascript.robot b/atest/acceptance/keywords/javascript.robot index f5015aa76..fbfc29194 100644 --- a/atest/acceptance/keywords/javascript.robot +++ b/atest/acceptance/keywords/javascript.robot @@ -25,14 +25,14 @@ Mouse Down On Link Execute Javascript [Documentation] LOG 2 Executing JavaScript: ... window.add_content('button_target', 'Inserted directly') - Execute Javascript window.add_content('button_target', 'Inserted directly') + Execute Javascript with arguments window.add_content('button_target', 'Inserted directly') Page Should Contain Inserted directly 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') - Execute Javascript ${CURDIR}/executed_by_execute_javascript.js + Execute Javascript with arguments ${CURDIR}/executed_by_execute_javascript.js Page Should Contain Inserted via file Open Context Menu @@ -56,60 +56,70 @@ Drag and Drop by Offset Drag and Drop by Offset id=draggable ${100} ${20} Element Text Should Be id=droppable Dropped! -Scroll to Element via Javascript +Execute single line JavaScript with arguments [Documentation] Scroll to element by executing javascript with target web ... element as argument - [Tags] javascript_with_args - Go To Page "scroll/index.html" + [Setup] Go To Page "scroll/index.html" ${initial_position}= Get Vertical Position css:#target ${element}= Get WebElement css:#target + ${unused}= Set Variable ununsed set test variable ${script} return arguments[0].scrollIntoView(); - Execute Javascript with arguments ${script} ${element} + Execute Javascript with arguments ARGUMENTS ${element} ${unused} JAVASCRIPT ${script} ${position}= Get Vertical Position css:#target Should Be True ${initial_position} > ${position} Element Should Contain css:#result ${TEXT} -# test multiline -Execute JavaScript test -# [Tags] test_only - Go To Page "scroll/index.html" - ${useless_variable}= Set Variable 123 +Execute multiline JavaScript with arguments first + ${integer_variable}= Set Variable 123 Execute Javascript with arguments - ... ARGUMENTS - ... ${useless_variable} - ... JAVASCRIPT - ... alert('Hello, world!'); - ... alert('This is me!'); - ... alert(arguments[0]); + ... ARGUMENTS + ... ${integer_variable} + ... JAVASCRIPT + ... console.log('Hello, world!'); + ... console.log(arguments[0]); -# python atest/run.py firefox --suite javascript --include test_only -Show WebElement type - [Tags] test_only - Go To Page "tables/tables.html" - ${element}= get WebElement xpath://*[@id="mergedRows"] - ${useless_variable}= Set Variable 123 +Execute multiline JavaScript with arguments last + ${integer_variable}= Set Variable 123 Execute Javascript with arguments - ... ARGUMENTS - ... ${element} - ... ${useless_variable} - ... JAVASCRIPT -# ... alert(typeof arguments[0]); -# ... element = document.evaluate("//*[@id='mergedRows']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; -# ... alert(typeof element); - ... return arguments[0].scrollIntoView(); -# ... element = arguments[0] -# ... element.scrollIntoView(); + ... JAVASCRIPT + ... console.log('Hello, world!'); + ... console.log(arguments[0]); + ... ARGUMENTS + ... ${integer_variable} -Highlight background -# [Tags] test_only - Go to Page "tables/tables.html" - ${element}= get WebElement xpath://*[@id="mixed-th-td"] +Execute multiline JavaScript with multiple arguments + [Setup] Go To Page "tables/tables.html" + ${number_variable}= Set Variable 123 + ${string_variable}= Set Variable string + ${boolean_variable}= Set Variable True + ${null_variable}= Set Variable Null + ${webelement_variable}= Get WebElement xpath://*[@id="mergedRows"] Execute Javascript with arguments - ... ARGUMENTS - ... ${element} - ... JAVASCRIPT - ... element_outside = arguments[0]; - ... element_inside = document.getElementById('mergedCols'); - ... console.log(typeof element_outside); - ... console.log(typeof element_inside); - ... return element_outside.scrollIntoView(behavior="auto"); + ... JAVASCRIPT + ... if (arguments[2]) { + ... console.log(arguments[3]); + ... } else { + ... console.log('This should not happen'); + ... } + ... console.log(arguments[0]); + ... return arguments[4].scrollIntoView(); + ... console.log(arguments[1].localname); + ... ARGUMENTS + ... ${number_variable} + ... ${string_variable} + ... ${boolean_variable} + ... ${null_variable} + ... ${webelement_variable} + +Execute multiline JavaScript + Execute Javascript with arguments + ... console.log('Hello, world!'); + ... console.log('Here I am.'); + ... console.log('Who else is here?'); + +Execute multiline JavaScript with marker + Execute Javascript with arguments + ... JAVASCRIPT + ... console.log('Hello, world!'); + ... console.log('Here I am.'); + ... console.log('Who else is here?'); diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index 9e0d1d79c..73ded164f 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -83,27 +83,52 @@ def execute_javascript_with_arguments(self, *code): #TODO: Add docstring """ - code, args = self._parse_javascript_and_arguments(code) - js = self._get_javascript_to_execute(code) - - if len(args) == 0: - self.info("Executing JavaScript \n%s" % ( - js)) + if len(code) == 1: + js = self._get_javascript_to_execute(code) + self.info("Executing JavaScript:\n%s" % js) return self.driver.execute_script(js) - else: - self.info("Executing JavaScript \n%s\nwith arguments \n%s" % ( - code, args)) - return self.driver.execute_script(code, args) + + elif len(code) > 1: + code, args = self._parse_javascript_and_arguments(code) + + if len(args) == 0: + self.info("Executing JavaScript: \n%s" % code) + return self.driver.execute_script(code) + else: + args_list = [] + for idx, item in enumerate(args): + args_list.append("arguments[" + str(idx) + "]: " + + str(item)) + self.info("Executing JavaScript: \n%s\nwith arguments \n%s" + % (code, "\n".join(args_list))) + return self.driver.execute_script(code, *args) @keyword - def execute_async_javascript_with_arguments(self, code, *arguments): - """ Executes asynchronous JavaScript code with the given arguments + def execute_async_javascript_with_arguments(self, *code): + """ Executes the given asynchronous JavaScript code with the given + arguments #TODO: Add docstring """ - js = self._get_javascript_to_execute(code) - self.info("Executing Asynchronous JavaScript \n%s with arguments \n%s" - % (js, str(*arguments))) - return self.driver.execute_async_script(js, *arguments) + + if len(code) == 1: + js = self._get_javascript_to_execute(code) + self.info("Executing Asynchronous JavaScript:\n%s" % js) + return self.driver.execute_async_script(js) + + elif len(code) > 1: + code, args = self._parse_javascript_and_arguments(code) + + if len(args) == 0: + self.info("Executing Asynchronous JavaScript: \n%s" % code) + return self.driver.execute_async_script(code) + else: + args_list = [] + for idx, item in enumerate(args): + args_list.append("arguments[" + str(idx) + "]: " + + str(item)) + self.info("Executing Asynchronous JavaScript: ""\n%s\n" + "with arguments \n%s" % (code, "\n".join(args_list))) + return self.driver.execute_async_script(code, *args) def _get_javascript_to_execute(self, lines): code = ''.join(lines) @@ -113,6 +138,7 @@ def _get_javascript_to_execute(self, lines): return code def _parse_javascript_and_arguments(self, code): + is_arg = False is_code = True self.codelines = '' From d954449bc51289d1263bd7b221d433a944177978 Mon Sep 17 00:00:00 2001 From: Arne Wohletz Date: Mon, 16 Jul 2018 14:54:01 +0200 Subject: [PATCH 13/39] Initial commit: added approvaltests for execute_javascript_with_arguments keyword added another acceptance test for same keyword --- atest/acceptance/keywords/javascript.robot | 20 +++++++ requirements-dev.txt | 1 + utest/test/approvals_reporters.json | 6 +++ utest/test/keywords/approvaltests_config.json | 3 ++ utest/test/keywords/test_javascript.py | 52 +++++++++++++++++++ 5 files changed, 82 insertions(+) create mode 100644 utest/test/approvals_reporters.json create mode 100644 utest/test/keywords/approvaltests_config.json create mode 100644 utest/test/keywords/test_javascript.py diff --git a/atest/acceptance/keywords/javascript.robot b/atest/acceptance/keywords/javascript.robot index fbfc29194..a038205a0 100644 --- a/atest/acceptance/keywords/javascript.robot +++ b/atest/acceptance/keywords/javascript.robot @@ -123,3 +123,23 @@ Execute multiline JavaScript with marker ... console.log('Hello, world!'); ... console.log('Here I am.'); ... console.log('Who else is here?'); + + +Execute multiline Javascript without marker with multiple arguments + [Setup] Go To Page "tables/tables.html" + [Tags] test_only + ${number_variable}= Set Variable 123 + ${string_variable}= Set Variable string + ${boolean_variable}= Set Variable True + ${null_variable}= Set Variable Null + ${webelement_variable}= Get WebElement xpath://*[@id="mergedRows"] + Execute Javascript with arguments + ... console.log('Hello, world!'); + ... console.log('Here I am.'); + ... console.log('Who else is here?'); + ... ARGUMENTS + ... ${number_variable} + ... ${string_variable} + ... ${boolean_variable} + ... ${null_variable} + ... ${webelement_variable} \ No newline at end of file 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. diff --git a/utest/test/approvals_reporters.json b/utest/test/approvals_reporters.json new file mode 100644 index 000000000..380d530e7 --- /dev/null +++ b/utest/test/approvals_reporters.json @@ -0,0 +1,6 @@ +[ + [ + "WinMerge", + "C:/Program Files (x86)/WinMerge/WinMergeU.exe" + ] +] \ No newline at end of file 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/test_javascript.py b/utest/test/keywords/test_javascript.py new file mode 100644 index 000000000..ca3f619fb --- /dev/null +++ b/utest/test/keywords/test_javascript.py @@ -0,0 +1,52 @@ +import os +import unittest + +from approvaltests.approvals import verify_all +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_with_args(self): + code, args = self.javascript._parse_javascript_and_arguments( + ['ARGUMENTS', 'argument1', 'argument2', 'JAVASCRIPT', + 'my.first.line.of.JS.code;', 'my.second.line.of.JS.code;']) + combined = code.split("\n") + args + verify_all("INPUT", combined) + + def test_get_javascript_with_args_first(self): + code, args = self.javascript._parse_javascript_and_arguments( + ['JAVASCRIPT', 'my.first.line.of.JS.code;', + 'my.second.line.of.JS.code', 'ARGUMENTS', 'argument1', + 'argument2']) + combined = code.split("\n") + args + verify_all("INPUT", combined) + + def test_get_javascript_no_markers(self): + code, args = self.javascript._parse_javascript_and_arguments( + ['my.first.line.of.JS.code;', 'my.second.line.of.JS.code;', + 'my.third.line.of.JS.code;']) + combined = code.split("\n") + args + verify_all("INPUT", combined) + + def test_get_javascript_no_code_marker(self): + code, args = self.javascript._parse_javascript_and_arguments( + ['my.first.line.of.JS.code;', 'my.second.line.of.JS.code;', + 'my.third.line.of.JS.code;', 'ARGUMENTS', 'argument1', + 'argument2', 'argument3']) + combined = code.split("\n") + args + verify_all("INPUT", combined) + From 4b3f52a5b985d8a48af76684acd70c1a436c7e52 Mon Sep 17 00:00:00 2001 From: Arne Wohletz Date: Mon, 16 Jul 2018 15:06:19 +0200 Subject: [PATCH 14/39] removed tag --- atest/acceptance/keywords/javascript.robot | 1 - 1 file changed, 1 deletion(-) diff --git a/atest/acceptance/keywords/javascript.robot b/atest/acceptance/keywords/javascript.robot index a038205a0..74ad2610c 100644 --- a/atest/acceptance/keywords/javascript.robot +++ b/atest/acceptance/keywords/javascript.robot @@ -127,7 +127,6 @@ Execute multiline JavaScript with marker Execute multiline Javascript without marker with multiple arguments [Setup] Go To Page "tables/tables.html" - [Tags] test_only ${number_variable}= Set Variable 123 ${string_variable}= Set Variable string ${boolean_variable}= Set Variable True From 987c60ac283ac96de76833fed3838b6c4e0706a7 Mon Sep 17 00:00:00 2001 From: Arne Wohletz Date: Mon, 16 Jul 2018 15:21:10 +0200 Subject: [PATCH 15/39] added approved files (approvaltests) --- ...sTest.test_get_javascript_no_code_marker.approved.txt | 9 +++++++++ ...t.test_get_javascript_no_code_marker.approved.txt.bak | 9 +++++++++ ...wordsTest.test_get_javascript_no_markers.approved.txt | 6 ++++++ ...sTest.test_get_javascript_no_markers.approved.txt.bak | 6 ++++++ ...ywordsTest.test_get_javascript_with_args.approved.txt | 7 +++++++ ...dsTest.test_get_javascript_with_args.approved.txt.bak | 7 +++++++ ...Test.test_get_javascript_with_args_first.approved.txt | 7 +++++++ ....test_get_javascript_with_args_first.approved.txt.bak | 0 8 files changed, 51 insertions(+) create mode 100644 utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code_marker.approved.txt create mode 100644 utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code_marker.approved.txt.bak create mode 100644 utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_markers.approved.txt create mode 100644 utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_markers.approved.txt.bak create mode 100644 utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args.approved.txt create mode 100644 utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args.approved.txt.bak create mode 100644 utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args_first.approved.txt create mode 100644 utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args_first.approved.txt.bak diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code_marker.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code_marker.approved.txt new file mode 100644 index 000000000..d2de9cb86 --- /dev/null +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code_marker.approved.txt @@ -0,0 +1,9 @@ +INPUT + +0) my.first.line.of.JS.code; +1) my.second.line.of.JS.code; +2) my.third.line.of.JS.code; +3) +4) argument1 +5) argument2 +6) argument3 diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code_marker.approved.txt.bak b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code_marker.approved.txt.bak new file mode 100644 index 000000000..592c3ddc5 --- /dev/null +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code_marker.approved.txt.bak @@ -0,0 +1,9 @@ +INPUT + +0) my.first.line.of.JS.code; +1) my.second.line.of.JS.code +2) my.third.line.of.JS.code; +3) +4) argument1 +5) argument2 +6) argument3 diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_markers.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_markers.approved.txt new file mode 100644 index 000000000..b6c51498d --- /dev/null +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_markers.approved.txt @@ -0,0 +1,6 @@ +INPUT + +7) my.first.line.of.JS.code; +8) my.second.line.of.JS.code; +9) my.third.line.of.JS.code; +10) diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_markers.approved.txt.bak b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_markers.approved.txt.bak new file mode 100644 index 000000000..70951f350 --- /dev/null +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_markers.approved.txt.bak @@ -0,0 +1,6 @@ +INPUT + +7) my.first.line.of.JS.code; +8) my.second.line.of.JS.code +9) my.third.line.of.JS.code; +10) diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args.approved.txt new file mode 100644 index 000000000..8cb5b83f1 --- /dev/null +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args.approved.txt @@ -0,0 +1,7 @@ +INPUT + +11) my.first.line.of.JS.code; +12) my.second.line.of.JS.code; +13) +14) argument1 +15) argument2 diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args.approved.txt.bak b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args.approved.txt.bak new file mode 100644 index 000000000..4a20f1ee9 --- /dev/null +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args.approved.txt.bak @@ -0,0 +1,7 @@ +INPUT + +11) my.first.line.of.JS.code; +12) my.second.line.of.JS.code +13) +14) argument1 +15) argument2 diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args_first.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args_first.approved.txt new file mode 100644 index 000000000..e7fd70edc --- /dev/null +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args_first.approved.txt @@ -0,0 +1,7 @@ +INPUT + +16) my.first.line.of.JS.code; +17) my.second.line.of.JS.code +18) +19) argument1 +20) argument2 diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args_first.approved.txt.bak b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args_first.approved.txt.bak new file mode 100644 index 000000000..e69de29bb From 477cad6246edadc37fbd965ce3f2a8b6d52316e3 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Thu, 9 Aug 2018 23:18:59 +0300 Subject: [PATCH 16/39] Create webdriver fix for Selenium 3.14.0 --- atest/acceptance/create_webdriver.robot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atest/acceptance/create_webdriver.robot b/atest/acceptance/create_webdriver.robot index 6b1ad8e3f..8877d573c 100644 --- a/atest/acceptance/create_webdriver.robot +++ b/atest/acceptance/create_webdriver.robot @@ -7,7 +7,7 @@ Library Collections Create Webdriver Creates Functioning WebDriver [Documentation] ... LOG 2:1 INFO REGEXP: Creating an instance of the \\w+ WebDriver. - ... LOG 2:4 DEBUG REGEXP: Created \\w+ WebDriver instance with session id (\\w|-)+. + ... LOG 2:6 DEBUG REGEXP: Created \\w+ WebDriver instance with session id (\\w|-)+. [Tags] Known Issue Internet Explorer Known Issue Safari [Setup] Set Driver Variables Create Webdriver ${DRIVER_NAME} kwargs=${KWARGS} From fb4802fe7d7f72592da451a7d10b2df9431c8be9 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Thu, 9 Aug 2018 23:35:10 +0300 Subject: [PATCH 17/39] Content assertion fix for Selenium 3.14.0 --- .../keywords/content_assertions.robot | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/atest/acceptance/keywords/content_assertions.robot b/atest/acceptance/keywords/content_assertions.robot index 7c4c31cc2..1da28e501 100644 --- a/atest/acceptance/keywords/content_assertions.robot +++ b/atest/acceptance/keywords/content_assertions.robot @@ -6,7 +6,7 @@ Resource ../resource.robot *** Test Cases *** Location Should Be - [Documentation] LOG 2:3 Current location is '${FRONT PAGE}'. + [Documentation] LOG 2:4 Current location is '${FRONT PAGE}'. Location Should Be ${FRONT PAGE} Location Should Be ${FRONT PAGE} message=taco Location Should Be ${FRONT PAGE} message=None @@ -22,7 +22,7 @@ Location Should Be Location Should Contain - [Documentation] LOG 2:3 Current location contains 'html'. + [Documentation] LOG 2:4 Current location contains 'html'. Location Should Contain html Location Should Contain html message=foobar Location Should Contain html message=None @@ -38,7 +38,7 @@ Location Should Contain Title Should Be - [Documentation] LOG 2:3 Page title is '(root)/index.html'. + [Documentation] LOG 2:4 Page title is '(root)/index.html'. Title Should Be (root)/index.html Run Keyword And Expect Error ... Title should have been 'not a title' but was '(root)/index.html'. @@ -49,8 +49,8 @@ Title Should Be Page Should Contain - [Documentation] LOG 2:5 Current page contains text 'needle'. - ... LOG 4.1:10 REGEXP: (?i) + [Documentation] LOG 2:7 Current page contains text 'needle'. + ... LOG 4.1:14 REGEXP: (?i) Page Should Contain needle Page Should Contain This is the haystack Run Keyword And Expect Error @@ -63,7 +63,7 @@ Page Should Contain with text having internal elements Page Should Contain Relative with text after Page Should Contain With Custom Log Level - [Documentation] LOG 2.1:10 DEBUG REGEXP: (?i) + [Documentation] LOG 2.1:14 DEBUG REGEXP: (?i) Run Keyword And Expect Error ... Page should have contained text 'non existing text' but did not. ... Page Should Contain non existing text DEBUG @@ -81,15 +81,15 @@ Page Should Contain With Frames Page Should Contain You're looking at right. Page Should Not Contain - [Documentation] LOG 2:8 Current page does not contain text 'non existing text'. - ... LOG 3.1:7 REGEXP: (?i) + [Documentation] LOG 2:11 Current page does not contain text 'non existing text'. + ... LOG 3.1:10 REGEXP: (?i) Page Should Not Contain non existing text Run Keyword And Expect Error ... Page should not have contained text 'needle'. ... Page Should Not Contain needle Page Should Not Contain With Custom Log Level - [Documentation] LOG 2.1:7 DEBUG REGEXP: (?i) + [Documentation] LOG 2.1:10 DEBUG REGEXP: (?i) Run Keyword And Expect Error ... Page should not have contained text 'needle'. ... Page Should Not Contain needle DEBUG @@ -199,7 +199,7 @@ Get Text ... Get Text missing_id Page Should Contain Checkbox - [Documentation] LOG 2:5 Current page contains checkbox 'can_send_email'. + [Documentation] LOG 2:7 Current page contains checkbox 'can_send_email'. [Setup] Go To Page "forms/prefilled_email_form.html" Page Should Contain Checkbox can_send_email Page Should Contain Checkbox xpath=//input[@type='checkbox' and @name='can_send_sms'] @@ -208,7 +208,7 @@ Page Should Contain Checkbox ... Page Should Contain Checkbox non-existing Page Should Not Contain Checkbox - [Documentation] LOG 2:5 Current page does not contain checkbox 'non-existing'. + [Documentation] LOG 2:7 Current page does not contain checkbox 'non-existing'. [Setup] Go To Page "forms/prefilled_email_form.html" Page Should Not Contain Checkbox non-existing Run Keyword And Expect Error @@ -298,7 +298,7 @@ Page Should Not Contain Text Field ... Page Should Not Contain Text Field website TextField Should Contain - [Documentation] LOG 2:7 Text field 'name' contains text ''. + [Documentation] LOG 2:10 Text field 'name' contains text ''. [Setup] Go To Page "forms/email_form.html" TextField Should contain name ${EMPTY} TextField Should contain website ${EMPTY} @@ -314,7 +314,7 @@ TextField Should Contain ... TextField Should contain website https://w3.org TextField Value Should Be - [Documentation] LOG 2:7 Content of text field 'name' is ''. + [Documentation] LOG 2:10 Content of text field 'name' is ''. [Setup] Go To Page "forms/email_form.html" textfield Value Should Be name ${EMPTY} Input Text name my name From 71fc90c461cfd789519bcd8baff53cddf9212926 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Thu, 9 Aug 2018 23:43:33 +0300 Subject: [PATCH 18/39] Fixing cookies for selenium 3.14.0 --- atest/acceptance/keywords/cookies.robot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atest/acceptance/keywords/cookies.robot b/atest/acceptance/keywords/cookies.robot index 1410c45fe..d2a821fc9 100644 --- a/atest/acceptance/keywords/cookies.robot +++ b/atest/acceptance/keywords/cookies.robot @@ -103,7 +103,7 @@ Test Get Cookie Object Value Test Get Cookie Keyword Logging [Documentation] - ... LOG 2:3 ${cookie} = name=another + ... LOG 2:4 ${cookie} = name=another ... value=value ... path=/ ... domain=localhost From 516b0f1ba2d1eb93fcefd0e5aa085d1b37210d82 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Thu, 9 Aug 2018 23:50:40 +0300 Subject: [PATCH 19/39] Fixing counting elements for selenium 3.14.0 --- atest/acceptance/keywords/counting_elements.robot | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/atest/acceptance/keywords/counting_elements.robot b/atest/acceptance/keywords/counting_elements.robot index 2baad41a6..7b8b31f89 100644 --- a/atest/acceptance/keywords/counting_elements.robot +++ b/atest/acceptance/keywords/counting_elements.robot @@ -75,12 +75,12 @@ Page Should Contain Element When Limit Is None Page Should Contain Element name: div_name limit=${None} Page Should Contain Element When Limit Is Number - [Documentation] LOG 2:3 INFO Current page contains 2 element(s). + [Documentation] LOG 2:4 INFO Current page contains 2 element(s). [Setup] Go To Page "links.html" Page Should Contain Element name: div_name limit=2 Page Should Contain Element Log Level Does Not Affect When Keyword Passes - [Documentation] LOG 2:3 INFO Current page contains 2 element(s). + [Documentation] LOG 2:4 INFO Current page contains 2 element(s). [Setup] Go To Page "links.html" Page Should Contain Element name: div_name loglevel=debug limit=2 @@ -101,8 +101,8 @@ Page Should Contain Element When Limit Is Not Number Page Should Contain Element When Error With Limit And Different Loglevels [Documentation] - ... LOG 2.1:5 INFO REGEXP: .*links\\.html.* - ... LOG 3.1:5 DEBUG REGEXP: .*links\\.html.* + ... LOG 2.1:7 INFO REGEXP: .*links\\.html.* + ... LOG 3.1:7 DEBUG REGEXP: .*links\\.html.* [Setup] Go To Page "links.html" Run Keyword And Ignore Error ... Page Should Contain Element name: div_name limit=99 From 01bdc0aa3b5154ca9f42cb1c0189aff3a41d6c4d Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Thu, 9 Aug 2018 23:55:35 +0300 Subject: [PATCH 20/39] Fixing screenshots for selenium 3.14.0 --- atest/acceptance/keywords/screenshots.robot | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/atest/acceptance/keywords/screenshots.robot b/atest/acceptance/keywords/screenshots.robot index 134290cc0..268c3d698 100644 --- a/atest/acceptance/keywords/screenshots.robot +++ b/atest/acceptance/keywords/screenshots.robot @@ -7,8 +7,8 @@ Force Tags Known Issue Internet Explorer *** Test Cases *** Capture page screenshot to default location [Documentation] - ... LOG 2:3 - ... LOG 8:3 + ... LOG 2:4 + ... LOG 8:4 [Setup] Remove Files ${OUTPUTDIR}/selenium-screenshot-*.png ${file} = Capture Page Screenshot ${count} = Count Files In Directory ${OUTPUTDIR} selenium-screenshot-*.png From 6d7a862d823bc199a6b0dd489e1aa4144758ee97 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 10 Aug 2018 00:00:02 +0300 Subject: [PATCH 21/39] Open and close fix for Selenium 3.14.0 --- atest/acceptance/open_and_close.robot | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/atest/acceptance/open_and_close.robot b/atest/acceptance/open_and_close.robot index d85b2e124..6a10a71a7 100644 --- a/atest/acceptance/open_and_close.robot +++ b/atest/acceptance/open_and_close.robot @@ -19,10 +19,10 @@ Close Browser Does Nothing When No Browser Is Opened Browser Open With Not Well-Formed URL Should Close [Documentation] Verify after incomplete 'Open Browser' browser closes - ... LOG 1.1:10 DEBUG STARTS: Opened browser with session id - ... LOG 1.1:10 DEBUG REGEXP: .*but failed to open url.* + ... LOG 1.1:15 DEBUG STARTS: Opened browser with session id + ... LOG 1.1:15 DEBUG REGEXP: .*but failed to open url.* ... LOG 2:2 DEBUG STARTS: DELETE - ... LOG 2:3 DEBUG STARTS: Finished Request + ... LOG 2:4 DEBUG STARTS: Finished Request Run Keyword And Expect Error * Open Browser bad.url.bad ${BROWSER} Close All Browsers @@ -58,7 +58,7 @@ Closing all browsers clears cache Run Keyword And Expect Error ... No browser with index or alias 'Browser 2' found. ... Switch Browser Browser 2 - + Get Session Id Open Browser ${ROOT}/forms/prefilled_email_form.html ${BROWSER} Browser 1 ... remote_url=${REMOTE_URL} desired_capabilities=${DESIRED_CAPABILITIES} From 9bcef571f8c15d65b346a7a00e27037abacb775c Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 10 Aug 2018 00:00:21 +0300 Subject: [PATCH 22/39] Update selenium to 3.14.0 in Travis --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index c2b514e80..a8c4e1eea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,21 +29,21 @@ matrix: - python: "3.6" env: - BROWSER=headlesschrome - - SELENIUM=3.12.0 + - SELENIUM=3.14.0 - ROBOTFRAMEWORK=3.0.4 - ROBOT_OPTIONS=--dotted - INTERPRETER=python3 - python: "pypy3.5" env: - BROWSER=chrome - - SELENIUM=3.12.0 + - SELENIUM=3.14.0 - ROBOTFRAMEWORK=3.0.4 - ROBOT_OPTIONS=--dotted - INTERPRETER=pypy3 - python: "3.4" env: - BROWSER=headlesschrome - - SELENIUM=3.12.0 + - SELENIUM=3.14.0 - ROBOTFRAMEWORK=3.0.4 - ROBOT_OPTIONS=--dotted - INTERPRETER=python3 @@ -51,14 +51,14 @@ matrix: - python: "2.7" env: - BROWSER=chrome - - SELENIUM=3.12.0 + - SELENIUM=3.14.0 - ROBOTFRAMEWORK=2.9.2 - ROBOT_OPTIONS=--dotted - INTERPRETER=python2 - python: "2.7" env: - BROWSER=chrome - - SELENIUM=3.12.0 + - SELENIUM=3.14.0 - ROBOTFRAMEWORK=2.8.7 - ROBOT_OPTIONS= - INTERPRETER=python2 From f431f5c03e380c88791fae3214de1aa5cfaa6cf4 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 10 Aug 2018 21:46:35 +0300 Subject: [PATCH 23/39] Add Python 3.4 to travis --- .travis.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a8c4e1eea..b30012ecc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,7 @@ matrix: - ROBOTFRAMEWORK=3.0.4 - ROBOT_OPTIONS=--dotted - INTERPRETER=pypy3 - - python: "3.4" + - python: "3.6" env: - BROWSER=headlesschrome - SELENIUM=3.14.0 @@ -48,6 +48,13 @@ matrix: - ROBOT_OPTIONS=--dotted - INTERPRETER=python3 - JYTHON=true + - python: "3.4" + env: + - BROWSER=headlesschrome + - SELENIUM=3.14.0 + - ROBOTFRAMEWORK=3.0.4 + - ROBOT_OPTIONS=--dotted + - INTERPRETER=python3 - python: "2.7" env: - BROWSER=chrome From ac3960801abe9a0a1f1a9a9140de318044fa2f0a Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 10 Aug 2018 22:25:21 +0300 Subject: [PATCH 24/39] Fixing .travis.yaml --- .travis.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index b30012ecc..994ac2721 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,13 +17,6 @@ before_install: - unzip chromedriver_linux64.zip - sudo chmod u+x chromedriver - sudo mv chromedriver /usr/bin/ - # Firefox latest - # - FDVERSION=`curl -s -L https://github.com/mozilla/geckodriver/releases/latest | grep -E href=\"\(.*\)geckodriver-v\(.*\)-linux64.tar.gz\"` - # - VFILE=`echo $FDVERSION | sed -E "s/^.*//" --` - # - wget --no-verbose $VFILE - # - tar xzf geckodriver*-linux64.tar.gz - # - sudo chmod u+x geckodriver - # - sudo mv geckodriver /usr/bin/ matrix: include: - python: "3.6" @@ -49,7 +42,7 @@ matrix: - INTERPRETER=python3 - JYTHON=true - python: "3.4" - env: + env: - BROWSER=headlesschrome - SELENIUM=3.14.0 - ROBOTFRAMEWORK=3.0.4 From 7ccc0212498877b421d92d2841df3de5c2d4b915 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 10 Aug 2018 22:32:49 +0300 Subject: [PATCH 25/39] Remove Firefox from .travis.yaml --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 994ac2721..b14a6b4a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ env: global: - JYTHON=false addons: - firefox: latest apt: sources: - google-chrome From 03a5c63107a01cc75b921c60a51c6a1ea6da164d Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Sat, 11 Aug 2018 00:37:31 +0300 Subject: [PATCH 26/39] Approvaltests (#1173) Adds ApprovalTests support the project. --- .travis.yml | 8 ++++- requirements-dev.txt | 1 + src/SeleniumLibrary/utils/platform.py | 4 +++ utest/README.rst | 20 +++++++++-- utest/test/approvals_reporters.json | 6 ++++ utest/test/keywords/approvaltests_config.json | 3 ++ ...wordsTest.test_get_javascript.approved.txt | 1 + utest/test/keywords/test_javascript.py | 33 +++++++++++++++++++ 8 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 src/SeleniumLibrary/utils/platform.py create mode 100644 utest/test/approvals_reporters.json 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/.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: diff --git a/requirements-dev.txt b/requirements-dev.txt index bddcaaa75..21f70296d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -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. 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/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/ 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 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..32bac4ed4 --- /dev/null +++ b/utest/test/keywords/test_javascript.py @@ -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) \ No newline at end of file From 1e9a8b325716be2249b41be45eed8b6f2f15ce05 Mon Sep 17 00:00:00 2001 From: arnewohletz1 Date: Tue, 26 Jun 2018 20:51:07 +0200 Subject: [PATCH 27/39] Added execute_javascript_with_arguments keyword --- src/SeleniumLibrary/keywords/javascript.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index 27d4d24bf..dd9ab1be9 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -77,6 +77,13 @@ def execute_async_javascript(self, *code): self.info("Executing Asynchronous JavaScript:\n%s" % js) return self.driver.execute_async_script(js) + @keyword + def execute_javascript_with_arguments(self, code, *arguments): + js = self._get_javascript_to_execute(code) + self.info("Executing JavaScript \n%s with arguments \n%s" % ( + js, str(*arguments))) + return self.driver.execute_script(js, *arguments) + def _get_javascript_to_execute(self, lines): code = ''.join(lines) path = code.replace('/', os.sep) From fdfa18b52abec3b0c94148d33e2750df86c28c08 Mon Sep 17 00:00:00 2001 From: arnewohletz1 Date: Sun, 1 Jul 2018 22:12:27 +0200 Subject: [PATCH 28/39] Added execute_asyncrhonous_javascript_with_arguments keyword --- src/SeleniumLibrary/keywords/javascript.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index dd9ab1be9..d01f7eb96 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -79,11 +79,26 @@ def execute_async_javascript(self, *code): @keyword def execute_javascript_with_arguments(self, code, *arguments): + """ Executes the JavaScript code with the given arguments + + """ js = self._get_javascript_to_execute(code) self.info("Executing JavaScript \n%s with arguments \n%s" % ( js, str(*arguments))) return self.driver.execute_script(js, *arguments) + @keyword + def execute_javascript_with_arguments(self, code, *arguments): + """ Executes asynchronous JavaScript code with the given arguments + + + """ + + js = self._get_javascript_to_execute(code) + self.info("Executing Asynchronous JavaScript \n%s with arguments \n%s" + % (js, str(*arguments))) + return self.driver.execute_async_script(js, *arguments) + def _get_javascript_to_execute(self, lines): code = ''.join(lines) path = code.replace('/', os.sep) From 56a3d843ece5ae434f7a35d54e7bbf4fc5bb5f18 Mon Sep 17 00:00:00 2001 From: Arne Wohletz Date: Mon, 2 Jul 2018 13:24:33 +0200 Subject: [PATCH 29/39] added acceptance test execute_javascript_with_arguments keyword --- atest/acceptance/keywords/javascript.robot | 17 +++++++++++++++++ src/SeleniumLibrary/keywords/javascript.py | 10 ++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/atest/acceptance/keywords/javascript.robot b/atest/acceptance/keywords/javascript.robot index 3e248ecd1..0c0ad856a 100644 --- a/atest/acceptance/keywords/javascript.robot +++ b/atest/acceptance/keywords/javascript.robot @@ -2,6 +2,9 @@ Test Setup Go To Page "javascript/dynamic_content.html" Resource ../resource.robot +*** Variables *** +${TEXT}= You scrolled in div. + *** Test Cases *** Clicking Elements Should Activate Javascript Title Should Be Original @@ -52,3 +55,17 @@ Drag and Drop by Offset Element Text Should Be id=droppable Drop here Drag and Drop by Offset id=draggable ${100} ${20} Element Text Should Be id=droppable Dropped! + +Scroll to Element via Javascript + [Documentation] Scroll to element by executing javascript with target web + ... element as argument + [Tags] javascript_with_args + Go To Page "scroll/index.html" + ${initial_position}= Get Vertical Position css:#target + ${element}= Get WebElement css:#target + set test variable ${script} return arguments[0].scrollIntoView(); + Execute Javascript with arguments ${script} ${element} + ${position}= Get Vertical Position css:#target + Should Be True ${initial_position} > ${position} + Element Should Contain css:#result ${TEXT} + diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index d01f7eb96..e0a718a22 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -79,8 +79,8 @@ def execute_async_javascript(self, *code): @keyword def execute_javascript_with_arguments(self, code, *arguments): - """ Executes the JavaScript code with the given arguments - + """ Executes the given JavaScript code with the given arguments + #TODO: Add docstring """ js = self._get_javascript_to_execute(code) self.info("Executing JavaScript \n%s with arguments \n%s" % ( @@ -88,12 +88,10 @@ def execute_javascript_with_arguments(self, code, *arguments): return self.driver.execute_script(js, *arguments) @keyword - def execute_javascript_with_arguments(self, code, *arguments): + def execute_async_javascript_with_arguments(self, code, *arguments): """ Executes asynchronous JavaScript code with the given arguments - - + #TODO: Add docstring """ - js = self._get_javascript_to_execute(code) self.info("Executing Asynchronous JavaScript \n%s with arguments \n%s" % (js, str(*arguments))) From a43b77354cf77ff5ad9904d60453d01f668e0cd6 Mon Sep 17 00:00:00 2001 From: Arne Wohletz Date: Mon, 2 Jul 2018 14:46:35 +0200 Subject: [PATCH 30/39] try to resolve merge conflict in javascript.py --- src/SeleniumLibrary/keywords/javascript.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index e0a718a22..27d4d24bf 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -77,26 +77,6 @@ def execute_async_javascript(self, *code): self.info("Executing Asynchronous JavaScript:\n%s" % js) return self.driver.execute_async_script(js) - @keyword - def execute_javascript_with_arguments(self, code, *arguments): - """ Executes the given JavaScript code with the given arguments - #TODO: Add docstring - """ - js = self._get_javascript_to_execute(code) - self.info("Executing JavaScript \n%s with arguments \n%s" % ( - js, str(*arguments))) - return self.driver.execute_script(js, *arguments) - - @keyword - def execute_async_javascript_with_arguments(self, code, *arguments): - """ Executes asynchronous JavaScript code with the given arguments - #TODO: Add docstring - """ - js = self._get_javascript_to_execute(code) - self.info("Executing Asynchronous JavaScript \n%s with arguments \n%s" - % (js, str(*arguments))) - return self.driver.execute_async_script(js, *arguments) - def _get_javascript_to_execute(self, lines): code = ''.join(lines) path = code.replace('/', os.sep) From 6377b07658b47834cd3e4834d268c73336a28977 Mon Sep 17 00:00:00 2001 From: Arne Wohletz Date: Mon, 2 Jul 2018 15:08:00 +0200 Subject: [PATCH 31/39] added execute_async_javscript_with_arguments keyword --- src/SeleniumLibrary/keywords/javascript.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index 27d4d24bf..e0a718a22 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -77,6 +77,26 @@ def execute_async_javascript(self, *code): self.info("Executing Asynchronous JavaScript:\n%s" % js) return self.driver.execute_async_script(js) + @keyword + def execute_javascript_with_arguments(self, code, *arguments): + """ Executes the given JavaScript code with the given arguments + #TODO: Add docstring + """ + js = self._get_javascript_to_execute(code) + self.info("Executing JavaScript \n%s with arguments \n%s" % ( + js, str(*arguments))) + return self.driver.execute_script(js, *arguments) + + @keyword + def execute_async_javascript_with_arguments(self, code, *arguments): + """ Executes asynchronous JavaScript code with the given arguments + #TODO: Add docstring + """ + js = self._get_javascript_to_execute(code) + self.info("Executing Asynchronous JavaScript \n%s with arguments \n%s" + % (js, str(*arguments))) + return self.driver.execute_async_script(js, *arguments) + def _get_javascript_to_execute(self, lines): code = ''.join(lines) path = code.replace('/', os.sep) From eb176ff07b248e213e00de971a5c075f7a4156fd Mon Sep 17 00:00:00 2001 From: Arne Wohletz Date: Mon, 9 Jul 2018 16:46:49 +0200 Subject: [PATCH 32/39] added support for ARGUMENTS and JAVASCRIPT markers in execute_javascript_with_arguments keyword (will eventually be copied to execute_javascript keyword) added proper acceptance tests --- atest/acceptance/keywords/javascript.robot | 44 ++++++++++++++++++++++ src/SeleniumLibrary/keywords/javascript.py | 37 ++++++++++++++++-- 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/atest/acceptance/keywords/javascript.robot b/atest/acceptance/keywords/javascript.robot index 0c0ad856a..f5015aa76 100644 --- a/atest/acceptance/keywords/javascript.robot +++ b/atest/acceptance/keywords/javascript.robot @@ -69,3 +69,47 @@ Scroll to Element via Javascript Should Be True ${initial_position} > ${position} Element Should Contain css:#result ${TEXT} +# test multiline +Execute JavaScript test +# [Tags] test_only + Go To Page "scroll/index.html" + ${useless_variable}= Set Variable 123 + Execute Javascript with arguments + ... ARGUMENTS + ... ${useless_variable} + ... JAVASCRIPT + ... alert('Hello, world!'); + ... alert('This is me!'); + ... alert(arguments[0]); + +# python atest/run.py firefox --suite javascript --include test_only +Show WebElement type + [Tags] test_only + Go To Page "tables/tables.html" + ${element}= get WebElement xpath://*[@id="mergedRows"] + ${useless_variable}= Set Variable 123 + Execute Javascript with arguments + ... ARGUMENTS + ... ${element} + ... ${useless_variable} + ... JAVASCRIPT +# ... alert(typeof arguments[0]); +# ... element = document.evaluate("//*[@id='mergedRows']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; +# ... alert(typeof element); + ... return arguments[0].scrollIntoView(); +# ... element = arguments[0] +# ... element.scrollIntoView(); + +Highlight background +# [Tags] test_only + Go to Page "tables/tables.html" + ${element}= get WebElement xpath://*[@id="mixed-th-td"] + Execute Javascript with arguments + ... ARGUMENTS + ... ${element} + ... JAVASCRIPT + ... element_outside = arguments[0]; + ... element_inside = document.getElementById('mergedCols'); + ... console.log(typeof element_outside); + ... console.log(typeof element_inside); + ... return element_outside.scrollIntoView(behavior="auto"); diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index e0a718a22..9e0d1d79c 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -78,14 +78,22 @@ def execute_async_javascript(self, *code): return self.driver.execute_async_script(js) @keyword - def execute_javascript_with_arguments(self, code, *arguments): + def execute_javascript_with_arguments(self, *code): """ Executes the given JavaScript code with the given arguments #TODO: Add docstring """ + + code, args = self._parse_javascript_and_arguments(code) js = self._get_javascript_to_execute(code) - self.info("Executing JavaScript \n%s with arguments \n%s" % ( - js, str(*arguments))) - return self.driver.execute_script(js, *arguments) + + if len(args) == 0: + self.info("Executing JavaScript \n%s" % ( + js)) + return self.driver.execute_script(js) + else: + self.info("Executing JavaScript \n%s\nwith arguments \n%s" % ( + code, args)) + return self.driver.execute_script(code, args) @keyword def execute_async_javascript_with_arguments(self, code, *arguments): @@ -104,8 +112,29 @@ def _get_javascript_to_execute(self, lines): code = self._read_javascript_from_file(path) return code + def _parse_javascript_and_arguments(self, code): + is_arg = False + is_code = True + self.codelines = '' + self.args = [] + + for exp in code: + if str(exp).strip() == "JAVASCRIPT": + is_code = True + is_arg = False + elif str(exp).strip() == "ARGUMENTS": + is_arg = True + is_code = False + elif is_code: + self.codelines = self.codelines.__add__(exp + '\n') + elif is_arg: + self.args.append(exp) + + return self.codelines, self.args + def _read_javascript_from_file(self, path): self.info('Reading JavaScript from file %s.' .format(path.replace(os.sep, '/'), path), html=True) with open(path) as file: return file.read().strip() + From 57720388bb0d66bd74e9bbde66dc76c6e2641a92 Mon Sep 17 00:00:00 2001 From: Arne Wohletz Date: Wed, 11 Jul 2018 15:42:53 +0200 Subject: [PATCH 33/39] FIX: javascript files can now be read with 'execute (async) javascript with arguments' keyword ADD: a few more atests for above keyword --- atest/acceptance/keywords/javascript.robot | 100 +++++++++++---------- src/SeleniumLibrary/keywords/javascript.py | 58 ++++++++---- 2 files changed, 97 insertions(+), 61 deletions(-) diff --git a/atest/acceptance/keywords/javascript.robot b/atest/acceptance/keywords/javascript.robot index f5015aa76..fbfc29194 100644 --- a/atest/acceptance/keywords/javascript.robot +++ b/atest/acceptance/keywords/javascript.robot @@ -25,14 +25,14 @@ Mouse Down On Link Execute Javascript [Documentation] LOG 2 Executing JavaScript: ... window.add_content('button_target', 'Inserted directly') - Execute Javascript window.add_content('button_target', 'Inserted directly') + Execute Javascript with arguments window.add_content('button_target', 'Inserted directly') Page Should Contain Inserted directly 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') - Execute Javascript ${CURDIR}/executed_by_execute_javascript.js + Execute Javascript with arguments ${CURDIR}/executed_by_execute_javascript.js Page Should Contain Inserted via file Open Context Menu @@ -56,60 +56,70 @@ Drag and Drop by Offset Drag and Drop by Offset id=draggable ${100} ${20} Element Text Should Be id=droppable Dropped! -Scroll to Element via Javascript +Execute single line JavaScript with arguments [Documentation] Scroll to element by executing javascript with target web ... element as argument - [Tags] javascript_with_args - Go To Page "scroll/index.html" + [Setup] Go To Page "scroll/index.html" ${initial_position}= Get Vertical Position css:#target ${element}= Get WebElement css:#target + ${unused}= Set Variable ununsed set test variable ${script} return arguments[0].scrollIntoView(); - Execute Javascript with arguments ${script} ${element} + Execute Javascript with arguments ARGUMENTS ${element} ${unused} JAVASCRIPT ${script} ${position}= Get Vertical Position css:#target Should Be True ${initial_position} > ${position} Element Should Contain css:#result ${TEXT} -# test multiline -Execute JavaScript test -# [Tags] test_only - Go To Page "scroll/index.html" - ${useless_variable}= Set Variable 123 +Execute multiline JavaScript with arguments first + ${integer_variable}= Set Variable 123 Execute Javascript with arguments - ... ARGUMENTS - ... ${useless_variable} - ... JAVASCRIPT - ... alert('Hello, world!'); - ... alert('This is me!'); - ... alert(arguments[0]); + ... ARGUMENTS + ... ${integer_variable} + ... JAVASCRIPT + ... console.log('Hello, world!'); + ... console.log(arguments[0]); -# python atest/run.py firefox --suite javascript --include test_only -Show WebElement type - [Tags] test_only - Go To Page "tables/tables.html" - ${element}= get WebElement xpath://*[@id="mergedRows"] - ${useless_variable}= Set Variable 123 +Execute multiline JavaScript with arguments last + ${integer_variable}= Set Variable 123 Execute Javascript with arguments - ... ARGUMENTS - ... ${element} - ... ${useless_variable} - ... JAVASCRIPT -# ... alert(typeof arguments[0]); -# ... element = document.evaluate("//*[@id='mergedRows']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; -# ... alert(typeof element); - ... return arguments[0].scrollIntoView(); -# ... element = arguments[0] -# ... element.scrollIntoView(); + ... JAVASCRIPT + ... console.log('Hello, world!'); + ... console.log(arguments[0]); + ... ARGUMENTS + ... ${integer_variable} -Highlight background -# [Tags] test_only - Go to Page "tables/tables.html" - ${element}= get WebElement xpath://*[@id="mixed-th-td"] +Execute multiline JavaScript with multiple arguments + [Setup] Go To Page "tables/tables.html" + ${number_variable}= Set Variable 123 + ${string_variable}= Set Variable string + ${boolean_variable}= Set Variable True + ${null_variable}= Set Variable Null + ${webelement_variable}= Get WebElement xpath://*[@id="mergedRows"] Execute Javascript with arguments - ... ARGUMENTS - ... ${element} - ... JAVASCRIPT - ... element_outside = arguments[0]; - ... element_inside = document.getElementById('mergedCols'); - ... console.log(typeof element_outside); - ... console.log(typeof element_inside); - ... return element_outside.scrollIntoView(behavior="auto"); + ... JAVASCRIPT + ... if (arguments[2]) { + ... console.log(arguments[3]); + ... } else { + ... console.log('This should not happen'); + ... } + ... console.log(arguments[0]); + ... return arguments[4].scrollIntoView(); + ... console.log(arguments[1].localname); + ... ARGUMENTS + ... ${number_variable} + ... ${string_variable} + ... ${boolean_variable} + ... ${null_variable} + ... ${webelement_variable} + +Execute multiline JavaScript + Execute Javascript with arguments + ... console.log('Hello, world!'); + ... console.log('Here I am.'); + ... console.log('Who else is here?'); + +Execute multiline JavaScript with marker + Execute Javascript with arguments + ... JAVASCRIPT + ... console.log('Hello, world!'); + ... console.log('Here I am.'); + ... console.log('Who else is here?'); diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index 9e0d1d79c..73ded164f 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -83,27 +83,52 @@ def execute_javascript_with_arguments(self, *code): #TODO: Add docstring """ - code, args = self._parse_javascript_and_arguments(code) - js = self._get_javascript_to_execute(code) - - if len(args) == 0: - self.info("Executing JavaScript \n%s" % ( - js)) + if len(code) == 1: + js = self._get_javascript_to_execute(code) + self.info("Executing JavaScript:\n%s" % js) return self.driver.execute_script(js) - else: - self.info("Executing JavaScript \n%s\nwith arguments \n%s" % ( - code, args)) - return self.driver.execute_script(code, args) + + elif len(code) > 1: + code, args = self._parse_javascript_and_arguments(code) + + if len(args) == 0: + self.info("Executing JavaScript: \n%s" % code) + return self.driver.execute_script(code) + else: + args_list = [] + for idx, item in enumerate(args): + args_list.append("arguments[" + str(idx) + "]: " + + str(item)) + self.info("Executing JavaScript: \n%s\nwith arguments \n%s" + % (code, "\n".join(args_list))) + return self.driver.execute_script(code, *args) @keyword - def execute_async_javascript_with_arguments(self, code, *arguments): - """ Executes asynchronous JavaScript code with the given arguments + def execute_async_javascript_with_arguments(self, *code): + """ Executes the given asynchronous JavaScript code with the given + arguments #TODO: Add docstring """ - js = self._get_javascript_to_execute(code) - self.info("Executing Asynchronous JavaScript \n%s with arguments \n%s" - % (js, str(*arguments))) - return self.driver.execute_async_script(js, *arguments) + + if len(code) == 1: + js = self._get_javascript_to_execute(code) + self.info("Executing Asynchronous JavaScript:\n%s" % js) + return self.driver.execute_async_script(js) + + elif len(code) > 1: + code, args = self._parse_javascript_and_arguments(code) + + if len(args) == 0: + self.info("Executing Asynchronous JavaScript: \n%s" % code) + return self.driver.execute_async_script(code) + else: + args_list = [] + for idx, item in enumerate(args): + args_list.append("arguments[" + str(idx) + "]: " + + str(item)) + self.info("Executing Asynchronous JavaScript: ""\n%s\n" + "with arguments \n%s" % (code, "\n".join(args_list))) + return self.driver.execute_async_script(code, *args) def _get_javascript_to_execute(self, lines): code = ''.join(lines) @@ -113,6 +138,7 @@ def _get_javascript_to_execute(self, lines): return code def _parse_javascript_and_arguments(self, code): + is_arg = False is_code = True self.codelines = '' From 4e4324656e415bdd142fc2574cc2b9ca86e579b4 Mon Sep 17 00:00:00 2001 From: Arne Wohletz Date: Mon, 16 Jul 2018 14:54:01 +0200 Subject: [PATCH 34/39] Initial commit: added approvaltests for execute_javascript_with_arguments keyword added another acceptance test for same keyword --- atest/acceptance/keywords/javascript.robot | 20 ++++++++++++++++++++ utest/test/approvals_reporters.json | 6 ------ 2 files changed, 20 insertions(+), 6 deletions(-) delete mode 100644 utest/test/approvals_reporters.json diff --git a/atest/acceptance/keywords/javascript.robot b/atest/acceptance/keywords/javascript.robot index fbfc29194..a038205a0 100644 --- a/atest/acceptance/keywords/javascript.robot +++ b/atest/acceptance/keywords/javascript.robot @@ -123,3 +123,23 @@ Execute multiline JavaScript with marker ... console.log('Hello, world!'); ... console.log('Here I am.'); ... console.log('Who else is here?'); + + +Execute multiline Javascript without marker with multiple arguments + [Setup] Go To Page "tables/tables.html" + [Tags] test_only + ${number_variable}= Set Variable 123 + ${string_variable}= Set Variable string + ${boolean_variable}= Set Variable True + ${null_variable}= Set Variable Null + ${webelement_variable}= Get WebElement xpath://*[@id="mergedRows"] + Execute Javascript with arguments + ... console.log('Hello, world!'); + ... console.log('Here I am.'); + ... console.log('Who else is here?'); + ... ARGUMENTS + ... ${number_variable} + ... ${string_variable} + ... ${boolean_variable} + ... ${null_variable} + ... ${webelement_variable} \ No newline at end of file diff --git a/utest/test/approvals_reporters.json b/utest/test/approvals_reporters.json deleted file mode 100644 index 3ac5beb63..000000000 --- a/utest/test/approvals_reporters.json +++ /dev/null @@ -1,6 +0,0 @@ -[ - [ - "Diffuse", - "/usr/bin/diffuse" - ] -] \ No newline at end of file From 88a7b978fcb79eafe605828280ef09c525ef9482 Mon Sep 17 00:00:00 2001 From: Arne Wohletz Date: Mon, 16 Jul 2018 15:06:19 +0200 Subject: [PATCH 35/39] removed tag --- atest/acceptance/keywords/javascript.robot | 1 - 1 file changed, 1 deletion(-) diff --git a/atest/acceptance/keywords/javascript.robot b/atest/acceptance/keywords/javascript.robot index a038205a0..74ad2610c 100644 --- a/atest/acceptance/keywords/javascript.robot +++ b/atest/acceptance/keywords/javascript.robot @@ -127,7 +127,6 @@ Execute multiline JavaScript with marker Execute multiline Javascript without marker with multiple arguments [Setup] Go To Page "tables/tables.html" - [Tags] test_only ${number_variable}= Set Variable 123 ${string_variable}= Set Variable string ${boolean_variable}= Set Variable True From 6372421671152a4c26ab945d35cfd5f4d4b6ee9e Mon Sep 17 00:00:00 2001 From: Arne Wohletz Date: Mon, 16 Jul 2018 15:21:10 +0200 Subject: [PATCH 36/39] added approved files (approvaltests) --- ...sTest.test_get_javascript_no_code_marker.approved.txt | 9 +++++++++ ...t.test_get_javascript_no_code_marker.approved.txt.bak | 9 +++++++++ ...wordsTest.test_get_javascript_no_markers.approved.txt | 6 ++++++ ...sTest.test_get_javascript_no_markers.approved.txt.bak | 6 ++++++ ...ywordsTest.test_get_javascript_with_args.approved.txt | 7 +++++++ ...dsTest.test_get_javascript_with_args.approved.txt.bak | 7 +++++++ ...Test.test_get_javascript_with_args_first.approved.txt | 7 +++++++ ....test_get_javascript_with_args_first.approved.txt.bak | 0 8 files changed, 51 insertions(+) create mode 100644 utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code_marker.approved.txt create mode 100644 utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code_marker.approved.txt.bak create mode 100644 utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_markers.approved.txt create mode 100644 utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_markers.approved.txt.bak create mode 100644 utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args.approved.txt create mode 100644 utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args.approved.txt.bak create mode 100644 utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args_first.approved.txt create mode 100644 utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args_first.approved.txt.bak diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code_marker.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code_marker.approved.txt new file mode 100644 index 000000000..d2de9cb86 --- /dev/null +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code_marker.approved.txt @@ -0,0 +1,9 @@ +INPUT + +0) my.first.line.of.JS.code; +1) my.second.line.of.JS.code; +2) my.third.line.of.JS.code; +3) +4) argument1 +5) argument2 +6) argument3 diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code_marker.approved.txt.bak b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code_marker.approved.txt.bak new file mode 100644 index 000000000..592c3ddc5 --- /dev/null +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_code_marker.approved.txt.bak @@ -0,0 +1,9 @@ +INPUT + +0) my.first.line.of.JS.code; +1) my.second.line.of.JS.code +2) my.third.line.of.JS.code; +3) +4) argument1 +5) argument2 +6) argument3 diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_markers.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_markers.approved.txt new file mode 100644 index 000000000..b6c51498d --- /dev/null +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_markers.approved.txt @@ -0,0 +1,6 @@ +INPUT + +7) my.first.line.of.JS.code; +8) my.second.line.of.JS.code; +9) my.third.line.of.JS.code; +10) diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_markers.approved.txt.bak b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_markers.approved.txt.bak new file mode 100644 index 000000000..70951f350 --- /dev/null +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_no_markers.approved.txt.bak @@ -0,0 +1,6 @@ +INPUT + +7) my.first.line.of.JS.code; +8) my.second.line.of.JS.code +9) my.third.line.of.JS.code; +10) diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args.approved.txt new file mode 100644 index 000000000..8cb5b83f1 --- /dev/null +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args.approved.txt @@ -0,0 +1,7 @@ +INPUT + +11) my.first.line.of.JS.code; +12) my.second.line.of.JS.code; +13) +14) argument1 +15) argument2 diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args.approved.txt.bak b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args.approved.txt.bak new file mode 100644 index 000000000..4a20f1ee9 --- /dev/null +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args.approved.txt.bak @@ -0,0 +1,7 @@ +INPUT + +11) my.first.line.of.JS.code; +12) my.second.line.of.JS.code +13) +14) argument1 +15) argument2 diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args_first.approved.txt b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args_first.approved.txt new file mode 100644 index 000000000..e7fd70edc --- /dev/null +++ b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args_first.approved.txt @@ -0,0 +1,7 @@ +INPUT + +16) my.first.line.of.JS.code; +17) my.second.line.of.JS.code +18) +19) argument1 +20) argument2 diff --git a/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args_first.approved.txt.bak b/utest/test/keywords/approved_files/JavaScriptKeywordsTest.test_get_javascript_with_args_first.approved.txt.bak new file mode 100644 index 000000000..e69de29bb From 2360df5f82c1f6f74b3314184e66d40f92314cc4 Mon Sep 17 00:00:00 2001 From: Arne Wohletz Date: Fri, 17 Aug 2018 12:26:40 +0200 Subject: [PATCH 37/39] Moved keyword logic into functions --- src/SeleniumLibrary/keywords/javascript.py | 88 ++++++++++------------ 1 file changed, 41 insertions(+), 47 deletions(-) diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index 73ded164f..6c2cb4c83 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -82,26 +82,8 @@ def execute_javascript_with_arguments(self, *code): """ Executes the given JavaScript code with the given arguments #TODO: Add docstring """ - - if len(code) == 1: - js = self._get_javascript_to_execute(code) - self.info("Executing JavaScript:\n%s" % js) - return self.driver.execute_script(js) - - elif len(code) > 1: - code, args = self._parse_javascript_and_arguments(code) - - if len(args) == 0: - self.info("Executing JavaScript: \n%s" % code) - return self.driver.execute_script(code) - else: - args_list = [] - for idx, item in enumerate(args): - args_list.append("arguments[" + str(idx) + "]: " + - str(item)) - self.info("Executing JavaScript: \n%s\nwith arguments \n%s" - % (code, "\n".join(args_list))) - return self.driver.execute_script(code, *args) + code, args = self._get_javascript_to_execute(code) + self._execute_javascript_code(code, *args) @keyword def execute_async_javascript_with_arguments(self, *code): @@ -109,36 +91,49 @@ def execute_async_javascript_with_arguments(self, *code): arguments #TODO: Add docstring """ - - if len(code) == 1: - js = self._get_javascript_to_execute(code) - self.info("Executing Asynchronous JavaScript:\n%s" % js) - return self.driver.execute_async_script(js) - - elif len(code) > 1: - code, args = self._parse_javascript_and_arguments(code) - - if len(args) == 0: - self.info("Executing Asynchronous JavaScript: \n%s" % code) - return self.driver.execute_async_script(code) - else: - args_list = [] - for idx, item in enumerate(args): - args_list.append("arguments[" + str(idx) + "]: " + - str(item)) - self.info("Executing Asynchronous JavaScript: ""\n%s\n" - "with arguments \n%s" % (code, "\n".join(args_list))) - return self.driver.execute_async_script(code, *args) + code, args = self._get_javascript_to_execute(code) + self._execute_async_javascript_code(code, args) + + def _prepare_argument_list(self, args): + self.args_list = [] + for idx, item in enumerate(args): + self.args_list.append("arguments[" + str(idx) + "]: " + + str(item)) + + def _execute_javascript_code(self, code, *args): + if len(args) > 0: + self._prepare_argument_list(args) + self.info("Executing JavaScript: ""\n%s\n" + "with arguments \n%s" % ( + code, "\n".join(self.args_list))) + else: + self.info("Executing JavaScript:\n%s" % code) + self.driver.execute_script(code, *args) + + def _execute_async_javascript_code(self, code, *args): + if len(args) > 0: + self._prepare_argument_list(*args) + self.info("Executing Async JavaScript: ""\n%s\n" + "with arguments \n%s" % ( + code, "\n".join(self.args_list))) + return self.driver.execute_script(code, *args) + + else: + self.info("Executing Async JavaScript: \n%s" % code) + return self.driver.execute_script(code) def _get_javascript_to_execute(self, lines): - code = ''.join(lines) - path = code.replace('/', os.sep) - if os.path.isabs(path) and os.path.isfile(path): - code = self._read_javascript_from_file(path) - return code + if all(isinstance(n, str) for n in lines): + code = ''.join(lines) + 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 _parse_javascript_and_arguments(self, code): + code, args = self._parse_javascript_and_arguments(lines) + return code, args + def _parse_javascript_and_arguments(self, code): is_arg = False is_code = True self.codelines = '' @@ -163,4 +158,3 @@ def _read_javascript_from_file(self, path): .format(path.replace(os.sep, '/'), path), html=True) with open(path) as file: return file.read().strip() - From bf7250ed0312062fd30d3f2b00a027da67008fc9 Mon Sep 17 00:00:00 2001 From: Arne Wohletz Date: Fri, 17 Aug 2018 13:14:02 +0200 Subject: [PATCH 38/39] Added WinMerge option to approvals_reporters.json --- utest/test/approvals_reporters.json | 10 ++++++++++ 1 file changed, 10 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..60ffbc71a --- /dev/null +++ b/utest/test/approvals_reporters.json @@ -0,0 +1,10 @@ +[ + [ + "WinMerge", + "C:/Program Files (x86)/WinMerge/WinMergeU.exe" + ], + [ + "Diffuse", + "/usr/bin/diffuse" + ] +] \ No newline at end of file From 6035d60c8fb674fd86a3aa1b5b8fff1ccc6ca170 Mon Sep 17 00:00:00 2001 From: Arne Wohletz Date: Fri, 17 Aug 2018 13:54:45 +0200 Subject: [PATCH 39/39] Fixed .travis.yml --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 28765736b..1339c36f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,7 +50,11 @@ matrix: - python: "2.7" env: - BROWSER=chrome +<<<<<<< HEAD - SELENIUM=3.14.0 +======= + - SELENIUM=3.12.0 +>>>>>>> origin/master - ROBOTFRAMEWORK=2.9.2 - ROBOT_OPTIONS=--dotted - INTERPRETER=python2