【问题标题】:How to set CasperJS page options from within a test in test environment?如何在测试环境的测试中设置 CasperJS 页面选项?
【发布时间】:2015-09-01 08:10:22
【问题描述】:

我使用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();
    });

});

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

我注定要失败吗?

【问题讨论】:

  • 您确实应该将 casper.start() 移动到 casper.test.begin() 内,否则当您添加另一个 casper.test.begin() 块时,您将遇到未定义的行为。

标签: javascript automation phantomjs casperjs


【解决方案1】:

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

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

示例 config.json:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-09
    • 1970-01-01
    • 2010-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多