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

Commit

Permalink
fix(debugger): expose require into debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
hankduan committed Mar 16, 2015
1 parent 2cd7be8 commit ef0fbc0
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,24 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort)
});

var vm_ = require('vm');
var context = { require: require };
for (var key in global) {
context[key] = global[key];
}
context.list = function(locator) {
/* globals browser */
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 sandbox = vm_.createContext(context);

var browserUnderDebug = this;

// Helper used only by debuggers at './debugger/modes/*.js' to insert code
Expand Down Expand Up @@ -719,7 +737,7 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort)
var execFn_ = function() {
// Run code through vm so that we can maintain a local scope which is
// isolated from the rest of the execution.
var res = vm_.runInThisContext(code);
var res = vm_.runInContext(code, sandbox);
if (!webdriver.promise.isPromise(res)) {
res = webdriver.promise.fulfilled(res);
}
Expand Down Expand Up @@ -774,19 +792,6 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort)
}
};

global.list = function(locator) {
/* globals browser */
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;
});
};

flow.timeout(1000, 'waiting for debugger to attach');
};

Expand Down

0 comments on commit ef0fbc0

Please sign in to comment.