Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various improvements. #30

Merged
merged 5 commits into from May 30, 2012
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/request_handlers/request_handler.js
@@ -1,7 +1,7 @@
/*
This file is part of the GhostDriver project from Neustar inc.

Copyright (c) 2012, Ivan De Marino <ivan.de.marino@gmail.com> - Neustar inc.
Copyright (c) 2012, Ivan De Marino <ivan.de.marino@gmail.com> - Neustar inc. and other authors.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -94,10 +94,12 @@ ghostdriver.RequestHandler = function() {
},

_buildResponseBody = function(sessionId, value, statusCode) {
// Need to check for undefined to prevent errors when trying to return boolean false
if(typeof(value) === "undefined") value = {};
return {
"sessionId" : sessionId || null,
"status" : statusCode || 0, //< '0' is Success
"value" : value || {}
"value" : value
};
},

Expand Down
32 changes: 30 additions & 2 deletions src/request_handlers/session_request_handler.js
@@ -1,7 +1,7 @@
/*
This file is part of the GhostDriver project from Neustar inc.

Copyright (c) 2012, Ivan De Marino <ivan.de.marino@gmail.com> - Neustar inc.
Copyright (c) 2012, Ivan De Marino <ivan.de.marino@gmail.com> - Neustar inc. and others.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you want to enter "and other authors" right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's appropriate.

All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -52,7 +52,9 @@ ghostdriver.SessionReqHand = function(session) {
IMPLICIT_WAIT : "implicit_wait",
WINDOW_HANDLE : "window_handle",
WINDOW_HANDLES : "window_handles",
FRAME : "frame"
FRAME : "frame",
SOURCE : "source",
COOKIE : "cookie"
},
_errors = require("./errors.js"),

Expand Down Expand Up @@ -127,6 +129,16 @@ ghostdriver.SessionReqHand = function(session) {
} else if (req.urlParsed.file === _const.FRAME && req.method === "POST") {
_postFrameCommand(req, res);
return;
} else if (req.urlParsed.file === _const.SOURCE && req.method === "GET") {
_getSourceCommand(req, res);
return;
} else if (req.urlParsed.file === _const.COOKIE) {
if(req.method === "DELETE") {
console.log("Handling delete cookie command...");
_deleteCookieCommand(req, res);
console.log("Cookies deleted.");
return;
}
}

throw _errors.createInvalidReqInvalidCommandMethodEH(req);
Expand Down Expand Up @@ -368,6 +380,22 @@ ghostdriver.SessionReqHand = function(session) {
}
},

_getSourceCommand = function(req, res) {
var source = _session.getCurrentWindow().content;
res.success(_session.getId(), source);
},

_deleteCookieCommand = function(req, res) {
_session.getCurrentWindow().evaluate(function() {
var p = document.cookie.split(";");
for(i=p.length-1;i>=0;--i) {
var key = p[i].split("=");
document.cookie = key + "=";
}
});
res.success(_session.getId());
},

_deleteWindowCommand = function(req, res) {
// TODO An optional JSON parameter "name" might be given
_session.closeCurrentWindow();
Expand Down
16 changes: 14 additions & 2 deletions src/request_handlers/webelement_request_handler.js
@@ -1,7 +1,7 @@
/*
This file is part of the GhostDriver project from Neustar inc.

Copyright (c) 2012, Ivan De Marino <ivan.de.marino@gmail.com> - Neustar inc.
Copyright (c) 2012, Ivan De Marino <ivan.de.marino@gmail.com> - Neustar inc. and other authors.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -35,7 +35,8 @@ ghostdriver.WebElementReqHand = function(id, session) {
_protoParent = ghostdriver.WebElementReqHand.prototype,
_const = {
VALUE : "value",
SUBMIT : "submit"
SUBMIT : "submit",
DISPLAYED : "displayed"
},
_errors = require("./errors.js"),

Expand All @@ -50,13 +51,24 @@ ghostdriver.WebElementReqHand = function(id, session) {
} else if (req.urlParsed.file === _const.SUBMIT && req.method === "POST") {
_submitCommand(req, res);
return;
} else if (req.urlParsed.file === _const.DISPLAYED && req.method === "GET") {
_getDisplayedCommand(req, res);
return;
} // else ...

// TODO lots to do...

throw _errors.createInvalidReqInvalidCommandMethodEH(req);
},

_getDisplayedCommand = function(req, res) {
var isDisplayedAtom = require("./webdriver_atoms.js").get("is_displayed");
var displayed = _session.getCurrentWindow().evaluate(isDisplayedAtom, _getJSON());
displayed = JSON.parse(displayed).value;
res.success(_session.getId(), displayed);
// TODO handle StaleElementReference
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me think that I need to migrate "_respondBasedOnResult" to the "session decoration".

I will.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will take a look.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want to give this a go?

I have reviewed your code: if you are going to add this, I'll wait to merge so that I can also review that and do one big merge :)

Otherwise, tomorrow I shall resume my work on GhostDriver (I was away from this code for the last 4/5 days) and I'll do it.
As you prefer.

I'm based in Europe (to give a time reference).

},

_valueCommand = function(req, res) {
var i, ilen,
postObj = JSON.parse(req.post),
Expand Down