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

Implicit wait fix / adding test for it #83

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/errors.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 / detronizator@gmail.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
27 changes: 27 additions & 0 deletions src/hub_register.js
@@ -1,3 +1,30 @@
/*
This file is part of the GhostDriver project from Neustar inc.

Copyright (c) 2012, Ivan De Marino <ivan.de.marino@gmail.com / detronizator@gmail.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/* generate node configuration for this node */
var nodeconf = function(port, hub){
var ref$, hubHost, hubPort;
Expand Down
2 changes: 1 addition & 1 deletion src/main.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 / detronizator@gmail.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
11 changes: 9 additions & 2 deletions src/request_handlers/request_handler.js
@@ -1,8 +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, Alex Anderson <@alxndrsn>
Copyright (c) 2012, Ivan De Marino <ivan.de.marino@gmail.com / detronizator@gmail.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -34,6 +33,14 @@ ghostdriver.RequestHandler = function() {
_errors = require("./errors.js"),
_session = null,
_handle = function(request, response) {
// NOTE: Some language bindings result in a malformed "post" object.
// This might have to do with PhantomJS poor WebServer implementation.
// Here we override "request.post" with the "request.postRaw" that
// is usually left intact.
if (request.hasOwnProperty("postRaw")) {
request["post"] = request["postRaw"];
}

_decorateRequest(request);
_decorateResponse(response);
},
Expand Down
2 changes: 1 addition & 1 deletion src/request_handlers/router_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 / detronizator@gmail.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
2 changes: 1 addition & 1 deletion src/request_handlers/session_manager_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 / detronizator@gmail.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
41 changes: 25 additions & 16 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 / detronizator@gmail.com>
Copyright (c) 2012, Alex Anderson <@alxndrsn>
All rights reserved.

Expand Down Expand Up @@ -732,10 +732,10 @@ ghostdriver.SessionReqHand = function(session) {
res.success(_session.getId(), _protoParent.getSessionCurrWindow.call(this, req).title);
},

_locateElementCommand = function(req, res, locatorMethod) {
_locateElementCommand = function(req, res, locatorMethod, startTime) {
// Search for a WebElement on the Page
var elementOrElements,
searchStartTime = new Date().getTime(),
searchStartTime = startTime || new Date().getTime(),
request = {};

// If a "locatorMethod" was not provided, default to "locateElement"
Expand All @@ -750,23 +750,32 @@ ghostdriver.SessionReqHand = function(session) {
}

// Try to find the element
// and retry if "startTime + implicitTimeout" is
// greater (or equal) than current time
do {
elementOrElements = locatorMethod(request);
elementOrElements = locatorMethod(request);

// console.log("Element or Elements: "+JSON.stringify(elementOrElements));
// console.log("Element or Elements: "+JSON.stringify(elementOrElements));

if (elementOrElements &&
elementOrElements.hasOwnProperty("status") &&
elementOrElements.status === 0 &&
elementOrElements.hasOwnProperty("value")) {
if (elementOrElements &&
elementOrElements.hasOwnProperty("status") &&
elementOrElements.status === 0 &&
elementOrElements.hasOwnProperty("value")) {

res.success(_session.getId(), elementOrElements.value);
return;
// find elements that returns no elements
// needs to keep finding if implicit wait set
if (elementOrElements.value.length != 0 ||
searchStartTime + _session.getTimeout(_session.timeoutNames().IMPLICIT) <
new Date().getTime()) {
res.success(_session.getId(), elementOrElements.value);
return;
}

}
} while(searchStartTime + _session.getTimeout(_session.timeoutNames().IMPLICIT) >= new Date().getTime());
}

// retry if "startTime + implicitTimeout" is
// greater (or equal) than current time
if (searchStartTime + _session.getTimeout(_session.timeoutNames().IMPLICIT) >= new Date().getTime()) {
setTimeout(function(){_locateElementCommand(req, res, locatorMethod, searchStartTime);}, 50);
Copy link
Owner

Choose a reason for hiding this comment

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

This would yeld!
The timeout will be put in the events queue, and stay there until picked.
The loop I used won't yeld.

I don't see why this is a good idea, sorry.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it will, kind of the point. It appears that looping with the while consumes the thread, which appears to be the same one that is the UI thread for the page itself (at least that's what it appeared to do to me).

Please give the test a try with and without this change.

Copy link
Owner

Choose a reason for hiding this comment

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

Will look into this. You might be right and I just spoke without thinking through it (I replied this morning, before my espresso, so I don't consider that good/quality thinking :P)

return;
}

// Error handler. We got a valid response, but it was an error response.
if (elementOrElements) {
Expand Down
2 changes: 1 addition & 1 deletion src/request_handlers/shutdown_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 / detronizator@gmail.com>
Copyright (c) 2010, Jim Evans <james.h.evans.jr@gmail.com> - Salesforce.com
All rights reserved.

Expand Down
2 changes: 1 addition & 1 deletion src/request_handlers/status_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 / detronizator@gmail.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
2 changes: 1 addition & 1 deletion 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 / detronizator@gmail.com>
Copyright (c) 2012, Alex Anderson <@alxndrsn>
All rights reserved.

Expand Down
2 changes: 1 addition & 1 deletion src/session.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 / detronizator@gmail.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
4 changes: 2 additions & 2 deletions src/third_party/parseuri.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 / detronizator@gmail.com>
Copyright (c) 2011, Steven Levithan <stevenlevithan.com>
All rights reserved.

Expand Down Expand Up @@ -67,4 +67,4 @@ parseUri.options = {
if (exports) {
exports.options = parseUri.options;
exports.parse = parseUri;
}
}
2 changes: 1 addition & 1 deletion src/webdriver_atoms.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 / detronizator@gmail.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
2 changes: 1 addition & 1 deletion src/webelementlocator.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 / detronizator@gmail.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
30 changes: 28 additions & 2 deletions test/java/src/test/java/ghostdriver/BaseTest.java
@@ -1,3 +1,30 @@
/*
This file is part of the GhostDriver project from Neustar inc.

Copyright (c) 2012, Ivan De Marino <ivan.de.marino@gmail.com / detronizator@gmail.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package ghostdriver;

import org.junit.After;
Expand All @@ -8,7 +35,6 @@
import org.openqa.selenium.remote.DesiredCapabilities;
import phantomjs.PhantomJSDriver;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
Expand All @@ -20,7 +46,7 @@
public abstract class BaseTest {
private WebDriver mDriver = null;

private static final String CONFIG_FILE = "config.ini";
private static final String CONFIG_FILE = "../config.ini";
private static final String BROWSER_FIREFOX = "firefox";
private static final String BROWSER_PHANTOMJS = "phantomjs";

Expand Down
27 changes: 27 additions & 0 deletions test/java/src/test/java/ghostdriver/BaseTestWithServer.java
@@ -1,3 +1,30 @@
/*
This file is part of the GhostDriver project from Neustar inc.

Copyright (c) 2012, Ivan De Marino <ivan.de.marino@gmail.com / detronizator@gmail.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package ghostdriver;

import ghostdriver.server.CallbackHttpServer;
Expand Down
27 changes: 27 additions & 0 deletions test/java/src/test/java/ghostdriver/CookieTest.java
@@ -1,3 +1,30 @@
/*
This file is part of the GhostDriver project from Neustar inc.

Copyright (c) 2012, Ivan De Marino <ivan.de.marino@gmail.com / detronizator@gmail.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package ghostdriver;

import ghostdriver.server.EmptyPageHttpRequestCallback;
Expand Down