2

I have a working webdriver javascript test script for my html page that runs using ChromeDriver without needing to start up a selenium standalone server:

test.js

'use strict';

var path = require('path');
var webdriver = require('selenium-webdriver');
var chrome = require('selenium-webdriver/chrome');

var options = new chrome.Options();
var logging_prefs = new webdriver.logging.Preferences();
logging_prefs.setLevel(webdriver.logging.Type.BROWSER, webdriver.logging.Level.ALL);
options.setLoggingPrefs(logging_prefs);

var driver = new webdriver.Builder().withCapabilities(options.toCapabilities()).build();

driver.get('file://' + path.resolve('./index.html'));
// Do some testing
driver.quit();

I want to port this test to use theintern.io, but I'd prefer not to have to run a standalone selenium server. Is this possible?

[Edit: Add info on the error and theintern config]

I see the error [POST http://localhost:4444/wd/hub/session] connect ECONNREFUSED which I guess is because I don't have the standalone server running.

My theintern config looks like this:

define({
  environments: [
    { browserName: 'chrome' }
  ],

  // Name of the tunnel class to use for WebDriver tests
  tunnel: 'NullTunnel',

  // Non-functional test suite(s) to run in each browser
  suites: [ /* 'myPackage/tests/foo', 'myPackage/tests/bar' */ ],

  // Functional test suite(s) to run in each browser once non-functional tests are completed
  functionalSuites: [ 'tests/functional/index' ],

  // A regular expression matching URLs to files that should not be included in code coverage analysis
  excludeInstrumentation: /^(?:tests|node_modules)\//
});

My theintern test looks like this:

define([
  'intern!object',
  'intern/chai!assert',
  'require'
], function (registerSuite, assert, require) {
  registerSuite({
    name: 'index',

    'first test': function () {
      return this.remote
        .get(require.toUrl('index.html'))
        ... //more test logic
    }
  });
});
robd
  • 9,646
  • 5
  • 40
  • 59
  • So, to clarify, are you already running ChromeDriver, or is your existing test environment spinning up a ChromeDriver server when you run tests? – Dylan Lacey Jan 31 '15 at 18:10
  • I'm not starting a separate server or anything like that. I've installed the latest ChromeDriver using brew, and I run the test.js script using `node test.js` and it just seems to work. As I understand it, I'm directly connecting to ChromeDriver and not going via a selenium server java process (I used [these](https://code.google.com/p/selenium/wiki/WebDriverJs#Getting_Started) instructions). – robd Jan 31 '15 at 18:37

1 Answers1

1

Intern speaks the standard WebDriver protocol so can be used with any server that implements the specification, not just Selenium. In this case if you are trying to connect to ChromeDriver just make sure that it is running first (chromedriver --port=4444 --url-base=wd/hub) and then run intern-runner config=mid/of/config and you should be good to go with the configuration that you currently have.

C Snover
  • 17,908
  • 5
  • 29
  • 39
  • Ah OK I see - that's very useful - thanks. Do you know if a ChromeDriver http server is started under the hood in my original script when I call `new webdriver.Builder()...build()`? I imagine not, and that it is eliminating http completely and just calling into the ChromeDriver API directly. Does theintern support something like that, or can it only drive the webdriver API via HTTP? – robd Feb 01 '15 at 13:50
  • The [WebDriver specification](https://w3c.github.io/webdriver/webdriver-spec.html) mandates the use of HTTP for communication (section 2.1). You could write a [Dig Dug](https://github.com/theintern/digdug) “tunnel” that starts local processes. If you do, please submit a pull request! :) – C Snover Feb 02 '15 at 06:00
  • Thanks for the link. For the moment I'm using Protractor with the "directConnect: true" option, which eliminates the need to run a separate http server. If I get a chance I may look at seeing what would be involved in adding a directConnect mode to theintern, but for the moment, Protractor seems to do the job. – robd Feb 03 '15 at 17:56