diff --git a/.travis.yml b/.travis.yml index c322f6af0..1339c36f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ env: global: - JYTHON=false addons: - firefox: latest apt: sources: - google-chrome @@ -17,58 +16,55 @@ 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" 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.6" + - python: "3.4" env: - BROWSER=headlesschrome - - SELENIUM=3.12.0 + - SELENIUM=3.14.0 - ROBOTFRAMEWORK=3.0.4 - 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 - - SELENIUM=2.53.6 +<<<<<<< HEAD + - SELENIUM=3.14.0 +======= + - SELENIUM=3.12.0 +>>>>>>> origin/master - 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 - - 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" @@ -82,7 +78,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/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} 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 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 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 diff --git a/atest/acceptance/keywords/javascript.robot b/atest/acceptance/keywords/javascript.robot index 3e248ecd1..74ad2610c 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 @@ -22,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 @@ -52,3 +55,90 @@ 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! + +Execute single line JavaScript with arguments + [Documentation] Scroll to element by executing javascript with target web + ... element as argument + [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 ARGUMENTS ${element} ${unused} JAVASCRIPT ${script} + ${position}= Get Vertical Position css:#target + Should Be True ${initial_position} > ${position} + Element Should Contain css:#result ${TEXT} + +Execute multiline JavaScript with arguments first + ${integer_variable}= Set Variable 123 + Execute Javascript with arguments + ... ARGUMENTS + ... ${integer_variable} + ... JAVASCRIPT + ... console.log('Hello, world!'); + ... console.log(arguments[0]); + +Execute multiline JavaScript with arguments last + ${integer_variable}= Set Variable 123 + Execute Javascript with arguments + ... JAVASCRIPT + ... console.log('Hello, world!'); + ... console.log(arguments[0]); + ... ARGUMENTS + ... ${integer_variable} + +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 + ... 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?'); + + +Execute multiline Javascript without marker 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 + ... 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/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 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} 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/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 diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index 27d4d24bf..47049a12d 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -77,15 +77,85 @@ 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): + """ Executes the given JavaScript code with the given arguments + #TODO: Add docstring + """ + code, args = self._get_javascript_to_execute(code) + self._execute_javascript_code(code, *args) + + @keyword + def execute_async_javascript_with_arguments(self, *code): + """ Executes the given asynchronous JavaScript code with the given + arguments + #TODO: Add docstring + """ + 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, [] + + 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 = '' + 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() + 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..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 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/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 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 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):