Skip to content

Commit bd5b2b7

Browse files
committed
fix JavaScript kw doc
1 parent 445a37d commit bd5b2b7

File tree

3 files changed

+26
-29
lines changed

3 files changed

+26
-29
lines changed

src/Selenium2Library/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ class Selenium2Library(
2828
Selenium2Library runs tests in a real browser instance. It should work in
2929
most modern browsers and can be used with both Python and Jython interpreters.
3030
31-
*Before running tests*
31+
= Before running tests =
3232
3333
Prior to running test cases using Selenium2Library, Selenium2Library must be
3434
imported into your Robot test suite (see `importing` section), and the
3535
`Open Browser` keyword must be used to open a browser to the desired location.
3636
37-
*Locating elements*
37+
= Locating elements =
3838
3939
All keywords in Selenium2Library that need to find an element on the page
4040
take an argument, `locator`. By default, when a locator value is provided,
@@ -72,12 +72,13 @@ class Selenium2Library(
7272
| css | Table Should Contain `|` css=table.my_class `|` text | Matches by @id or @name attribute |
7373
| xpath | Table Should Contain `|` xpath=//table/[@name="my_table"] `|` text | Matches by @id or @name attribute |
7474
75-
*Timeouts*
75+
= Timeouts =
7676
7777
There are several `Wait ...` keywords that take timeout as an
7878
argument. All of these timeout arguments are optional. The timeout
7979
used by all of them can be set globally using the
80-
`Set Selenium Timeout` keyword.
80+
`Set Selenium Timeout` keyword. The same timeout also applies to
81+
`Execute Async Javascript`.
8182
8283
All timeouts can be given as numbers considered seconds (e.g. 0.5 or 42)
8384
or in Robot Framework's time syntax (e.g. '1.5 seconds' or '1 min 30 s').

src/Selenium2Library/keywords/_browsermanagement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def set_selenium_timeout(self, seconds):
418418
There are several `Wait ...` keywords that take timeout as an
419419
argument. All of these timeout arguments are optional. The timeout
420420
used by all of them can be set globally using this keyword.
421-
See `introduction` for more information about timeouts.
421+
See `Timeouts` for more information about timeouts.
422422
423423
The previous timeout value is returned by this keyword and can
424424
be used to set the old value back later. The default timeout

src/Selenium2Library/keywords/_javascript.py

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,23 @@ def confirm_action(self):
6868
def execute_javascript(self, *code):
6969
"""Executes the given JavaScript code.
7070
71-
`code` may contain multiple lines of code but must contain a
72-
return statement (with the value to be returned) at the end.
73-
74-
`code` may be divided into multiple cells in the test data. In that
75-
case, the parts are catenated together without adding spaces.
71+
`code` may contain multiple lines of code and may be divided into
72+
multiple cells in the test data. In that case, the parts are
73+
catenated together without adding spaces.
7674
7775
If `code` is an absolute path to an existing file, the JavaScript
7876
to execute will be read from that file. Forward slashes work as
7977
a path separator on all operating systems.
8078
81-
Note that, by default, the code will be executed in the context of the
82-
Selenium object itself, so `this` will refer to the Selenium object.
83-
Use `window` to refer to the window of your application, e.g.
84-
`window.document.getElementById('foo')`.
79+
The JavaScript executes in the context of the currently selected
80+
frame or window. Use _window_ to refer to the window of your
81+
application and _document_ to refer to the document object
82+
of the current frame or window, e.g.
83+
_document.getElementById('foo')_.
84+
85+
This keyword returns None unless there is a return statement in the
86+
JavaScript. Return values are converted to the appropriate type in
87+
Python, including WebElements.
8588
8689
Example:
8790
| Execute JavaScript | window.my_js_function('arg1', 'arg2') |
@@ -94,24 +97,17 @@ def execute_javascript(self, *code):
9497
def execute_async_javascript(self, *code):
9598
"""Executes asynchronous JavaScript code.
9699
97-
`code` may contain multiple lines of code but must contain a
98-
return statement (with the value to be returned) at the end.
99-
100-
`code` may be divided into multiple cells in the test data. In that
101-
case, the parts are catenated together without adding spaces.
102-
103-
If `code` is an absolute path to an existing file, the JavaScript
104-
to execute will be read from that file. Forward slashes work as
105-
a path separator on all operating systems.
100+
Similar to `Execute Javascript` except that scripts executed with
101+
this keyword must explicitly signal they are finished by invoking the
102+
provided callback. This callback is always injected into the executed
103+
function as the last argument.
106104
107-
Note that, by default, the code will be executed in the context of the
108-
Selenium object itself, so `this` will refer to the Selenium object.
109-
Use `window` to refer to the window of your application, e.g.
110-
`window.document.getElementById('foo')`.
105+
Scripts must complete within the script timeout or this keyword will
106+
fail. See the `Timeouts` section for more information.
111107
112108
Example:
113-
| Execute Async JavaScript | window.my_js_function('arg1', 'arg2') |
114-
| Execute Async JavaScript | ${CURDIR}/js_to_execute.js |
109+
| Execute Async JavaScript | var callback = arguments[arguments.length - 1]; | window.setTimeout(callback, 2000); |
110+
| Execute Async JavaScript | ${CURDIR}/async_js_to_execute.js | |
115111
"""
116112
js = self._get_javascript_to_execute(''.join(code))
117113
self._info("Executing Asynchronous JavaScript:\n%s" % js)

0 commit comments

Comments
 (0)