Skip to content
This repository
Browse code

Merge pull request #10 from kzys/forward-back

Add /session/:sessionId/forward and /session/:sessionId/back
  • Loading branch information...
commit 1fda5cf9118309625073f7bc7273d7917745b0fb 2 parents 01aad6b + cff5fc9
Ivan De Marino authored

Showing 1 changed file with 18 additions and 1 deletion. Show diff stats Hide diff stats

  1. +18 1 request_handlers/session_request_handler.js
19 request_handlers/session_request_handler.js
@@ -11,7 +11,9 @@ ghostdriver.SessionReqHand = function(session) {
11 11 ELEMENT : "element",
12 12 ELEMENT_DIR : "/element/",
13 13 TITLE : "title",
14   - WINDOW : "window"
  14 + WINDOW : "window",
  15 + FORWARD : "forward",
  16 + BACK : "back"
15 17 },
16 18
17 19 _handle = function(req, res) {
@@ -22,6 +24,15 @@ ghostdriver.SessionReqHand = function(session) {
22 24
23 25 _protoParent.handle.call(this, req, res);
24 26
  27 + var responseAfterLoadFinished = function (func) {
  28 + _session.getCurrentWindow().onLoadFinished = function () {
  29 + res.writeJSON(_protoParent.buildSuccessResponseBody.call(this, _session.getId()));
  30 + res.statusCode = 200;
  31 + res.closeGracefully();
  32 + };
  33 + _session.getCurrentWindow().evaluate(func);
  34 + };
  35 +
25 36 // Handle "/url" GET and POST
26 37 if (req.urlParsed.file === _const.URL) { //< ".../url"
27 38 if (req.method === "GET") {
@@ -73,6 +84,12 @@ ghostdriver.SessionReqHand = function(session) {
73 84 throw new ghostdriver.VariableResourceNotFound(req);
74 85 }
75 86 return;
  87 + } else if (req.urlParsed.file === _const.FORWARD) {
  88 + responseAfterLoadFinished(function () { history.forward() });
  89 + return;
  90 + } else if (req.urlParsed.file === _const.BACK) {
  91 + responseAfterLoadFinished(function () { history.back() });
  92 + return;
76 93 }
77 94
78 95 throw new ghostdriver.InvalidCommandMethod(req);

0 comments on commit 1fda5cf

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