Skip to content

Commit

Permalink
Merge pull request #1866 from robotframework/fixing_eval_js_type_hints
Browse files Browse the repository at this point in the history
fixed type hinting so that it is not converted to str
  • Loading branch information
emanlove authored Nov 18, 2023
2 parents 68edcfe + 1aa3d16 commit 3114312
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
8 changes: 8 additions & 0 deletions atest/acceptance/keywords/async_javascript.robot
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ Execute Async Javascript With ARGUMENTS and JAVASCRIPT Marker
... alert(arguments[0]);
Alert Should Be Present 123 timeout=10 s

Execute Javascript with dictionary object
&{ARGS}= Create Dictionary key=value number=${1} boolean=${TRUE}
${returned} Execute Async Javascript arguments[1](arguments[0]); ARGUMENTS ${ARGS}
Should Be True type($returned) == dict
Should Be Equal ${returned}[key] value
Should Be Equal ${returned}[number] ${1}
Should Be Equal ${returned}[boolean] ${TRUE}

Should Be Able To Return Javascript Primitives From Async Scripts Neither None Nor Undefined
${result} = Execute Async Javascript arguments[arguments.length - 1](123);
Should Be Equal ${result} ${123}
Expand Down
8 changes: 8 additions & 0 deletions atest/acceptance/keywords/javascript.robot
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ Execute Javascript from File With ARGUMENTS Marker
... 123
Alert Should Be Present 123 timeout=10 s

Execute Javascript with dictionary object
&{ARGS}= Create Dictionary key=value number=${1} boolean=${TRUE}
${returned} Execute JavaScript return arguments[0] ARGUMENTS ${ARGS}
Should Be True type($returned) == dict
Should Be Equal ${returned}[key] value
Should Be Equal ${returned}[number] ${1}
Should Be Equal ${returned}[boolean] ${TRUE}

Open Context Menu
[Tags] Known Issue Safari
Go To Page "javascript/context_menu.html"
Expand Down
4 changes: 2 additions & 2 deletions src/SeleniumLibrary/keywords/javascript.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class JavaScriptKeywords(LibraryComponent):
arg_marker = "ARGUMENTS"

@keyword
def execute_javascript(self, *code: Union[WebElement, str]) -> Any:
def execute_javascript(self, *code: Any) -> Any:
"""Executes the given JavaScript code with possible arguments.
``code`` may be divided into multiple cells in the test data and
Expand Down Expand Up @@ -73,7 +73,7 @@ def execute_javascript(self, *code: Union[WebElement, str]) -> Any:
return self.driver.execute_script(js_code, *js_args)

@keyword
def execute_async_javascript(self, *code: Union[WebElement, str]) -> Any:
def execute_async_javascript(self, *code: Any) -> Any:
"""Executes asynchronous JavaScript code with possible arguments.
Similar to `Execute Javascript` except that scripts executed with
Expand Down

0 comments on commit 3114312

Please sign in to comment.