0

I've been looking for some kind of tutorial or example on how to do this, but either I'm not understanding that the solution is right under my nose, or no one has really put this out there.

What I'm trying to do is use casperjs to automate a process where I create an account on a website. I will be providing a few different user names, and then I want to output a file at the end with the username that was used for registration along with the password.

If I don't need to use PHP to do this, that's fine as well. I'm just very confused. Thanks for the help.

mitchellwright
  • 171
  • 2
  • 11
  • Something I don't get, if you "create an account on a website", you'll have to choose a username and a password… so why do you need to get them back? If you just want some kind of success confirmation, just return some status code. – NiKo May 28 '12 at 12:21

1 Answers1

1

Not sure to fully understand your question (see my comment above it), but basically:

var casper = require('casper').create();
var username = 'foo';
var password = 'bar';

casper.start('http://service.domain.tld/register.html', function() {
    this.fill('form[action="/register"]', {
        'username': username,
        'password': password
    }, true);
});

casper.then(function() {
    if (/Your account was created/.test(this.fetchText('.success'))) {
        this.echo('Created account: ' + username + '/' + password);
    } else {
        this.echo('Failed creating account for ' + username);
    }
});

casper.run();

You could also return some JSON serialization of any supplementary information to ease their consumption by a PHP script.

NiKo
  • 11,215
  • 6
  • 46
  • 56
  • The reason is because I would potentially be creating multiple accounts on the same site. The password was going to be generated. I have since moved on to a different method. I appreciate you taking the time to answer the question though. – mitchellwright Jun 06 '12 at 01:49