This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Import GhostDriver v1.0.4

Issues in this release: https://github.com/detro/ghostdriver/issues?labels=1.0.4&state=closed
See GhostDriver Changelog for more details.
  • Loading branch information...
detro committed Jul 25, 2013
1 parent 8114d44 commit 73bb56084028e1ee902bfedb8bd0443b337c7578
Showing with 3,238 additions and 3,628 deletions.
  1. +2 −2 src/ghostdriver/inputs.js
  2. +5 −13 src/ghostdriver/lastupdate
  3. +17 −14 src/ghostdriver/main.js
  4. +3 −0 src/ghostdriver/request_handlers/request_handler.js
  5. +4 −8 src/ghostdriver/request_handlers/router_request_handler.js
  6. +6 −7 src/ghostdriver/request_handlers/session_manager_request_handler.js
  7. +20 −25 src/ghostdriver/request_handlers/session_request_handler.js
  8. +49 −74 src/ghostdriver/request_handlers/webelement_request_handler.js
  9. +36 −33 src/ghostdriver/session.js
  10. +9 −6 src/ghostdriver/third_party/console++.js
  11. +35 −48 src/ghostdriver/third_party/webdriver-atoms/active_element.js
  12. +115 −128 src/ghostdriver/third_party/webdriver-atoms/clear.js
  13. +15 −17 src/ghostdriver/third_party/webdriver-atoms/clear_local_storage.js
  14. +15 −17 src/ghostdriver/third_party/webdriver-atoms/clear_session_storage.js
  15. +135 −137 src/ghostdriver/third_party/webdriver-atoms/click.js
  16. +35 −48 src/ghostdriver/third_party/webdriver-atoms/default_content.js
  17. +267 −254 src/ghostdriver/third_party/webdriver-atoms/deps.js
  18. +108 −118 src/ghostdriver/third_party/webdriver-atoms/double_click.js
  19. +106 −116 src/ghostdriver/third_party/webdriver-atoms/drag.js
  20. +15 −16 src/ghostdriver/third_party/webdriver-atoms/execute_async_script.js
  21. +13 −15 src/ghostdriver/third_party/webdriver-atoms/execute_script.js
  22. +13 −16 src/ghostdriver/third_party/webdriver-atoms/execute_sql.js
  23. +83 −84 src/ghostdriver/third_party/webdriver-atoms/find_element.js
  24. +83 −84 src/ghostdriver/third_party/webdriver-atoms/find_elements.js
  25. +84 −99 src/ghostdriver/third_party/webdriver-atoms/focus_on_element.js
  26. +84 −85 src/ghostdriver/third_party/webdriver-atoms/frame_by_id_or_name.js
  27. +35 −48 src/ghostdriver/third_party/webdriver-atoms/frame_by_index.js
  28. +14 −16 src/ghostdriver/third_party/webdriver-atoms/get_appcache_status.js
  29. +37 −52 src/ghostdriver/third_party/webdriver-atoms/get_attribute.js
  30. +45 −58 src/ghostdriver/third_party/webdriver-atoms/get_attribute_value.js
  31. +7 −7 src/ghostdriver/third_party/webdriver-atoms/get_current_position.js
  32. +7 −8 src/ghostdriver/third_party/webdriver-atoms/get_element_from_cache.js
  33. +35 −48 src/ghostdriver/third_party/webdriver-atoms/get_frame_window.js
  34. +29 −41 src/ghostdriver/third_party/webdriver-atoms/get_in_view_location.js
  35. +15 −17 src/ghostdriver/third_party/webdriver-atoms/get_local_storage_item.js
  36. +15 −17 src/ghostdriver/third_party/webdriver-atoms/get_local_storage_keys.js
  37. +15 −17 src/ghostdriver/third_party/webdriver-atoms/get_local_storage_size.js
  38. +7 −9 src/ghostdriver/third_party/webdriver-atoms/get_location.js
  39. +35 −49 src/ghostdriver/third_party/webdriver-atoms/get_location_in_view.js
  40. +15 −17 src/ghostdriver/third_party/webdriver-atoms/get_session_storage_item.js
  41. +15 −17 src/ghostdriver/third_party/webdriver-atoms/get_session_storage_keys.js
  42. +15 −17 src/ghostdriver/third_party/webdriver-atoms/get_session_storage_size.js
  43. +48 −61 src/ghostdriver/third_party/webdriver-atoms/get_size.js
  44. +85 −89 src/ghostdriver/third_party/webdriver-atoms/get_text.js
  45. +49 −62 src/ghostdriver/third_party/webdriver-atoms/get_top_left_coordinates.js
  46. +46 −59 src/ghostdriver/third_party/webdriver-atoms/get_value_of_css_property.js
  47. +3 −7 src/ghostdriver/third_party/webdriver-atoms/get_window_position.js
  48. +4 −7 src/ghostdriver/third_party/webdriver-atoms/get_window_size.js
  49. +81 −86 src/ghostdriver/third_party/webdriver-atoms/is_displayed.js
  50. +41 −57 src/ghostdriver/third_party/webdriver-atoms/is_enabled.js
  51. +7 −7 src/ghostdriver/third_party/webdriver-atoms/is_online.js
  52. +43 −56 src/ghostdriver/third_party/webdriver-atoms/is_selected.js
  53. +4 −4 src/ghostdriver/third_party/webdriver-atoms/lastupdate
  54. +97 −110 src/ghostdriver/third_party/webdriver-atoms/move_mouse.js
  55. +110 −118 src/ghostdriver/third_party/webdriver-atoms/pinch.js
  56. +15 −17 src/ghostdriver/third_party/webdriver-atoms/remove_local_storage_item.js
  57. +15 −17 src/ghostdriver/third_party/webdriver-atoms/remove_session_storage_item.js
  58. +107 −117 src/ghostdriver/third_party/webdriver-atoms/right_click.js
  59. +110 −118 src/ghostdriver/third_party/webdriver-atoms/rotate.js
  60. +66 −69 src/ghostdriver/third_party/webdriver-atoms/scroll_into_view.js
  61. +98 −110 src/ghostdriver/third_party/webdriver-atoms/scroll_mouse.js
  62. +15 −17 src/ghostdriver/third_party/webdriver-atoms/set_local_storage_item.js
  63. +15 −17 src/ghostdriver/third_party/webdriver-atoms/set_session_storage_item.js
  64. +4 −7 src/ghostdriver/third_party/webdriver-atoms/set_window_position.js
  65. +4 −7 src/ghostdriver/third_party/webdriver-atoms/set_window_size.js
  66. +115 −130 src/ghostdriver/third_party/webdriver-atoms/submit.js
  67. +110 −118 src/ghostdriver/third_party/webdriver-atoms/swipe.js
  68. +110 −118 src/ghostdriver/third_party/webdriver-atoms/tap.js
  69. +114 −128 src/ghostdriver/third_party/webdriver-atoms/type.js
  70. +24 −13 src/ghostdriver/webelementlocator.js
