Skip to content
Browse files

Merge pull request #10 from kzys/forward-back

Add /session/:sessionId/forward and /session/:sessionId/back
  • Loading branch information...
2 parents 01aad6b + cff5fc9 commit 1fda5cf9118309625073f7bc7273d7917745b0fb @detro committed Apr 26, 2012
Showing with 18 additions and 1 deletion.
  1. +18 −1 request_handlers/session_request_handler.js
View
19 request_handlers/session_request_handler.js
@@ -11,7 +11,9 @@ ghostdriver.SessionReqHand = function(session) {
ELEMENT : "element",
ELEMENT_DIR : "/element/",
TITLE : "title",
- WINDOW : "window"
+ WINDOW : "window",
+ FORWARD : "forward",
+ BACK : "back"
},
_handle = function(req, res) {
@@ -22,6 +24,15 @@ ghostdriver.SessionReqHand = function(session) {
_protoParent.handle.call(this, req, res);
+ var responseAfterLoadFinished = function (func) {
+ _session.getCurrentWindow().onLoadFinished = function () {
+ res.writeJSON(_protoParent.buildSuccessResponseBody.call(this, _session.getId()));
+ res.statusCode = 200;
+ res.closeGracefully();
+ };
+ _session.getCurrentWindow().evaluate(func);
+ };
+
// Handle "/url" GET and POST
if (req.urlParsed.file === _const.URL) { //< ".../url"
if (req.method === "GET") {
@@ -73,6 +84,12 @@ ghostdriver.SessionReqHand = function(session) {
throw new ghostdriver.VariableResourceNotFound(req);
}
return;
+ } else if (req.urlParsed.file === _const.FORWARD) {
+ responseAfterLoadFinished(function () { history.forward() });
+ return;
+ } else if (req.urlParsed.file === _const.BACK) {
+ responseAfterLoadFinished(function () { history.back() });
+ return;
}
throw new ghostdriver.InvalidCommandMethod(req);

0 comments on commit 1fda5cf

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