tronjavolta
tronjavolta

Reputation: 757

How to set CasperJS page options from within a test in test environment?

I run most of my CasperJS tests with the test command as well as the --ssl-protocol=anyand --ignore-ssl-errors=true flags.

Is there a way that I can add those 2 flags to the tests themselves if they're in the test environment? I know you can set page options if you use the casper module like var casper = require('casper').create({, but that's not how my tests are set up.

I also know you can do stuff like

casper.options.verbose = true;
casper.options.logLevel = "debug";

...but casper.options.ignoreSslProtocol=true doesn't seem to work.

here's part of my login test --

var config = require('../../config'),
    x = require('casper').selectXPath;

casper.test.comment('basic login test!');
casper.start(config.base_url);
casper.test.begin('test basic login functionality', function (test) {

    casper.then(function() {
       this.click('.js-flip_box');
       test.info('logging in');
       this.fill('#login_form', {
            'email': config.email,
            'password': config.password
        }, true);
    });

    casper.then(function () {
        test.assertVisible ('.home_bar', 'nav bar visible');
    });

    casper.run(function() {
        test.done();
    });

});

...which I run with casperjs --ssl-protocol=any --ignore-ssl-errors=true test login.js (a mouthful)

am I doomed?

Upvotes: 1

Views: 838

Answers (1)

Artjom B.
Artjom B.

Reputation: 61952

You can't, because PhantomJS doesn't provide such an option, but it should be really easy to add it to the code base as a pull request.

If you don't want to edit the source code and compile it yourself, then you can use the next best thing which is the --config=config.json option where you can define such options instead of defining them on the commandline directly. See here and here for more information.

Example config.json:

{
    "ignoreSslErrors": true,
    "sslProtocol": "any"
}

See here for a full list of options.

Upvotes: 1

Related Questions