I'm trying to write a test for my site, by logging into it and performing some actions. I've got a script that is SO CLOSE to working but there is one key flaw which i haven't been able to circumvent. See logic below
var phantom = require('phantom');
var rl = require('readline-sync');
var Spooky = require('spooky');
// Go to login page
spooky.start(url);
// Generate an image of the captcha
spooky.then(function () {
this.capture('captcha.png');
});
// Fill in login form
spooky.then([{
captcha: new Captcha()
}, function () {
this.fill('form#login-form', {
'username': 'username',
'password': 'password',
'recaptcha_response_field' : captcha.phrase
});
}]);
spooky.wait(5000, function() {
this.capture('afterlogin.png');
});
spooky.run();
function Captcha() {
return {
phrase: ask("Enter Captcha Phrase: ")
}
}
function ask (msg, options){
return rl.question(msg, options)
}
So, this generates the images fine, fills out the form fine. The problem is with injecting the "new Captcha()" function. If, for example, I didn't need to see an image of the form first, i could put in my username and pass with the ask function, and it would fill it all out. But this seems to evaluate before the spooky promises.
When I run the script, it asks for the phrase first, then after i enter it it generates the image. I need to generate the image BEFORE asking the phrase. If anybody could shed some light on my issue that would be great! Let me know if you need any more info.