Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor : WebDriverError : could not initialize sun.security.ssl.SSLContextImpl$TLSContext

I am just new to protractor, and I am blocked when starting the tutorial. I can't find the real source of the error ...

What I did :

  1. install protractor (npm install -g protractor)
  2. update and run webdriver-manager
  3. copy/paste example files from protractor tutorial
  4. run 'protractor conf.js'

What I get :

[11:35:46] I/hosted - Using the selenium server at     http://localhost:4444/wd/hub
[11:35:46] I/launcher - Running 1 instances of WebDriver
[11:35:46] E/launcher - Could not initialize class sun.security.ssl.SSLContextImpl$TLSContext
[11:35:46] E/launcher - WebDriverError: Could not initialize class sun.security.ssl.SSLContextImpl$TLSContext
    at WebDriverError (/home/bmargogne/.nvm/versions/node/v6.8.1/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/error.js:27:5)
    at Object.checkLegacyResponse (/home/bmargogne/.nvm/versions/node/v6.8.1/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/error.js:639:15)
    at parseHttpResponse (/home/bmargogne/.nvm/versions/node/v6.8.1/lib/node_modules/protractor/node_modules/selenium-webdriver/http/index.js:538:13)
    at client_.send.then.response (/home/bmargogne/.nvm/versions/node/v6.8.1/lib/node_modules/protractor/node_modules/selenium-webdriver/http/index.js:472:11)
    at ManagedPromise.invokeCallback_ (/home/bmargogne/.nvm/versions/node/v6.8.1/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1379:14)
    at TaskQueue.execute_ (/home/bmargogne/.nvm/versions/node/v6.8.1/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2913:14)
    at TaskQueue.executeNext_ (/home/bmargogne/.nvm/versions/node/v6.8.1/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2896:21)
    at asyncRun (/home/bmargogne/.nvm/versions/node/v6.8.1/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2820:25)
    at /home/bmargogne/.nvm/versions/node/v6.8.1/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:639:7
    at process._tickCallback (internal/process/next_tick.js:103:7)
From: Task: WebDriver.createSession()
    at Function.createSession (/home/bmargogne/.nvm/versions/node/v6.8.1/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:329:24)
    at Builder.build (/home/bmargogne/.nvm/versions/node/v6.8.1/lib/node_modules/protractor/node_modules/selenium-webdriver/builder.js:458:24)
    at Hosted.DriverProvider.getNewDriver (/home/bmargogne/.nvm/versions/node/v6.8.1/lib/node_modules/protractor/built/driverProviders/driverProvider.js:37:33)
    at Runner.createBrowser (/home/bmargogne/.nvm/versions/node/v6.8.1/lib/node_modules/protractor/built/runner.js:198:43)
    at /home/bmargogne/.nvm/versions/node/v6.8.1/lib/node_modules/protractor/built/runner.js:277:30
    at _fulfilled (/home/bmargogne/.nvm/versions/node/v6.8.1/lib/node_modules/protractor/node_modules/q/q.js:834:54)
    at self.promiseDispatch.done (/home/bmargogne/.nvm/versions/node/v6.8.1/lib/node_modules/protractor/node_modules/q/q.js:863:30)
    at Promise.promise.promiseDispatch (/home/bmargogne/.nvm/versions/node/v6.8.1/lib/node_modules/protractor/node_modules/q/q.js:796:13)
    at /home/bmargogne/.nvm/versions/node/v6.8.1/lib/node_modules/protractor/node_modules/q/q.js:556:49
    at runSingle (/home/bmargogne/.nvm/versions/node/v6.8.1/lib/node_modules/protractor/node_modules/q/q.js:137:13)
[11:35:46] E/launcher - Process exited with error code 199

Notes

  1. Protractor : v4.0.14
  2. Java : openjdk 9-Ubuntu 9b134 (?)
  3. System : Ubuntu 16.04
  4. NodeJS : v6.8.1
  5. I get the same output by using "capabilities.browserName:'firefox'" in conf.js

Any help would be welcome !

like image 641
Bertrand Engogram Avatar asked Jan 04 '17 10:01

Bertrand Engogram


1 Answers

Well, I will try to take a guess, as I have no experience in this area.
The problem seems to be the following:

