Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #22 from emanlove/fix-s2l-timeout-bug

Fix s2l timeout bug
  • Loading branch information...
commit ae9846ed452fbc6426fd2a6c31f98e6aab5dbfa5 2 parents 4e08194 + de41df5
Ed Manlove authored February 15, 2012
2  src/Selenium2Library/keywords/_browsermanagement.py
@@ -339,6 +339,8 @@ def set_selenium_timeout(self, seconds):
339 339
         """
340 340
         old_timeout = self.get_selenium_timeout()
341 341
         self._timeout_in_secs = robot.utils.timestr_to_secs(seconds)
  342
+        for browser in self._cache.browsers:
  343
+            browser.set_script_timeout(self._timeout_in_secs)
342 344
         return old_timeout
343 345
 
344 346
     def set_selenium_implicit_wait(self, seconds):
26  src/Selenium2Library/keywords/_javascript.py
@@ -91,6 +91,32 @@ def execute_javascript(self, *code):
91 91
         self._info("Executing JavaScript:\n%s" % js)
92 92
         return self._current_browser().execute_script(js)
93 93
 
  94
+    def execute_async_javascript(self, *code):
  95
+        """Executes asynchronous JavaScript code.
  96
+
  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.
  106
+
  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')`.
  111
+
  112
+        Example:
  113
+        | Execute Async JavaScript | window.my_js_function('arg1', 'arg2') |
  114
+        | Execute Async JavaScript | ${CURDIR}/js_to_execute.js |
  115
+        """
  116
+        js = self._get_javascript_to_execute(''.join(code))
  117
+        self._info("Executing Asynchronous JavaScript:\n%s" % js)
  118
+        return self._current_browser().execute_async_script(js)
  119
+
94 120
     def get_alert_message(self):
95 121
         """Returns the text of current JavaScript alert.
96 122
 
86  test/acceptance/keywords/async_javascript.txt
... ...
@@ -0,0 +1,86 @@
  1
+*** Settings ***
  2
+Test Setup      Go To Page "javascript/dynamic_content.html"
  3
+Resource        ../resource.txt
  4
+
  5
+*** Test Cases ***
  6
+Should Not Timeout If Callback Invoked Immediately
  7
+    ${result} =  Execute Async Javascript  arguments[arguments.length - 1](123);
  8
+    Should Be Equal  ${result}  ${123}
  9
+
  10
+Should Be Able To Return Javascript Primitives From Async Scripts Neither None Nor Undefined
  11
+    ${result} =  Execute Async Javascript  arguments[arguments.length - 1](123);
  12
+    Should Be Equal  ${result}  ${123}
  13
+    ${result} =  Execute Async Javascript  arguments[arguments.length - 1]('abc');
  14
+    Should Be Equal  ${result}  abc
  15
+    ${result} =  Execute Async Javascript  arguments[arguments.length - 1](false);
  16
+    Should Be Equal  ${result}  ${false}
  17
+    ${result} =  Execute Async Javascript  arguments[arguments.length - 1](true);
  18
+    Should Be Equal  ${result}  ${true}
  19
+
  20
+Should Be Able To Return Javascript Primitives From Async Scripts Null And Undefined
  21
+    ${result} =  Execute Async Javascript  arguments[arguments.length - 1](null);
  22
+    Should Be Equal  ${result}  ${None}
  23
+    ${result} =  Execute Async Javascript  arguments[arguments.length - 1]();
  24
+    Should Be Equal  ${result}  ${None}
  25
+
  26
+Should Be Able To Return An Array Literal From An Async Script
  27
+    ${result} =  Execute Async Javascript  arguments[arguments.length - 1]([]);
  28
+    Should Not Be Equal  ${result}  ${None}
  29
+    Length Should Be  ${result}  0
  30
+
  31
+Should Be Able To Return An Array Object From An Async Script
  32
+    ${result} =  Execute Async Javascript  arguments[arguments.length - 1](new Array());
  33
+    Should Not Be Equal  ${result}  ${None}
  34
+    Length Should Be  ${result}  0
  35
+
  36
+Should Be Able To Return Arrays Of Primitives From Async Scripts
  37
+    ${result} =  Execute Async Javascript  arguments[arguments.length - 1]([null, 123, 'abc', true, false]);
  38
+    Should Not Be Equal  ${result}  ${None}
  39
+    Length Should Be  ${result}  5
  40
+    ${value} =  Remove From List  ${result}  -1
  41
+    Should Be Equal  ${value}  ${false}
  42
+    ${value} =  Remove From List  ${result}  -1
  43
+    Should Be Equal  ${value}  ${true}
  44
+    ${value} =  Remove From List  ${result}  -1
  45
+    Should Be Equal  ${value}  abc
  46
+    ${value} =  Remove From List  ${result}  -1
  47
+    Should Be Equal  ${value}  ${123}
  48
+    ${value} =  Remove From List  ${result}  -1
  49
+    Should Be Equal  ${value}  ${None}
  50
+    Length Should Be  ${result}  0
  51
+
  52
+Should Timeout If Script Does Not Invoke Callback
  53
+    Run Keyword And Expect Error  TimeoutException: Message: ''\ \
  54
+    ...  Execute Async Javascript  return 1 + 2;
  55
+
  56
+Should Timeout If Script Does Not Invoke Callback With A Zero Timeout
  57
+    Run Keyword And Expect Error  TimeoutException: Message: ''\ \
  58
+    ...  Execute Async Javascript  window.setTimeout(function() {}, 0);
  59
+
  60
+Should Not Timeout If Script Callsback Inside A Zero Timeout
  61
+    ${result} =  Execute Async Javascript
  62
+    ...  var callback = arguments[arguments.length - 1];
  63
+    ...  window.setTimeout(function() { callback(123); }, 0)
  64
+
  65
+Should Timeout If Script Does Not Invoke Callback With Long Timeout
  66
+    Set Selenium Timeout  0.5 seconds
  67
+    Run Keyword And Expect Error  TimeoutException: Message: ''\ \
  68
+    ...  Execute Async Javascript  var callback = arguments[arguments.length - 1]; window.setTimeout(callback, 1500);
  69
+
  70
+Should Detect Page Loads While Waiting On An Async Script And Return An Error
  71
+    Set Selenium Timeout  0.1 seconds
  72
+    Run Keyword And Expect Error  WebDriverException: Message: ''\ \
  73
+    ...  Execute Async Javascript  window.location = javascript/dynamic;
  74
+
  75
+Should Catch Errors When Executing Initial Script
  76
+    Run Keyword And Expect Error  WebDriverException: Message: ''\ \
  77
+    ...  Execute Async Javascript  throw Error('you should catch this!');
  78
+
  79
+#TODO Implement Selenium asynchronous javascript test
  80
+#Should Be Able To Execute Asynchronous Scripts
  81
+#    # To Do
  82
+
  83
+#TODO  EdManlove  Add support for arguement passing to selenium javascript calls
  84
+#Should Be Able To Pass Multiple Arguments To Async Scripts
  85
+#    ${result} =  Execute Async Javascript  arguments[arguments.length - 1](arguments[0] + arguments[1]);  1  2
  86
+#    Should Be Equal  ${result}  ${3}

0 notes on commit ae9846e

Please sign in to comment.
Something went wrong with that request. Please try again.