Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: detro/ghostdriver
base: 5235f3f343
...
head fork: detro/ghostdriver
compare: b5dc1cc31f
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 17, 2012
@detro Adding "/session/:id/window_handle(s)" commands 271ff1a
@detro A positive "Response" is now a one-liner.
Added a "decorator" method (res.success()) to handle success responses with minimum code.
b5dc1cc
View
5 examples/google_cheese/src/main/java/ghostdriver/GoogleCheeseServerOnly.java
@@ -8,6 +8,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
+import java.util.Set;
import java.util.concurrent.TimeUnit;
@@ -72,6 +73,10 @@ public static long runTest(int port) throws MalformedURLException, IOException,
driver.manage().timeouts().setScriptTimeout(2, TimeUnit.SECONDS);
System.out.println("Done changing Timeouts.");
+ System.out.println("Current Window Handle: " + driver.getWindowHandle());
+ Set<String> whandles = driver.getWindowHandles();
+ System.out.println("Number of Window Handles: " + whandles.size() + " - list: " + whandles.toString());
+
// Play around with the navigation...
driver.navigate().refresh();
System.out.println("Refreshed.");
View
19 src/request_handlers/request_handler.js
@@ -56,10 +56,27 @@ ghostdriver.RequestHandler = function() {
request.urlParsed = require("./third_party/parseuri.js").parse(request.url);
},
+ _writeJSONDecorator = function(obj) {
+ this.write(JSON.stringify(obj));
+ },
+
+ _successDecorator = function(sessionId, value) {
+ this.statusCode = 200;
+
+ if (arguments.length > 0) {
+ // write something, only if there is something to write
+ this.writeJSON(_buildSuccessResponseBody(sessionId, value));
+ this.close();
+ } else {
+ this.closeGracefully();
+ }
+ },
+
_decorateResponse = function(response) {
response.setHeader("Cache", "no-cache");
response.setHeader("Content-Type", "application/json;charset=UTF-8");
- response.writeJSON = function(obj) { this.write(JSON.stringify(obj)); };
+ response.writeJSON = _writeJSONDecorator;
+ response.success = _successDecorator;
},
_buildResponseBody = function(sessionId, value, statusCode) {
View
12 src/request_handlers/session_manager_request_handler.js
@@ -80,8 +80,6 @@ ghostdriver.SessionManagerReqHand = function() {
var activeSessions = [],
sessionId;
- res.statusCode = 200;
-
// Create array of format '[{ "id" : SESSION_ID, "capabilities" : SESSION_CAPABILITIES_OBJECT }]'
for (sessionId in _sessions) {
activeSessions.push({
@@ -90,8 +88,7 @@ ghostdriver.SessionManagerReqHand = function() {
});
}
- res.writeJSON(_protoParent.buildSuccessResponseBody.call(this, null, activeSessions));
- res.close();
+ res.success(null, activeSessions);
},
_deleteSession = function(sessionId) {
@@ -112,8 +109,7 @@ ghostdriver.SessionManagerReqHand = function() {
if (typeof(_sessions[sId]) !== "undefined") {
_deleteSession(sId);
- res.statusCode = 200;
- res.closeGracefully();
+ res.success();
} else {
throw _errors.createInvalidReqVariableResourceNotFoundEH(req);
}
@@ -128,9 +124,7 @@ ghostdriver.SessionManagerReqHand = function() {
session = _getSession(sId);
if (session !== null) {
- res.statusCode = 200;
- res.writeJSON(_protoParent.buildSuccessResponseBody.call(this, sId, _sessions[sId].getCapabilities()));
- res.close();
+ res.success(sId, _sessions[sId].getCapabilities());
} else {
throw _errors.createInvalidReqVariableResourceNotFoundEH(req);
}
View
51 src/request_handlers/session_request_handler.js
@@ -49,7 +49,9 @@ ghostdriver.SessionReqHand = function(session) {
TIMEOUTS : "timeouts",
TIMEOUTS_DIR : "/timeouts/",
ASYNC_SCRIPT : "async_script",
- IMPLICIT_WAIT : "implicit_wait"
+ IMPLICIT_WAIT : "implicit_wait",
+ WINDOW_HANDLE : "window_handle",
+ WINDOW_HANDLES : "window_handles"
},
_errors = require("./errors.js"),
@@ -115,6 +117,12 @@ ghostdriver.SessionReqHand = function(session) {
req.method === "POST") {
_postTimeout(req, res);
return;
+ } else if (req.urlParsed.file === _const.WINDOW_HANDLE && req.method === "GET") {
+ _getWindowHandle(req, res);
+ return;
+ } else if (req.urlParsed.file === _const.WINDOW_HANDLES && req.method === "GET") {
+ _getWindowHandles(req, res);
+ return;
}
throw _errors.createInvalidReqInvalidCommandMethodEH(req);
@@ -122,9 +130,7 @@ ghostdriver.SessionReqHand = function(session) {
_createOnSuccessHandler = function(res) {
return function (status) {
- res.statusCode = 200;
- res.writeJSON(_protoParent.buildSuccessResponseBody.call(res, _session.getId()));
- res.closeGracefully();
+ res.success(_session.getId());
};
},
@@ -168,9 +174,7 @@ ghostdriver.SessionReqHand = function(session) {
}
// If we arrive here, everything should be fine, birds are singing, the sky is blue
- res.statusCode = 200;
- res.writeJSON(_protoParent.buildSuccessResponseBody.call(this, _session.getId(), result.value));
- res.close();
+ res.success(_session.getId(), result.value);
},
_refreshCommand = function(req, res) {
@@ -261,12 +265,17 @@ ghostdriver.SessionReqHand = function(session) {
}
},
+ _getWindowHandle = function(req, res) {
+ res.success(_session.getId(), _session.getCurrentWindowHandle());
+ },
+
+ _getWindowHandles = function(req, res) {
+ res.success(_session.getId(), _session.getWindowHandles());
+ },
+
_getScreenshotCommand = function(req, res) {
var rendering = _session.getCurrentWindow().renderBase64PNG();
-
- res.statusCode = 200;
- res.writeJSON(_protoParent.buildSuccessResponseBody.call(this, _session.getId(), rendering));
- res.close();
+ res.success(_session.getId(), rendering);
},
_getUrlCommand = function(req, res) {
@@ -292,8 +301,7 @@ ghostdriver.SessionReqHand = function(session) {
clearTimeout(timer);
if (status === "success") {
- res.statusCode = 200;
- res.closeGracefully();
+ res.success();
} else {
_errors.handleInvalidReqInvalidCommandMethodEH(req, res);
}
@@ -323,11 +331,9 @@ ghostdriver.SessionReqHand = function(session) {
postObj["type"] = _session.timeoutNames().ASYNC_SCRIPT;
}
- if (typeof(postObj["type"]) !== "undefined" &&
- typeof(postObj["ms"]) !== "undefined") {
+ if (typeof(postObj["type"]) !== "undefined" && typeof(postObj["ms"]) !== "undefined") {
_session.setTimeout(postObj["type"], postObj["ms"]);
- res.statusCode = 200;
- res.closeGracefully();
+ res.success();
} else {
throw _errors.createInvalidReqMissingCommandParameterEH(req);
}
@@ -336,8 +342,7 @@ ghostdriver.SessionReqHand = function(session) {
_deleteWindowCommand = function(req, res) {
// TODO An optional JSON parameter "name" might be given
_session.closeCurrentWindow();
- res.statusCode = 200;
- res.closeGracefully();
+ res.success();
},
_postWindowCommand = function(req, res) {
@@ -347,9 +352,7 @@ ghostdriver.SessionReqHand = function(session) {
_getTitleCommand = function(req, res) {
var result = _session.getCurrentWindow().evaluate(function() { return document.title; });
- res.statusCode = 200;
- res.writeJSON(_protoParent.buildSuccessResponseBody.call(this, _session.getId(), result));
- res.close();
+ res.success(_session.getId(), result);
},
_postElementCommand = function(req, res) {
@@ -363,9 +366,7 @@ ghostdriver.SessionReqHand = function(session) {
do {
element = _locator.locateElement(JSON.parse(req.post));
if (element) {
- res.statusCode = 200;
- res.writeJSON(_protoParent.buildSuccessResponseBody.call(this, _session.getId(), element.getJSON()));
- res.close();
+ res.success(_session.getId(), element.getJSON());
return;
}
} while(searchStartTime + _session.getTimeout(_session.timeoutNames().IMPLICIT) >= new Date().getTime());
View
4 src/request_handlers/status_request_handler.js
@@ -48,9 +48,7 @@ ghostdriver.StatusReqHand = function() {
_protoParent.handle.call(this, req, res);
if (req.method === "GET" && req.urlParsed.file === "status") {
- res.statusCode = 200;
- res.writeJSON(_protoParent.buildSuccessResponseBody.call(this, null, _statusObj));
- res.close();
+ res.success(null, _statusObj);
return;
}
View
6 src/request_handlers/webelement_request_handler.js
@@ -70,8 +70,7 @@ ghostdriver.WebElementReqHand = function(id, session) {
// TODO - Error handling based on the value of "typeRes"
- res.statusCode = 200;
- res.closeGracefully();
+ res.success();
return;
}
@@ -85,8 +84,7 @@ ghostdriver.WebElementReqHand = function(id, session) {
// Listen for the page to Finish Loading after the submit
_getSession().getCurrentWindow().setOneShotCallback("onLoadFinished", function(status) {
if (status === "success") {
- res.statusCode = 200;
- res.closeGracefully();
+ res.success();
}
// TODO - what do we do if this fails?
View
12 src/session.js
@@ -141,6 +141,14 @@ ghostdriver.Session = function(desiredCapabilities) {
return Object.keys(_windows).length;
},
+ _getCurrentWindowHandle = function() {
+ return _currentWindowHandle;
+ },
+
+ _getWindowHandles = function() {
+ return Object.keys(_windows);
+ },
+
_closeWindow = function(windowHandle) {
_windows[windowHandle].release();
delete _windows[windowHandle];
@@ -182,7 +190,9 @@ ghostdriver.Session = function(desiredCapabilities) {
aboutToDelete : _aboutToDelete,
setTimeout : _setTimeout,
getTimeout : _getTimeout,
- timeoutNames : _timeoutNames
+ timeoutNames : _timeoutNames,
+ getCurrentWindowHandle : _getCurrentWindowHandle,
+ getWindowHandles : _getWindowHandles
};
};

No commit comments for this range

Something went wrong with that request. Please try again.