Skip to content

Instantly share code, notes, and snippets.

@jaredhirsch
Forked from lloyd/real_repro.js
Created November 16, 2012 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredhirsch/4082586 to your computer and use it in GitHub Desktop.
Save jaredhirsch/4082586 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var webdriver = require('wd');
browser = webdriver.remote();
browser.on('status', function(info){
console.log('\x1b[36m%s\x1b[0m', info);
});
browser.on('command', function(meth, path){
console.log(' > \x1b[33m%s\x1b[0m: %s', meth, path);
});
function check(err) {
if (err) {
console.log("FATAL ERROR:", err);
process.exit(1);
}
}
browser.init({}, function() {
browser.setImplicitWaitTimeout(5000, function(err) {
check(err);
browser.get("http://people.mozilla.org/~lhilaiel/hang/", function(err) {
check(err);
// 1: open a dialog
browser.elementById("theButton", function(err, elem) {
check(err);
browser.clickElement(elem, function(err) {
check(err);
browser.window("mypopup", function(err) {
check(err);
// 2: interact with it
browser.elementById("#foo", function(err, elem) {
check(err);
// 3. window closes itself WHILE WE'RE LOOKING FOR AN ELEMENT WITH EXPLICIT WAIT SET
// 4. try to find an element in the dialog
browser.elementById("foo", console.log);
});
});
});
});
});
});
});
/*
translated into json wire protocol: use curl to repro this manually at command line.
make the implicit wait really, really long so we can cut and paste json commands in time.
POST /session
POST /session/:sessionId/timeouts/async_script {"ms":10000}
POST /session/:sessionId/url {"url":"http://people.mozilla.org/~lhilaiel/hang/"}
// 1: open a dialog
POST /session/:sessionId/element {"using":"id", "value":"theButton"}
POST /session/:sessionId/element/:id/click
POST /session/:sessionId/window {"name":"mypopup"}
// 2: interact with it
POST /session/:sessionId/element {"using":"id", "value":"foo"}
// 3. window closes itself WHILE WE'RE LOOKING FOR AN ELEMENT WITH EXPLICIT WAIT SET
// 4. try to find an element in the dialog
POST /session/:sessionId/element {"using":"id", "value":"foo"}
*/
/* here's how the commands look as curls in practice:
curl -i -X POST -H "Accept: application/json" -H "Content-type: application/json" --data '{"desiredCapabilities":{"browserName":"firefox"}}' http://localhost:4444/wd/hub/session
// you need to set sessionID to whatever the session ID is in the response
export sessionID=1352745925723
// the rest should be cut-and-paste:
curl -i -X POST -H "Accept: application/json" -H "Content-type: application/json" --data '{"ms":5000}' http://localhost:4444/wd/hub/session/$sessionID/timeouts/async_script
curl -i -X POST -H "Accept: application/json" -H "Content-type: application/json" --data '{"url":"http://people.mozilla.org/~lhilaiel/hang/"}' http://localhost:4444/wd/hub/session/$sessionID/url
curl -i -X POST -H "Accept: application/json" -H "Content-type: application/json" --data '{"using":"id", "value":"theButton"}' http://localhost:4444/wd/hub/session/$sessionID/element
curl -i -X POST -H "Accept: application/json" -H "Content-type: application/json" http://localhost:4444/wd/hub/session/$sessionID/element/0/click
curl -i -X POST -H "Accept: application/json" -H "Content-type: application/json" --data '{"name":"mypopup"}' http://localhost:4444/wd/hub/session/$sessionID/window
curl -i -X POST -H "Accept: application/json" -H "Content-type: application/json" --data '{"using":"id", "value":"foo"}' http://localhost:4444/wd/hub/session/$sessionID/element
curl -i -X POST -H "Accept: application/json" -H "Content-type: application/json" --data '{"using":"id", "value":"foo"}' http://localhost:4444/wd/hub/session/$sessionID/element
*/
@jaredhirsch
Copy link
Author

I'm unable to ever find the #foo element. What I've been doing isntead to try to pin down the moment at which the thing disappears is to look for the html element in the popup, by passing the json '{"using":"tag name", "value":"html"}'. Even if I do this a hundred or so times, i.e. to extreme granularity, I never hit the timeout.

Either I'm not successfully setting the implicit waits at the start of the session, or the bug really isn't in webdriver.

Pretty interesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment