Given these Node dependencies:
{
"chromedriver": "^2.24.1",
"cucumber": "^1.3.0",
"geckodriver": "^1.1.2",
"phantomjs-prebuilt": "^2.1.12",
"selenium-webdriver": "^3.0.0-beta-2"
}
I would like PhantomJS and Firefox to ignore SSL certificates. Here is how my browser.js looks:
require('geckodriver');
// main browser object
var browserHandle;
// load selenium webdriver and some rules
var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
// load phantomjs into webdriver capabilities
var phantomjs_exe = require('phantomjs-prebuilt').path;
var customPhantom = webdriver.Capabilities.phantomjs();
customPhantom.set("phantomjs.binary.path", phantomjs_exe);
webdriver.Builder()
//.forBrowser('firefox')
//.forBrowser('phantomjs')
.withCapabilities(customPhantom)
.build();
Any suggestions with --ignore-ssl-errors=yes
? How can I implement it in the code? I want to use only JavaScript, rather than Java.
This is only for Javascript / Node.js Selenium Webdriverjs case, only MacOS solution.
Firefox case:
a. Setup a new Profile using the Profile Manager for Firefox.
/Applications/Firefox.app/Contents/MacOS/firefox-bin -P
(-profilemanager
, this works as well)b. Add the ffprofile File
<profilePath>
"} to the file, where <profilePath>
is the Path you copied in a.
c. Add your local system to the Profile
/Applications/Firefox.app/Contents/MacOS/firefox-bin -P
https://...
. You should see a Page telling you there is a Problem with the certificated. Add this into your browser.js or where you call a browser programmatically:
var webdriver = require('selenium-webdriver'),
firefox = require('selenium-webdriver/firefox'),
var ffProfileFile = require('./ffprofile');
var ffProfile = new firefox.Profile(ffProfileFile['ffprofile']);
var ffOptions = new firefox.Options().setProfile(ffProfile);
return browserHandle = new firefox.Driver(ffOptions);
Phantomjs case ( I have got two solutions here, pick up the one which is better for you):
solution 1:
var webdriver = require('selenium-webdriver'),
phantom = require('phantomjs-prebuilt');
var capabilities = webdriver.Capabilities.phantomjs();
capabilities.set(webdriver.Capability.ACCEPT_SSL_CERTS, true);
capabilities.set(webdriver.Capability.SECURE_SSL, false);
capabilities.set("phantomjs.cli.args",
["--web-security=no",
"--ssl-protocol=any",
"--ignore-ssl-errors=yes"]
);
return browserHandle = new webdriver
.Builder()
.withCapabilities(capabilities)
.build();
solution 2:
var webdriver = require('selenium-webdriver'),
phantom = require('phantomjs-prebuilt');
var capabilities = {
'browserName' : 'phantomjs',
'phantomjs.cli.args': ['--ignore-ssl-errors=true',
'--ssl-protocol=any', '--web-security=false']
}
return browserHandle = new webdriver
.Builder()
.withCapabilities(capabilities)
.build();
for this one the 'phantomjs.cli.args': ['--ignore-ssl-errors=true']
did the job for me.
Hope it will be useful for you.
For Firefox, you can use the following code:
var driver = new webdriver.Builder().withCapabilities(Capabilities.firefox()
.set("acceptInsecureCerts", true)).build();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With