Question

To my understanding Protractor is meant to run on top of WebDriver on a Node.js server and send commands to a selenium server (feel free to correct me if I'm wrong).

Anyway, I was wondering if it is possible to load Protractor into a web page as a JavaScript library (like you would load jQuery for example) so it would be accessible from the JavaScript code in the page.

Can it be done? If so, how? What files do I need? What dependencies?

My goal is to use its capabilities of selecting elements by their various angular bindings, and its waiting for angular events capabilities.

Was it helpful?

Solution

I don't think you can. You can write your own locators, or use directives to isolate element/binding. Another good thing to do would be to dive into the protractor source code and see how they do it. Particularly check out their clientsidescripts.js file. Here is an example of how they find bindings. You would call it like this: findBindings('exampleBinding');

clientSideScripts.findBindings = function() {
  var binding = arguments[0];
  var using = arguments[1] || document;
  var bindings = using.getElementsByClassName('ng-binding');
  var matches = [];
  for (var i = 0; i < bindings.length; ++i) {
    var dataBinding = angular.element(bindings[i]).data('$binding');
    if(dataBinding) {
      var bindingName = dataBinding.exp || dataBinding[0].exp || dataBinding;
      if (bindingName.indexOf(binding) != -1) {
        matches.push(bindings[i]);
      }
    }
  }
  return matches; // Return the whole array for webdriver.findElements.
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top