Unable to get selenium standalone working locally

1,792 views
Skip to first unread message

James Spence

unread,
Jun 27, 2017, 2:33:54 PM6/27/17
to NightwatchJs
Hello all,

I am having trouble getting nightwatch and selenium server working together. Here is my configuration:

require('../getEnv');
const directory = __dirname;

module.exports = {
   src_folders: [`${directory}/../../specs`],
   custom_commands_path: `${directory}/../../commands`,
   output_folder: `${directory}/../../reports`,
   selenium: {
      host: '127.0.0.1',
      start_process: true,
      server_path: `${directory}/../selenium-server-standalone-3.4.0.jar`,
      port: 4444,
      cli_args: {
         'webdriver.chrome.driver' : `${directory}/../chromedriver`,
         'webdriver.gecko.driver' : `${directory}/..geckodriver`
      }
   },
   test_settings: {
      default : {
         selenium_host: '127.0.0.1',
         selenium_port: 4444,
         launch_url: getEnv('baseUrl'),
         default_path_prefix : '',
         silent: true,
         screenshots: {
            enabled: getEnv('screenshots', false),
            path: `${directory}/../../screenshots`
         },
         desiredCapabilities: {
            browserName: 'chrome',
            javascriptEnabled: true,
            binary: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
         },
         globals: {
            before: done => {
               let chai = require('chai');
               global.expect = chai.expect;
               chai.Should();
               done();
            },
            isBrowserstack: false
         }
      }
   }
};


From what I can see in the docs, I have configured selenium correctly: I have defined the jar path to my selenium standalone, I have defined my path to chromedriver, and my desiredCapabilities are set to use chrome. I even added the additional `binary` setting in order to make sure it could find Chrome correctly.

However, when running this test with the `verbose` flag, I get the following output:

Starting selenium server... started - PID:  5117

[Ttbx / Landing / 02 Login] Test Suite
==========================================

Running:  Access login
INFO Request: POST /session
 - data:  {"desiredCapabilities":{"browserName":"chrome","javascriptEnabled":true,"acceptSslCerts":true,"platform":"ANY","binary":"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome","name":"Ttbx / Landing / 02 Login"}}
 - headers:  {"Content-Type":"application/json; charset=utf-8","Content-Length":219}
Error processing the server response:
 <!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <link rel="stylesheet" type="text/css" href="/assets/displayhelpservlet.css" media="all"/>
  <link href="/assets/favicon.ico" rel="icon" type="image/x-icon" />
  <script src="/assets/jquery-3.1.1.min.js" type="text/javascript"></script>
  <script src="/assets/displayhelpservlet.js" type="text/javascript"></script>
  <script type="text/javascript">
    var json = Object.freeze('{"version":"3.4.0","type":"Standalone","consoleLink":"/wd/hub"}');
  </script>
</head>
<body>

<div id="content">
  <div id="help-heading">
    <h1><span id="logo"></span></h1>
    <h2>Selenium <span class="se-type"></span>&nbsp;v.<span class="se-version"></span></h2>
  </div>

  <div id="content-body">
    <p>
      Whoops! The URL specified routes to this help page.
    </p>
    <p>
      For more information about Selenium <span class="se-type"></span> please see the
      <a class="se-docs">docs</a> and/or visit the <a class="se-wiki">wiki</a>.
      <span id="console-item">
        Or perhaps you are looking for the Selenium <span class="se-type"></span> <a class="se-console">console</a>.
      </span>
    </p>
    <p>
      Happy Testing!
    </p>
  </div>

  <div>
    <footer id="help-footer">
      Selenium is made possible through the efforts of our open source community, contributions from
      these <a href="https://github.com/SeleniumHQ/selenium/blob/master/AUTHORS">people</a>, and our
      <a href="http://www.seleniumhq.org/sponsors/">sponsors</a>.
   </footer>
  </div>
 </div>

</body>
</html>
INFO Response 200 POST /session (120ms) { value: -1, error: 'Unexpected token < in JSON at position 0' }

