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

时间:2015-08-31 23:22:08

标签: javascript automation phantomjs casperjs

我使用test命令运行我的大多数CasperJS测试 --ssl-protocol=any--ignore-ssl-errors=true标记。

如果他们在测试环境中,有没有办法可以将这两个标志添加到测试中?我知道如果您使用像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();
    });

});

...我用casperjs --ssl-protocol=any --ignore-ssl-errors=true test login.js(一口)

运行 我注定了吗?

1 个答案:

答案 0 :(得分:1)

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

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

示例config.json:

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

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