Skip to content
This repository
Browse code

Handle case when "submit" doesn't return.

This happens when the "onsubmit" event gets aborted within the page.
In the current implementation, we would wait indefinitely.
This fix makes sure we "timeout" and report the error.

Closes Issue #107.
  • Loading branch information...
commit 279b6c577931ed17614d81dd3bed757a8a4453bd 1 parent 01609ed
Ivan De Marino authored October 31, 2012
38  src/request_handlers/webelement_request_handler.js
@@ -347,37 +347,43 @@ ghostdriver.WebElementReqHand = function(idOrElement, session) {
347 347
     },
348 348
 
349 349
     _postSubmitCommand = function(req, res) {
350  
-        var submitRes,
  350
+        var currWindow = _protoParent.getSessionCurrWindow.call(this, _session, req),
  351
+            submitRes,
351 352
             abortCallback = false;
352 353
 
353  
-        // Listen for the page to Finish Loading after the submit
354  
-        _protoParent.getSessionCurrWindow.call(this, _session, req).setOneShotCallback("onLoadFinished", function(status) {
  354
+        currWindow.execFuncAndWaitForLoad(function() {  //< do the submit
  355
+            submitRes = currWindow.evaluate(require("./webdriver_atoms.js").get("submit"), _getJSON());
  356
+
  357
+            // If Submit was NOT positive, status will be set to something else than '0'
  358
+            submitRes = JSON.parse(submitRes);
  359
+            if (submitRes && submitRes.status !== 0) {
  360
+                abortCallback = true;   //< handling the error here
  361
+                res.respondBasedOnResult(_session, req, submitRes);
  362
+            }
  363
+        }, function(status) {                   //< onLoadFinished
  364
+            // Report about the Load, only if it was not already handled
355 365
             if (!abortCallback) {
356 366
                 if (status === "success") {
357 367
                     res.success(_session.getId());
358 368
                 } else {
359 369
                     _errors.handleFailedCommandEH(
360 370
                         _errors.FAILED_CMD_STATUS.UNKNOWN_ERROR,
361  
-                        "Submit failed",
  371
+                        "Submit succeded but Load Failed",
362 372
                         req,
363 373
                         res,
364 374
                         _session,
365 375
                         "WebElementReqHand");
366 376
                 }
367 377
             }
  378
+        }, function() {                         //< onError / onTimeout
  379
+            _errors.handleFailedCommandEH(
  380
+                _errors.FAILED_CMD_STATUS.UNKNOWN_ERROR,
  381
+                "Submit failed",
  382
+                req,
  383
+                res,
  384
+                _session,
  385
+                "WebElementReqHand");
368 386
         });
369  
-
370  
-        // Submit
371  
-        submitRes = _protoParent.getSessionCurrWindow.call(this, _session, req).evaluate(
372  
-            require("./webdriver_atoms.js").get("submit"),
373  
-            _getJSON());
374  
-
375  
-        // If Submit was NOT positive, status will be set to something else than '0'
376  
-        submitRes = JSON.parse(submitRes);
377  
-        if (submitRes && submitRes.status !== 0) {
378  
-            abortCallback = true; //< handling the error here
379  
-            res.respondBasedOnResult(_session, req, submitRes);
380  
-        }
381 387
     },
382 388
 
383 389
     _postClickCommand = function(req, res) {
8  src/session.js
@@ -157,7 +157,7 @@ ghostdriver.Session = function(desiredCapabilities) {
157 157
                 clearTimeout(timer);
158 158
                 clearAllCallbacks();
159 159
 
160  
-                onLoadFunc();
  160
+                onLoadFunc.apply(thisPage, arguments);
161 161
             }
162 162
         });
163 163
         this.setOneShotCallback("onLoadFinished", function () {
@@ -165,7 +165,7 @@ ghostdriver.Session = function(desiredCapabilities) {
165 165
             clearTimeout(timer);
166 166
             clearAllCallbacks();
167 167
 
168  
-            onLoadFunc();
  168
+            onLoadFunc.apply(thisPage, arguments);
169 169
         });
170 170
         this.setOneShotCallback("onError", function(message, stack) {
171 171
             // console.log("onError: "+message+"\n");
@@ -180,7 +180,7 @@ ghostdriver.Session = function(desiredCapabilities) {
180 180
             clearTimeout(timer);
181 181
             clearAllCallbacks();
182 182
 
183  
-            onErrorFunc();
  183
+            onErrorFunc.apply(thisPage, arguments);
184 184
         });
185 185
 
186 186
         // Starting timer
@@ -188,7 +188,7 @@ ghostdriver.Session = function(desiredCapabilities) {
188 188
             thisPage.stop(); //< stop the page from loading
189 189
             clearAllCallbacks();
190 190
 
191  
-            onErrorFunc();
  191
+            onErrorFunc.apply(thisPage, arguments);
192 192
         }, _getTimeout(_const.TIMEOUT_NAMES.PAGE_LOAD));
193 193
 
194 194
         // We are ready to execute

0 notes on commit 279b6c5

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