Could not initialize class sun.security.ssl.SSLContextImpl$TLSContext

at least according to the log that you show, and assuming all the setup for Protractor has been done correctly.

This is "stuff" coming from JDK code.
Let's see why Java is needed in some parts first, as it will help us to understand a bit few things.
Right at the first line of your log it's clear that you're using a selenium server (https://github.com/angular/protractor/blob/master/docs/server-setup.md).
As can be seen by reading the link above, the selenium server does need JDK so we found one Java "entry point".

The selenium server is started using the webdriver-manager, so in the code for the webdriver-manager there must be some call to start java. Let's see where it is.
Looking at the source here
https://github.com/angular/webdriver-manager/blob/70614a23e289088c852f5c0162a947488ffc77e0/lib/cmds/start.ts

we can see that java will be started here

let seleniumProcess = spawn('java', args, stdio);

and these args are defined in the following way:

let args: string[] = [];  

and this is filled with called like this for example:

  if (osType === 'Linux') {
    // selenium server may take a long time to start because /dev/random is BLOCKING if there is not
    // enough entropy the solution is to use /dev/urandom, which is NON-BLOCKING (use /dev/./urandom
    // because of a java bug)
    // https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/1301
    // https://bugs.openjdk.java.net/browse/JDK-6202721
    args.push('-Djava.security.egd=file:///dev/./urandom');  

I noticed that you mention you use OpenJDK 9, which is not yet probably trustable right now as it is still not released for general availability:
http://www.java9countdown.xyz/
http://openjdk.java.net/projects/jdk9/

My first suggestion: Use a production stable Java version, like 8 for the moment, which appears to be the default in my Ubuntu 16.04 machine.

To get a good feeling about where the error you see might originate, I suggest reading the following SO post:
SSLContext initialization and the first answer in there, which I found very instructive anyway. You can also read here: https://www.java.com/en/configure_crypto.html.

Looking to that, I would suggest that one has to start java with the following system property jdk.tls.client.protocols on (although the defaults should be ok...). One way to do it would be to add the following line

args.push('-Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"');

for example right before the call to let seleniumProcess = spawn('java', args, stdio); in the file mentioned above.

What else you could try
You could check whether you can avoid this error by connecting your script directly to the browser, without selenium server intervention. This is doable if you run locally for the moment and should be faster as you avoid one hop. In the case that your browser is located remotely (not your case for the moment...) you NEED to use selenium server.

As stated in the selenium server setup page I linked at the beginning, this possibility of avoiding using it is indeed listed. The key section in the selenium server setup documentation that mention this is the following

Connecting Directly to Browser Drivers

Protractor can test directly against Chrome and Firefox without using a Selenium Server. To use this, in your config file set directConnect: true.

directConnect: true - Your test script communicates directly Chrome Driver or Firefox Driver, bypassing any Selenium Server. If this is true, settings for seleniumAddress and seleniumServerJar will be ignored. If you attempt to use a browser other than Chrome or Firefox an error will be thrown. The advantage of directly connecting to browser drivers is that your test scripts may start up and run faster.

So, taking the conf.js you use from the tutorial, you would add a line defining this extra configuration, i.e.

// conf.js
exports.config = {
  directConnect: true
  framework: 'jasmine',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['spec.js']
}

Some people have reported that using this option in combination with the Chrome browser instead of Firefox has resolved some issues which anyway do not seem strictly related to yours: https://github.com/angular/angular-seed/issues/254

What else? Some people have also reported that updating the chromedriver to a specific version have solved some issues in the webdriver when using chrome, e.g.: https://github.com/angular/protractor/issues/3640
https://github.com/angular/webdriver-manager/issues/102
So one suggestion would be to try using Chrome in the same running conditions and see what you get. It might run without problems.

Please, keep in mind that all the software components rely in some cases to specific versions of the subcomponents (specific browser versions, etc.) so check also that those requirements are met. These are listed in the relevant pages for the software you use: protractor, webdriver-manager, etc.

Again, I stress the fact that I'm neither a developer in these languages or frameworks, so my view of the system is not the best and the most informed one. I also assume the setup up to the running point has been done correctly.

like image 62
fedepad Avatar answered Sep 18 '22 17:09

fedepad