Created
October 8, 2012 16:28
-
-
Save kyo-ago/3853421 to your computer and use it in GitHub Desktop.
ChromeDriver経由でSeleniumIDEの内容を実行するJSサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (d,s) {s=d.createElement('script');s.src = 'http://code.jquery.com/jquery-latest.js';d.body.appendChild(s);return s})(document).addEventListener('load', function () {var interval = setInterval(function () { | |
if (!jQuery) { | |
return; | |
} | |
clearInterval(interval); | |
load(); | |
}); | |
}, false); | |
function load () { | |
var sessionId, test_doc; | |
$.when($.ajax({ | |
'processData' : false, | |
'data' : '{"desiredCapabilities" : {}}', | |
'type' : 'POST', | |
'url' : '/session', | |
'dataType' : 'json' | |
}), | |
create_document() | |
).done(function (result, doc) { | |
sessionId = result[0].sessionId | |
test_doc = doc; | |
var href = test_doc.querySelector('link[rel="selenium.base"]').href; | |
return $.ajax({ | |
'processData' : false, | |
'data' : '{"url" : "'+href+'"}', | |
'type' : 'POST', | |
'url' : '/session/'+sessionId+'/url' | |
}); | |
}).done(function () { | |
console.log(arguments); | |
$.ajax({ | |
'type' : 'DELETE', | |
'url' : '/session/'+sessionId+'/window' | |
}); | |
}); | |
function create_document () { | |
var defer = $.Deferred(); | |
var input = document.createElement('input'); | |
input.type = 'file'; | |
input.addEventListener('change', function (evt) { | |
var file = evt.target.files[0]; | |
var render = new FileReader(); | |
render.addEventListener('load', function (evt) { | |
var doc = document.implementation.createHTMLDocument(''); | |
var range=doc.createRange(); | |
range.selectNodeContents(doc.documentElement); | |
range.deleteContents(); | |
doc.documentElement.appendChild(range.createContextualFragment(evt.target.result)); | |
defer.resolve(doc); | |
}, false); | |
render.readAsText(file, 'UTF-8'); | |
}, false); | |
document.body.appendChild(input); | |
return defer.promise(); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment