File tree Expand file tree Collapse file tree 2 files changed +15
-11
lines changed
javascript/firefox-driver/js
java/client/test/org/openqa/selenium Expand file tree Collapse file tree 2 files changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -241,10 +241,10 @@ public void shouldCatchErrorsWhenExecutingInitialScript() {
241
241
@ Test
242
242
public void shouldNotTimeoutWithMultipleCallsTheFirstOneBeingSynchronous () {
243
243
driver .get (pages .ajaxyPage );
244
- driver .manage ().timeouts ().setScriptTimeout (100 , TimeUnit .MILLISECONDS );
244
+ driver .manage ().timeouts ().setScriptTimeout (10 , TimeUnit .MILLISECONDS );
245
245
assertTrue ((Boolean ) executor .executeAsyncScript ("arguments[arguments.length - 1](true);" ));
246
246
assertTrue ((Boolean ) executor .executeAsyncScript (
247
- "var cb = arguments[arguments.length - 1]; window.setTimeout(function(){cb(true);}, 99 );" ));
247
+ "var cb = arguments[arguments.length - 1]; window.setTimeout(function(){cb(true);}, 9 );" ));
248
248
}
249
249
250
250
@ JavascriptEnabled
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ limitations under the License.
34
34
if ( isAsync ) {
35
35
window . clearTimeout ( timeoutId ) ;
36
36
window . removeEventListener ( 'unload' , onunload , false ) ;
37
+ timeoutId = true ;
37
38
}
38
39
39
40
document . __webdriver_evaluate [ 'args' ] = null ;
@@ -65,16 +66,19 @@ limitations under the License.
65
66
66
67
var startTime = new Date ( ) . getTime ( ) ;
67
68
try {
68
- if ( isAsync ) {
69
- timeoutId = window . setTimeout ( function ( ) {
70
- sendResponse (
71
- Error ( 'Timed out waiting for async script result after ' +
72
- ( new Date ( ) . getTime ( ) - startTime ) + 'ms' ) ,
73
- 28 ) ; // "script timeout" == 28
74
- } , timeout ) ;
75
- }
76
69
var result = new Function ( script ) . apply ( null , args ) ;
77
- if ( ! isAsync ) {
70
+ if ( isAsync ) {
71
+ // if the callback method is called synchronously in the provided script
72
+ // don't set a timeout function, since the timeout has already been 'cleared'
73
+ if ( ! timeoutId ) {
74
+ timeoutId = window . setTimeout ( function ( ) {
75
+ sendResponse (
76
+ Error ( 'Timed out waiting for async script result after ' +
77
+ ( new Date ( ) . getTime ( ) - startTime ) + 'ms' ) ,
78
+ 28 ) ; // "script timeout" == 28
79
+ } , timeout ) ;
80
+ }
81
+ } else {
78
82
sendResponse ( result , 0 ) ;
79
83
}
80
84
} catch ( e ) {
You can’t perform that action at this time.
0 commit comments