Created
June 21, 2013 04:13
-
-
Save anonymous/5828718 to your computer and use it in GitHub Desktop.
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
var page = require('webpage').create(), | |
url = 'http://localhost:1134/test_client.html'; | |
//Visit the specified url | |
page.open(url, function (status) { | |
check(step1); | |
}); | |
//Fill in the command and click 'Go!' | |
function step1(){ | |
page.evaluate(function() { | |
document.getElementsByName('command')[0].value = 'whoami'; | |
document.getElementById('execute').click(); | |
}); | |
check(step2); | |
} | |
//Log the output | |
function step2(){ | |
page.evaluate(function() { | |
console.log(document.getElementById('output').innerHTML); | |
}); | |
phantom.exit(); | |
} | |
//Check and wait for the 'Go!' button to be enabled | |
function check(step){ | |
state = page.evaluate(function() { | |
return document.getElementById('execute').getAttribute('aria-disabled') == "false" && document.getElementById('output').innerHTML !=''; | |
}); | |
if(!state) | |
setTimeout(function(){ | |
check(step); | |
},50); | |
else | |
step(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment