mercredi 31 décembre 2014

Is it possible to use Protractor to test the value of a variable not model-bound to the DOM?

I'm relatively new to Angular and new (today) to Protractor, so I'm not exactly sure how to ask this question - thus I not quite sure if there is a duplicate out there. Below is a very simplified version of a much larger, much more complex application we are developing, but the basic idea is the same.


Let's say I have a simple web page:



<input id="my-input" ng-model="myValue">
<button id="submit-button" ng-click="doSomething()">
Click Me
</button>


Controlled by a simplified angular app:



// some-angular-app.js

$scope.myValue = "";
$scope.computedValue = null;

$scope.doSomething = function() {
$scope.computedValue = "Hello World";
}


Essentially, when you click on the button, it triggers a function which manipulates variables in your app. In our case (as above), the variables (i.e. $scope.computedValue) are not bound to the DOM in any way - they are actually compiled and passed to a JSON request to be consumed by our API. However, I want to test those values -- something like:



// some-protractor-test.js

describe('form submission', function() {
it('should corretly set the computed value', function() {
browser.get('http://ift.tt/1ELseoZ');
element(by.css("#my-input")).sendKeys("Hello Input");
element(by.css("#submit-button")).click();

// ??? how to check that computedValue === "Hello World" ???
});
});


Is is possible to use Protractor to check the state of our data in this manner, or must all interaction with the Angular app be handled through DOM elements?


Aucun commentaire:

Enregistrer un commentaire