Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor - invalid SSL certificate

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.

like image 251
Joseph Avatar asked Dec 12 '17 10:12

Joseph


People also ask

How to get SSL certificate in Selenium?

EdgeOptions ssl = new EdgeOptions(); -- Object of EdgeOptions is created. ssl. setAcceptInsecureCerts(true); -- Insecure certificates are accepted by using Boolean true as an argument. WebDriver driver = new EdgeDriver(ssl); -- The options now pass to the WebDriver instance to start with the desired settings.

How to handle SSL certificates in Selenium WebDriver in chrome c#?

setProperty("webdriver. ie. driver","IEDriverServer.exe"); WebDriver driver = new InternetExplorerDriver(capabilities); The above code will help to handle SSL certificate error in IE.

What is SSL certificate in Selenium?

New Selenium IDE A SSL is the standardized protocol used to create a connection between the browser and server. The information exchanged via a SSL certificate is encrypted and it verifies if the information is sent to the correct server. It authenticates a website and provides protection from hacking.

What is SSL in angular?

To serve an Angular app locally with SSL we have to use the options --ssl , --ssl-key and --ssl-cert together with ng serve . Hence, after generating the local certificate authority and ssl certificate we have to set the sslKey and sslCert environment variables to the path of the certificate and key files.


2 Answers

This works for me, (in conf file):

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

Hope that helps.

like image 86
M. Hudson Avatar answered Oct 22 '22 15:10

M. Hudson


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 ;)

like image 45
Yuqiu G. Avatar answered Oct 22 '22 15:10

Yuqiu G.