如何在测试环境中的测试中设置 CasperJS 页面选项?

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

我 运行 我的大部分 CasperJS 测试都使用 test 命令以及 --ssl-protocol=any--ignore-ssl-errors=true 标志。

如果它们在测试环境中,是否有办法将这 2 个标志添加到测试本身?我知道如果你使用像 var casper = require('casper').create({ 这样的 casper 模块,你可以设置页面选项,但这不是我的测试设置方式。

我也知道你可以做

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

...但是 casper.options.ignoreSslProtocol=true 似乎不起作用。

这是我的登录测试的一部分 --

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 运行 with casperjs --ssl-protocol=any --ignore-ssl-errors=true test login.js (a mouthful)

我注定要失败吗?

你不能,因为 PhantomJS 不提供这样的选项,但将它作为拉取请求添加到代码库应该非常容易。

如果您不想编辑源代码并自己编译,那么您可以使用下一个最好的选择,即 --config=config.json 选项,您可以在其中定义此类选项,而不是在直接命令行。有关详细信息,请参阅 here and here

示例config.json:

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

有关选项的完整列表,请参阅 here