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

Commit ef0fbc0

Browse files
committed
fix(debugger): expose require into debugger
1 parent 2cd7be8 commit ef0fbc0

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

lib/protractor.js

+19-14
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,24 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort)
673673
});
674674

675675
var vm_ = require('vm');
676+
var context = { require: require };
677+
for (var key in global) {
678+
context[key] = global[key];
679+
}
680+
context.list = function(locator) {
681+
/* globals browser */
682+
return browser.findElements(locator).then(function(arr) {
683+
var found = [];
684+
for (var i = 0; i < arr.length; ++i) {
685+
arr[i].getText().then(function(text) {
686+
found.push(text);
687+
});
688+
}
689+
return found;
690+
});
691+
};
692+
var sandbox = vm_.createContext(context);
693+
676694
var browserUnderDebug = this;
677695

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

777-
global.list = function(locator) {
778-
/* globals browser */
779-
return browser.findElements(locator).then(function(arr) {
780-
var found = [];
781-
for (var i = 0; i < arr.length; ++i) {
782-
arr[i].getText().then(function(text) {
783-
found.push(text);
784-
});
785-
}
786-
return found;
787-
});
788-
};
789-
790795
flow.timeout(1000, 'waiting for debugger to attach');
791796
};
792797

0 commit comments

Comments
 (0)