Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hankduan committed Jan 13, 2015
1 parent 749d4d3 commit c6822ac
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 129 deletions.
133 changes: 12 additions & 121 deletions bin/elementexplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tab> 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');
5 changes: 3 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
6 changes: 3 additions & 3 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}

Expand Down Expand Up @@ -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.');
Expand Down

0 comments on commit c6822ac

Please sign in to comment.