Error retrieving a new session from the selenium server

Connection refused! Is selenium server started?
{ value: -1, error: 'Unexpected token < in JSON at position 0' }

It appears that selenium is starting up but not running the webdriver properly. I should mention, if I run the chromedriver separately, and change my selenium port to 9515, the tests will run properly. However, I believe that is because my tests aren't running through selenium anymore, so it's not really "working" the way I need it to.

Anybody have any ideas of what I might be doing wrong? Any help to point me in the right direction would be much appreciated!!

James Spence

unread,
Jun 27, 2017, 2:46:58 PM6/27/17
to NightwatchJs
The following is my selenium-debug.log as well:
13:44:46.130 INFO - Selenium build info: version: '3.4.0', revision: 'unknown'
13:44:46.130 INFO - Launching a standalone Selenium Server
2017-06-27 13:44:46.147:INFO::main: Logging initialized @220ms to org.seleniumhq.jetty9.util.log.StdErrLog
13:44:46.193 INFO - Driver provider org.openqa.selenium.ie.InternetExplorerDriver registration is skipped:
 registration capabilities Capabilities [{ensureCleanSession=true, browserName=internet explorer, version=, platform=WINDOWS}] does not match the current platform MAC
13:44:46.194 INFO - Driver provider org.openqa.selenium.edge.EdgeDriver registration is skipped:
 registration capabilities Capabilities [{browserName=MicrosoftEdge, version=, platform=WINDOWS}] does not match the current platform MAC
13:44:46.194 INFO - Driver class not found: com.opera.core.systems.OperaDriver
13:44:46.194 INFO - Driver provider com.opera.core.systems.OperaDriver registration is skipped:
Unable to create new instances on this machine.
13:44:46.194 INFO - Driver class not found: com.opera.core.systems.OperaDriver
13:44:46.194 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
2017-06-27 13:44:46.229:INFO:osjs.Server:main: jetty-9.4.3.v20170317
2017-06-27 13:44:46.260:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler@d8355a8{/,null,AVAILABLE}
2017-06-27 13:44:46.294:INFO:osjs.AbstractConnector:main: Started ServerConnector@146ba0ac{HTTP/1.1,[http/1.1]}{0.0.0.0:4444}
2017-06-27 13:44:46.294:INFO:osjs.Server:main: Started @368ms
13:44:46.294 INFO - Selenium Server is up and running


James Spence

unread,
Jun 27, 2017, 3:09:41 PM6/27/17
to NightwatchJs
I figured it out! Of course it was some dumb configuration. New configuration posted below:
require('../getEnv');
const directory = __dirname;
const Util = require(`${directory}/../../util.js`);

module.exports = {
src_folders: [`${directory}/../../specs`],
custom_commands_path: `${directory}/../../commands`,
output_folder: `${directory}/../../reports`,
selenium: {
start_process: true,
server_path: `${Util.getBinDirectory()}/selenium-server-standalone-3.4.0.jar`,
port: 4444,
cli_args: {
'webdriver.chrome.driver' : `${Util.getBinDirectory()}/chromedriver`,
'webdriver.gecko.driver' : `${Util.getBinDirectory()}/geckodriver`
}
},
test_settings: {
default : {
launch_url: getEnv('baseUrl'),
selenium_host: 'localhost',
selenium_port: 4444,
silent: true,
screenshots: {
enabled: getEnv('screenshots', false),
path: Util.getScreenshotsDirectory()
},
desiredCapabilities: {
javascriptEnabled: true,
browserName: 'chrome'
// browserName: 'firefox',
// marionette: true
},
globals: {
before: done => {
let chai = require('chai');
global.expect = chai.expect;
chai.Should();
done();
},
isBrowserstack: false
}
}
}
};

(sorry for weird tabbing)

Basically had a few issues in my configuration, but the main issue was my default_path_prefix setting. That setting was causing my requests to selenium to not go to the right URL, which was causing the error page to appear instead.

Hopefully this helps somebody else find the right direction!
Reply all
Reply to author
Forward
0 new messages