var webdriver = require('selenium-webdriver');

function loadAssets (driver) {
  var s = '';
  s += 'var s = document.createElement("script");';
  s += 's.type = "text/javascript";'
  s += 's.src = "http://localhost:7000/core.js";';
  s += 'var domel = document.getElementsByTagName("script")[0];';
  s += 'domel.parentNode.insertBefore(s, domel);';
  driver.get('http://quailpages/forms/simple-form.html');
  driver.executeScript(s);
}

/**
 * creates a webdriver client
 * @param callBack or promise
 */
exports.createClient = function (callBack) {
  var serverConfig = 'http://127.0.0.1:4444/wd/hub';
  var capabilities = {
    silent: true, // maybe output more for tests?
    browserName: 'phantomjs',
    javascriptEnabled: true,
    takesScreenshot: true,
    databaseEnabled: false,
    cssSelectorsEnabled:true,
    webStorageEnabled: true
  };

  var driver = new webdriver
    .Builder()
    .usingServer(serverConfig)
    .withCapabilities(capabilities)
    .build();

  loadAssets(driver);

  if (typeof callBack === 'function') {
    return callBack (driver);
  }
  else if ( typeof callBack === 'object' && typeof callBack.resolve === 'function' ) {
    return callBack.resolve(driver);
  }
  else {
    return driver;
  }
}

var webdriver = require('selenium-webdriver');

function loadAssets (driver) {
  var s = '';
  s += 'var s = document.createElement("script");';
  s += 's.type = "text/javascript";'
  s += 's.src = "http://localhost:7000/core.js";';
  s += 'var domel = document.getElementsByTagName("head")[0];';
  s += 'if (domel) domel.appendChild(s, domel);';
  driver.get('http://quailpages/forms/simple-form.html');
  driver.executeScript(s);
}

/**
 * creates a webdriver client
 * @param callBack or promise
 */
exports.createClient = function (callBack) {
  var serverConfig = 'http://127.0.0.1:4444/wd/hub';
  var capabilities = {
    silent: true, // maybe output more for tests?
    browserName: 'phantomjs',
    javascriptEnabled: true,
    takesScreenshot: true,
    databaseEnabled: false,
    cssSelectorsEnabled:true,
    webStorageEnabled: true
  };

  var driver = new webdriver
    .Builder()
    .usingServer(serverConfig)
    .withCapabilities(capabilities)
    .build();

  loadAssets(driver);

  if (typeof callBack === 'function') {
    return callBack (driver);
  }
  else if ( typeof callBack === 'object' && typeof callBack.resolve === 'function' ) {
    return callBack.resolve(driver);
  }
  else {
    return driver;
  }
}

Append scripts to the load page
Append scripts to the load page
