Question

I have a form inside my page for user that want to register inside the site. After registration I insert user inside database create an activation key and send an email, until user doesn't click the link inside the email with the activation key he can't login inside the site.

With CasperJS I would like to test this functionality, the fillForm is ok but how can I test the activation key?

I have thought to create an input hidden with the activation key (only if is in TEST mode not i production!) and retrieve this value with getFieldValue function.

Is this the right way to do it or there is a better mode to do?

this is my casperjs test to retrieve activation key after registration (I create an input hidden with the activation code):

view            = 'users/registered';

casper
.start(webroot + view)
.then(function() {
    __utils__.log("Retrieving data from input activation-key");
    activationKey = __utils__.getFieldValue('activation-key');
}).then(function() {
    __utils__.log("Activating account with the key " + activationKey);

}).then(function(){
    this.evaluate(function() {
        __utils__.log("Activating account with the key " + activationKey);
        window.location = webroot + 'users/activate/' + activationKey;
    }); 
}).then(function(){
    this.echo(this.getCurrentUrl());
});

casper.run(function() {
    this.echo('test registeration successful!').exit();
});

casper.viewport(page.width, page.height);

casper.test.done();
Était-ce utile?

La solution

I managed to do what i wanted with registration, it could help you : CasperJS- Register on a site and validate the mail sent on Gmail -for both slimer and phantom-

And before i did some scraping with an activation code too, for manual activation (pure JS, no jQuery here, i didn't want to inject JQuery on gmail DOM environment) :

this.waitForSelector("div.msg",function(){
            this.test.assertSelectorHasText("a","Activation message");
            //var code declared in the main scope
            code = this.evaluate(function(){
                var strongs = document.getElementsByTagName('strong')
                    ,i
                    ,l = strongs.length
                    ;
                    for (i = 0; i < l; ++i) {
                        if(strongs[i].textContent === "activation code:"){
                            //get back the code in DOM context -> split to get back only what I want
                            return (strongs[i].parentNode.textContent.split(' ')[2]);
                        }
                    }
            });
            this.echo("code : " + code,"INFO");
        });
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top