diff --git a/bin/elementexplorer.js b/bin/elementexplorer.js index 184b56c7a..f4adde3a4 100755 --- a/bin/elementexplorer.js +++ b/bin/elementexplorer.js @@ -32,124 +32,15 @@ * Typing tab at a blank prompt will fill in a suggestion for finding * elements. */ - -var webdriver = require('selenium-webdriver'); -var protractor = require('../lib/protractor.js'); -var repl = require('repl'); -var util = require('util'); -var vm = require('vm'); - -var driver, browser; - -var INITIAL_SUGGESTIONS = [ - 'element(by.id(\'\'))', - 'element(by.css(\'\'))', - 'element(by.name(\'\'))', - 'element(by.binding(\'\'))', - 'element(by.xpath(\'\'))', - 'element(by.tagName(\'\'))', - 'element(by.className(\'\'))' -]; - -var list = function(locator) { - return browser.findElements(locator).then(function(arr) { - var found = []; - for (var i = 0; i < arr.length; ++i) { - arr[i].getText().then(function(text) { - found.push(text); - }); - } - return found; - }); -}; - -var flowEval = function(code, context, file, callback) { - - var vmErr, - result, - flow = webdriver.promise.controlFlow(); - - flow.execute(function() { - try { - result = vm.runInThisContext(code, file); - } catch (e) { - vmErr = e; - callback(vmErr, null); - } - if (vmErr && process.domain) { - process.domain.emit('error', vmErr); - process.domain.exit(); - } - - if (webdriver.promise.isPromise(result)) { - return result.then(function(val) {return val}); - } else { - return result; - } - }).then(function(res) { - if (!vmErr) { - callback(null, res); - } - }, function(err) { - callback('There was a webdriver error: ' + err.name + ' ' + err.message, - null); - }); -}; - -var startRepl = function() { - var flowRepl = repl.start({ - 'useGlobal': true, - 'eval': flowEval - }); - - var originalComplete = flowRepl.complete; - - flowRepl.complete = function(line, completeCallback) { - if (line == '') { - completeCallback(null, [INITIAL_SUGGESTIONS, '']); - } else { - originalComplete.apply(this, arguments); - } - }; - - flowRepl.on('exit', function() { - driver.quit(); - util.puts('Shutting down. Goodbye.'); - }); -}; - -var startUp = function() { - driver = new webdriver.Builder(). - usingServer('http://localhost:4444/wd/hub'). - withCapabilities({'browserName': 'chrome'}).build(); - - driver.getSession().then(function(session) { - driver.manage().timeouts().setScriptTimeout(11000); - - browser = protractor.wrapDriver(driver); - - // Set up globals to be available from the command line. - global.driver = driver; - global.protractor = protractor; - global.browser = browser; - global.$ = browser.$; - global.$$ = browser.$$; - global.element = browser.element; - global.by = global.By = protractor.By; - global.list = list; - - - util.puts('Type to see a list of locator strategies.'); - util.puts('Use the `list` helper function to find elements by strategy:'); - util.puts(' e.g., list(by.binding(\'\')) gets all bindings.'); - util.puts(''); - - var url = process.argv[2] || 'about:blank'; - util.puts('Getting page at: ' + url); - driver.get(url); - - startRepl(); - }); -}; - -startUp(); +console.log('Please use "protractor --elementExplorer [options] [configFile]"' + + ' for full functionality\n'); + +if (process.argv.length > 3) { + console.log('usage: elementexplorer.js [urL]'); + process.exit(1); +} else if (process.argv.length === 3) { + process.argv[2] = ('--baseUrl=' + process.argv[2]); +} + +process.argv.push('--elementExplorer'); +require('../lib/cli.js'); diff --git a/lib/cli.js b/lib/cli.js index d3c4e241b..9adcaf139 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -131,8 +131,9 @@ if (!configFile) { } if (!configFile && !argv.elementExplorer && args.length < 3) { - console.log('you must either specify a configuration file ' + - 'or at least 3 options. See "protractor --help" for more info.'); + console.log('**you must either specify a configuration file ' + + 'or at least 3 options. See below for the options:\n'); + optimist.showHelp(); process.exit(1); } diff --git a/lib/debugger/clients/wdrepl.js b/lib/debugger/clients/explorer.js similarity index 100% rename from lib/debugger/clients/wdrepl.js rename to lib/debugger/clients/explorer.js diff --git a/lib/frameworks/repl.js b/lib/frameworks/explorer.js similarity index 100% rename from lib/frameworks/repl.js rename to lib/frameworks/explorer.js diff --git a/lib/launcher.js b/lib/launcher.js index d98c6c8aa..eb3a982fc 100644 --- a/lib/launcher.js +++ b/lib/launcher.js @@ -155,13 +155,13 @@ var init = function(configFile, additionalConfig) { }); }).then(function() { // 3) If we're in `elementExplorer` mode, run only that. - if (config.elementExplorer) { + if (config.elementExplorer || config.framework === 'explorer') { if (config.multiCapabilities.length != 1) { throw new Error('Must specify only 1 browser while using elementExplorer'); } else { config.capabilities = config.multiCapabilities[0]; } - config.framework = 'repl'; + config.framework = 'explorer'; var Runner = require('./runner'); var runner = new Runner(config); diff --git a/lib/protractor.js b/lib/protractor.js index 117033aad..d8b2b6032 100644 --- a/lib/protractor.js +++ b/lib/protractor.js @@ -777,7 +777,7 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort) * @param {number=} opt_debugPort Optional port to use for the debugging process */ Protractor.prototype.enterRepl = function(opt_debugPort) { - var debuggerClientPath = __dirname + '/debugger/clients/wdrepl.js'; + var debuggerClientPath = __dirname + '/debugger/clients/explorer.js'; this.initDebugger_(debuggerClientPath, opt_debugPort); }; diff --git a/lib/runner.js b/lib/runner.js index f2386f6de..88c5e5770 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -234,7 +234,7 @@ Runner.prototype.run = function() { plugins, browser_; - if (this.config_.framework !== 'repl' && !this.config_.specs.length) { + if (this.config_.framework !== 'explorer' && !this.config_.specs.length) { throw new Error('Spec patterns did not match any files.'); } @@ -272,9 +272,9 @@ Runner.prototype.run = function() { } else if (self.config_.framework === 'debugprint') { // Private framework. Do not use. frameworkPath = './frameworks/debugprint.js'; - } else if (self.config_.framework === 'repl') { + } else if (self.config_.framework === 'explorer') { // Private framework. Do not use. - frameworkPath = './frameworks/repl.js'; + frameworkPath = './frameworks/explorer.js'; } else { throw new Error('config.framework (' + self.config_.framework + ') is not a valid framework.');