Accessing Angular inside Protractor Test

Is it possible to access angular within your protractor tests like you do in unit testing?

Use case is that I have a service that transforms text and I want to access that service to transform some data within the actual test script. I know there is the addMockModule method in protractor but I cannot figure out how to use it for this purpose.

Would appreciate any help!



There is a function called evaluate(). Find an element in the dom and then run the expression.

For example. If you want to count the number of todos in the website (under Add Some Control), do this:

Open the element explorer in protractor

  then(function(count) {

It should give you a 2

You can also use executeAsyncScript

browser.executeAsyncScript(function(callback) {
  // Here we use document.body, but your app may live under a different
  // element.
  var service = angular.element(document.body)
  service.query({}, function(data) {
}).then(function (output) {

See an example:


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.