chitcharonko
chitcharonko

Reputation: 331

Declare two or more casper in a single script

What I want to do is to declare two caspers, the two will login to a certain site, one will act as an admin and the other one will act as a typical user. And I want to do it in a single script.

Is it possible to declare two or more casper in a single script? just like this one:

var casper1 = require("casper").create({
    verbose: true,  timeout: null
});

var casper2 = require("casper").create({
    verbose: true,  timeout: null
});

Upvotes: 2

Views: 607

Answers (1)

Artjom B.
Artjom B.

Reputation: 61952

That heavily depends on how the web site handles sessions. If this is done through a unique ID in every request as a request parameter, then this is possible. But as soon as cookies are used, this is not possible.

CasperJS is like a browser. You can have multiple tabs (casper instances), but the session is handled by the browser (PhantomJS). Even if you have multiple casper instances, they operate on the same cookies, so you cannot be logged in as a user and as an admin at the same time. This is because PhantomJS handles the cookies and even if you have multiple casper instances, there is only one phantomjs process underneath.

If the admin interface is on another domain, this multiple casper instances should work. The rule of thumb is, if you can login in a single browser window with multiple tabs, you can do it with multiple casper instances.

So, if they are on the same domain and cookies are used, you would need to do this with different scripts.

Other questions that might interest you:

Upvotes: 5

Related Questions