@@ -312,11 +312,11 @@ ghostdriver.Inputs = function () {
},
_mouseButtonDown = function (session, button) {
_mouseButtonClick(session, "mousedown", button);
_mouseButtonEvent(session, "mousedown", button);
},
_mouseButtonUp = function (session, button) {
_mouseButtonClick(session, "mouseUp", button);
_mouseButtonEvent(session, "mouseUp", button);
},
_keyEvent = function (session, eventType, keyCode) {
View
@@ -1,15 +1,7 @@
2013-03-18 01:28:52
2013-07-25 23:22:39
commit 2792939c149829d03e7ed07cd6f03f5fd7e73ef4 (HEAD, tag: refs/tags/1.0.3, refs/remotes/origin/master, refs/remotes/origin/HEAD, refs/heads/master)
Author: Ivan De Marino <ivan.de.marino@gmail.com>
Date: Mon Mar 18 01:27:12 2013 +0000
commit e3c255e66f99fd34fbf03269b8dc44bafdda940a (HEAD, refs/remotes/origin/master, refs/remotes/origin/HEAD, refs/heads/master)
Author: Ivan De Marino <detronizator@gmail.com>
Date: Thu Jul 25 00:21:44 2013 +0100
Java Binding JAR 1.0.3 now ready.
Can be added to a Maven project with:
<dependency>
<groupId>com.github.detro.ghostdriver</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.0.3</version>
</dependency>
Log "page.onError".
View
@@ -25,28 +25,31 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// Load dependencies
// NOTE: We need to provide PhantomJS with the "require" module ASAP. This is a pretty s**t way to load dependencies
var ghostdriver = {
system : require("system"),
hub : require("./hub_register.js"),
logger : require("./logger.js"),
config : null, //< will be set in a short while
version : "1.0.3"
},
server = require("webserver").create(),
router,
parseURI = require("./third_party/parseuri.js"),
_log = ghostdriver.logger.create("GhostDriver");
var server = require("webserver").create(), //< webserver
router, //< router request handler
_log; //< logger for "main.js"
// "ghostdriver" global namespace
ghostdriver = {
system : require("system"),
hub : require("./hub_register.js"),
logger : require("./logger.js"),
config : null, //< this will be set below
version : "1.0.4"
};
// create logger
_log = ghostdriver.logger.create("GhostDriver");
// Initialize the configuration
require("./config.js").init(ghostdriver.system.args);
ghostdriver.config = require("./config.js").get();
// Enable "strict mode" for the 'parseURI' library
parseURI.options.strictMode = true;
require("./third_party/parseuri.js").options.strictMode = true;
// Load all the core dependencies
// NOTE: We need to provide PhantomJS with the "require" module ASAP. This is a pretty s**t way to load dependencies
phantom.injectJs("session.js");
phantom.injectJs("inputs.js");
phantom.injectJs("request_handlers/request_handler.js");
@@ -62,6 +62,9 @@ ghostdriver.RequestHandler = function() {
},
_decorateRequest = function(request) {
// Normalize URL first
request.url = request.url.replace(/^\/wd\/hub/, '');
// Then parse it
request.urlParsed = require("./third_party/parseuri.js").parse(request.url);
},
@@ -59,17 +59,13 @@ ghostdriver.RouterReqHand = function() {
_log.debug("_handle", "Request => " + JSON.stringify(req, null, " "));
try {
if (req.urlParsed.directory.match(/^\/wd\/hub/)) {
req.url = req.urlParsed.source.replace(/^\/wd\/hub/, '');
req.urlParsed = require("./third_party/parseuri.js").parse(req.url);
}
if (req.urlParsed.file === _const.STATUS) { // GET '/status'
if (req.urlParsed.chunks.length === 1 && req.urlParsed.file === _const.STATUS) { // GET '/status'
_statusRH.handle(req, res);
} else if (req.urlParsed.file === _const.SHUTDOWN) { // GET '/shutdown'
} else if (req.urlParsed.chunks.length === 1 && req.urlParsed.file === _const.SHUTDOWN) { // GET '/shutdown'
_shutdownRH.handle(req, res);
phantom.exit();
} else if (req.urlParsed.file === _const.SESSION || // POST '/session'
req.urlParsed.file === _const.SESSIONS || // GET '/sessions'
} else if ((req.urlParsed.chunks.length === 1 && req.urlParsed.file === _const.SESSION) || // POST '/session'
(req.urlParsed.chunks.length === 1 && req.urlParsed.file === _const.SESSIONS) || // GET '/sessions'
req.urlParsed.directory === _const.SESSION_DIR) { // GET or DELETE '/session/:id'
_sessionManRH.handle(req, res);
} else if (req.urlParsed.chunks[0] === _const.SESSION) { // GET, POST or DELETE '/session/:id/...'
@@ -40,10 +40,10 @@ ghostdriver.SessionManagerReqHand = function() {
_handle = function(req, res) {
_protoParent.handle.call(this, req, res);
if (req.urlParsed.file === "session" && req.method === "POST") {
if (req.urlParsed.chunks.length === 1 && req.urlParsed.file === "session" && req.method === "POST") {
_postNewSessionCommand(req, res);
return;
} else if (req.urlParsed.file === "sessions" && req.method === "GET") {
} else if (req.urlParsed.chunks.length === 1 && req.urlParsed.file === "sessions" && req.method === "GET") {
_getActiveSessionsCommand(req, res);
return;
} else if (req.urlParsed.directory === "/session/") {
@@ -60,7 +60,8 @@ ghostdriver.SessionManagerReqHand = function() {
_postNewSessionCommand = function(req, res) {
var newSession,
postObj;
postObj,
redirectToHost;
try {
postObj = JSON.parse(req.post);
@@ -76,10 +77,8 @@ ghostdriver.SessionManagerReqHand = function() {
_log.info("_postNewSessionCommand", "New Session Created: " + newSession.getId());
// Redirect to the newly created Session
res.statusCode = 303; //< "303 See Other"
res.setHeader("Location", "http://" + req.headers.Host + "/wd/hub/session/"+newSession.getId());
res.closeGracefully();
// Return newly created Session Capabilities
res.success(newSession.getId(), newSession.getCapabilities());
return;
}
@@ -456,31 +456,23 @@ ghostdriver.SessionReqHand = function(session) {
currWindow.switchToMainFrame();
// Load URL and wait for load to finish (or timeout)
currWindow.execFuncAndWaitForLoad(
function() {
currWindow.open(postObj.url);
currWindow.execFuncAndWaitForLoad(function() {
currWindow.open(postObj.url.trim());
},
_createOnSuccessHandler(res), //< success
function(errMsg) { //< failure/timeout
if (errMsg === "timeout") {
// Request timed out
_errors.handleFailedCommandEH(
_errors.FAILED_CMD_STATUS.TIMEOUT,
"URL '" + postObj.url + "' didn't load within the 'Page Load Timeout'",
req,
res,
_session,
"SessionReqHand");
} else {
// Unknown error
_errors.handleFailedCommandEH(
_errors.FAILED_CMD_STATUS.UNKNOWN_ERROR,
"URL '" + postObj.url + "' didn't load. Error: '" + errMsg + "'",
req,
res,
_session,
"SessionReqHand");
}
_createOnSuccessHandler(res), //< success
function(errMsg) { //< failure/timeout
var errCode = errMsg === "timeout"
? _errors.FAILED_CMD_STATUS.TIMEOUT
: _errors.FAILED_CMD_STATUS.UNKNOWN_ERROR;
// Report error
_errors.handleFailedCommandEH(
errCode,
"URL '" + postObj.url + "' didn't load. Error: '" + errMsg + "'",
req,
res,
_session,
"SessionReqHand");
});
} else {
throw _errors.createInvalidReqMissingCommandParameterEH(req);
@@ -498,6 +490,9 @@ ghostdriver.SessionReqHand = function(session) {
}
if (typeof(postObj["type"]) !== "undefined" && typeof(postObj["ms"]) !== "undefined") {
_log.debug("_postTimeout", JSON.stringify(postObj));
// Set the right timeout on the Session
switch(postObj["type"]) {
case _session.timeoutNames.SCRIPT:
@@ -820,7 +815,7 @@ ghostdriver.SessionReqHand = function(session) {
_postWindowCommand = function(req, res) {
var params = JSON.parse(req.post);
if (typeof(params) === "object" && params.name) {
if (typeof(params) === "object" && typeof(params.name) === "string") {
// Report a success if we manage to switch the current window,
// otherwise throw a Failed Command Error
if (_session.switchToWindow(params.name)) {
@@ -364,49 +364,38 @@ ghostdriver.WebElementReqHand = function(idOrElement, session) {
abortCallback = false;
currWindow.execFuncAndWaitForLoad(function() {
// do the submit
submitRes = currWindow.evaluate(require("./webdriver_atoms.js").get("submit"), _getJSON());
// If Submit was NOT positive, status will be set to something else than '0'
submitRes = JSON.parse(submitRes);
if (submitRes && submitRes.status !== 0) {
abortCallback = true; //< handling the error here
res.respondBasedOnResult(_session, req, submitRes);
}
}, function(status) { //< onLoadFinished
// Report about the Load, only if it was not already handled
if (!abortCallback) {
if (status === "success") {
// do the submit
submitRes = currWindow.evaluate(require("./webdriver_atoms.js").get("submit"), _getJSON());
// If Submit was NOT positive, status will be set to something else than '0'
submitRes = JSON.parse(submitRes);
if (submitRes && submitRes.status !== 0) {
abortCallback = true; //< handling the error here
res.respondBasedOnResult(_session, req, submitRes);
}
},
function(status) { //< onLoadFinished
// Report about the Load, only if it was not already handled
if (!abortCallback) {
res.success(_session.getId());
} else {
}
},
function(errMsg) {
var errCode = errMsg === "timeout"
? _errors.FAILED_CMD_STATUS.TIMEOUT
: _errors.FAILED_CMD_STATUS.UNKNOWN_ERROR;
// Report Submit Error, only if callbacks were not "aborted"
if (!abortCallback) {
_errors.handleFailedCommandEH(
_errors.FAILED_CMD_STATUS.UNKNOWN_ERROR,
"Submit succeeded but Load Failed. Status: '" + status + "'",
errCode,
"Submit failed: " + errMsg,
req,
res,
_session,
"WebElementReqHand");
}
}
}, function(errMsg) {
if (errMsg === "timeout") { //< onTimeout
_errors.handleFailedCommandEH(
_errors.FAILED_CMD_STATUS.TIMEOUT,
"Submit timed-out",
req,
res,
_session,
"WebElementReqHand");
} else { //< onError (generic)
_errors.handleFailedCommandEH(
_errors.FAILED_CMD_STATUS.UNKNOWN_ERROR,
"Submit failed: " + arguments[0],
req,
res,
_session,
"WebElementReqHand");
}
});
});
},
_postClickCommand = function(req, res) {
@@ -416,52 +405,38 @@ ghostdriver.WebElementReqHand = function(idOrElement, session) {
// Clicking on Current Element can cause a page load, hence we need to wait for it to happen
currWindow.execFuncAndWaitForLoad(function() {
// do the click
clickRes = currWindow.evaluate(require("./webdriver_atoms.js").get("click"), _getJSON());
// If Click was NOT positive, status will be set to something else than '0'
clickRes = JSON.parse(clickRes);
if (clickRes && clickRes.status !== 0) {
abortCallback = true; //< handling the error here
res.respondBasedOnResult(_session, req, clickRes);
}
}, function(status) { //< onLoadFinished
// Report Load Finished, only if callbacks were not "aborted"
if (!abortCallback) {
if (status === "success") {
// do the click
clickRes = currWindow.evaluate(require("./webdriver_atoms.js").get("click"), _getJSON());
// If Click was NOT positive, status will be set to something else than '0'
clickRes = JSON.parse(clickRes);
if (clickRes && clickRes.status !== 0) {
abortCallback = true; //< handling the error here
res.respondBasedOnResult(_session, req, clickRes);
}
},
function(status) { //< onLoadFinished
// Report Load Finished, only if callbacks were not "aborted"
if (!abortCallback) {
res.success(_session.getId());
} else {
_errors.handleFailedCommandEH(
_errors.FAILED_CMD_STATUS.UNKNOWN_ERROR,
"Click succeeded but Load Failed. Status: '" + status + "'",
req,
res,
_session,
"WebElementReqHand");
}
}
}, function(errMsg) {
// Report Load Error, only if callbacks were not "aborted"
if (!abortCallback) {
if (errMsg === "timeout") { //< onTimeout
},
function(errMsg) {
var errCode = errMsg === "timeout"
? _errors.FAILED_CMD_STATUS.TIMEOUT
: _errors.FAILED_CMD_STATUS.UNKNOWN_ERROR;
// Report Load Error, only if callbacks were not "aborted"
if (!abortCallback) {
_errors.handleFailedCommandEH(
_errors.FAILED_CMD_STATUS.TIMEOUT,
"Click failed: " + arguments[0],
req,
res,
_session,
"WebElementReqHand");
} else { //< onError
_errors.handleFailedCommandEH(
_errors.FAILED_CMD_STATUS.UNKNOWN_ERROR,
"Click failed: " + arguments[0],
errCode,
"Click failed: " + errMsg,
req,
res,
_session,
"WebElementReqHand");
}
}
});
});
},
_getSelectedCommand = function(req, res) {
Oops, something went wrong.

0 comments on commit 73bb560

Please sign in to comment.