Protractor - invalid SSL certificate
Asked Answered
S

3

19

We have an application and testing this locally shows an invalid SSL certificate warning. Normally I would just add an exception and get on with it. However is there anyway for protractor to ignore this?

I've seen some capabilities in selenium where SSL can be ignored but can't seem to find any in protractor.

Stuckey answered 12/12, 2017 at 10:29 Comment(5)
Where did you encounter the issue? On running protractor? what is the exact error? what browser did you use or config file? Please add details on your question as much as possible.Deepfry
I've seen this using both Firefox and Chrome. The error isn't an error, it is a warning within Firefox (I can't upload a screenshot) - but the text is "Your connection is not secure The owner of localhost has configured their website improperly. To protect your information from being stolen, Firefox has not connected to this website." The error code appears to be "localhost:4200 uses an invalid security certificate. The certificate is not trusted because it is self-signed. Error code: SEC_ERROR_UNKNOWN_ISSUER"Stuckey
on Chrome the error is NET::ERR_CERT_AUTHORITY_INVALIDStuckey
can you share the website?Deepfry
@PaulCo - afraid not - it's an internal only development just now (which is why we don't have a proper SSL certificate yet.)Stuckey
M
31

This works for me, (in conf file):

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

Hope that helps.

Mathes answered 13/12, 2017 at 11:50 Comment(1)
I tried with this but still the URL loads with 'not secure' and it asks for username and password.Pith
J
4
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);
    });
}

But for the long run, I would suggest migrating to cypress (https://www.cypress.io/), because it have many other features out of the box: video, screenshot, etc. And believe me, it is worth it ;)

Justifiable answered 6/6, 2018 at 11:24 Comment(0)
A
0

try

webdriver-manager update --ignore_ssl

or configure protractor.conf.js for firefox

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
                }
            )
        ]);
    },
}
Astrix answered 12/12, 2017 at 21:53 Comment(4)
Currently running 12.0.6 - just about to test with the ignore ssl flagStuckey
Ok ignore ssl flag didn't work. Can I ask a slight different question - is there a way to specify a profile for firefox in the config.js file which would allow me to permanently add an exception (it's not the nicest or best way but could get me round this)Stuckey
try something like this. (I updated the answer). Sorry unable to try on my side.Astrix
I'll give this a go later onStuckey

© 2022 - 2024 — McMap. All rights reserved.