I am building a Math tutoring application and would like to test my UI using angular's e2e testing suite.
Currently I am working on a Fraction page that generates a random fraction, displays a series of shaded and unshaded boxes and asks the user to input the fraction formed by the shading.
Using an e2e test, I would like to test how the UI responds to both correct and incorrect input; however, since the fraction is randomized on page load, I do not know what 'correct' input is from inside the test.
The easiest way for me to get the correct answers to input would be to gain access to the Fraction object, located at $scope.problemObject
for the controller, and call its API functions .getNumerator()
and .getDenominator()
. However, I have not found a way to get to this object from within my tests.
Relevant lines from my controller are:
$scope.problemObject = Fraction.random();
// This produces an object with two relevant
// functions (getNumerator() & getDenominator())
What I Have Tried
binding()
Initially I thought binding()
would do what I needed, however all calls to binding('problemObject')
or binding('problemObject.getNumerator()'
and the like issue an error saying that the binding cannot be found. I suspect that this is because $scope.problemObject
and the return value of $scope.problemObject.getNumerator()
are not directly bound to the UI.
angular.element().scope()
Executing angular.element('#problem').scope().problemObject
from the console on the page that I am testing works perfectly; however, trying the same line from within my test issues the following error: 'selectors not implemented'.
I have also tried a few variations:
element('#problem').scope().problemObject
: Error: 'Object # has no method 'scope''
angular.element(element('#problem')).scope().problemObject
: Error: 'Cannot read property 'problemObject' of undefined'