簡體   English   中英

如何在測試環境中的測試中設置CasperJS頁面選項?

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

我使用test命令以及--ssl-protocol=any--ignore-ssl-errors=true標志運行大多數CasperJS測試。

如果它們在測試環境中,是否可以將這兩個標志添加到測試本身中? 我知道,如果您使用casper模塊(如var casper = require('casper').create({ ,則可以設置頁面選項,但這不是我的測試設置方式。

我也知道你可以做類似的事情

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運行casperjs --ssl-protocol=any --ignore-ssl-errors=true test login.js (滿口)

我注定了嗎?

您不能這樣做,因為PhantomJS沒有提供這樣的選項,但是將它作為請求請求添加到代碼庫中應該真的很容易。

如果您不想編輯源代碼並自己進行編譯,則可以使用下一個最好的方法--config=config.json選項,您可以在其中定義這樣的選項,而不是直接在命令行上定義它們。 有關更多信息,請參見此處此處

示例config.json:

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

有關完整的選項列表,請參見此處

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM