量角器 - 无效的 SSL 证书

Protractor - invalid SSL certificate

我们有一个应用程序,本地测试显示无效的 SSL 证书警告。通常我只会添加一个例外并继续它。然而,量角器是否可以忽略这一点?

我在 selenium 中看到了一些可以忽略 SSL 但似乎在量角器中找不到的功能。

尝试

webdriver-manager update --ignore_ssl

或为 firefox

配置 protractor.conf.js
var makeFirefoxProfile = function(preferenceMap) {
    var profile = new FirefoxProfile();
    for (var key in preferenceMap) {
        profile.setPreference(key, preferenceMap[key]);
    }
    return q.resolve({
        browserName: 'firefox',
        marionette: true,
        firefox_profile: profile
    });
};

exports.config = {
    seleniumAddress: 'http://localhost:4444/wd/hub',
    framework: 'jasmine2',
    getMultiCapabilities: function() {
        return q.all([
            makeFirefoxProfile(
                {
                    'browser.acceptSslCerts': true
                }
            )
        ]);
    },
}

这对我有用,(在 conf 文件中):

capabilities: {
    browserName : 'firefox',
    marionette : true,
    acceptInsecureCerts : true
}

希望对您有所帮助。

capabilities: {
    browserName: 'chrome',
    chromeOptions: {
        // for ci test
        args: ['--headless', 'no-sandbox', "--disable-browser-side-navigation",
            "--allow-insecure-localhost"
            /// for https sites: ignore ssl on https://localhost...
            /// further args please see https://peter.sh/experiments/chromium-command-line-switches/
        ]
    }
}

maybe you want to take some screenshots to test where the error occurs

import fs from 'fs';

function writeScreenShot(data, filename) {
    const stream = fs.createWriteStream(filename);
    stream.write(new Buffer(data, 'base64'));
    stream.end();
}

export function takeScreenshot(browser, path){
    browser.takeScreenshot().then((png) => {
        writeScreenShot(png, path);
    });
}

但长期 运行,我建议迁移到 cypress (https://www.cypress.io/),因为它有许多其他开箱即用的功能:视频、屏幕截图等。相信我,这是值得的 ;)