ng-repeat with ng-model bindings
My markup looks like this: My markup looks like this:
<div ng-repeat = "cat in pets">
<div contenteditable ng-model="cat.name"></div>
</div>
And I tried to test if there is anything in the repeater with this test:
cats = ptor.findElements(
protractor.By.repeater('cat in pets').column('cat.name')
)
vats.then (arr) ->
console.log arr
expect(arr[0]).toBeDefined() <-- not defined
expect(arr.length).toBeGreaterThan(0) <-- not defined
i tried different values for the binding 'cat', 'name' and '{{ cat.name }}' at no avail.
When I add a regular binding to my markup like {{ project.title }} like in the samples here: https://github.com/angular/protractor/blob/master/spec/findelements_spec.js#L9 I get some results in 'arr'. It seems to only look for the combination of 'ng-binding' and the exact column() string.
For now the only way I see to test if the repeater is empty is by selecting the first row and testing if that exists.
For anybody interested in the content a the found element:
{ then: [Function: then],
cancel: [Function: cancel],
isPending: [Function: isPending],
errback: [Function: reject],
driver_: { session_: [Object], executor_: [Object], flow_: [Object] },
id_:
{ then: [Function: then],
cancel: [Function: cancel],
isPending: [Function: isPending] },
click: [Function],
sendKeys: [Function],
getTagName: [Function],
getCssValue: [Function],
getAttribute: [Function],
getText: [Function],
getSize: [Function],
getLocation: [Function],
isEnabled: [Function],
isSelected: [Function],
submit: [Function],
clear: [Function],
isDisplayed: [Function],
getOuterHtml: [Function],
getInnerHtml: [Function],
findElement: [Function],
findElements: [Function],
isElementPresent: [Function],
evaluate: [Function] }
This leaves me with the problem of determining whether a row was added when 'addRow' was clicked
In the process of adding logic to find all the bindings. Will R-P when done.
I've added this code at line 199 of the clientsidescripts, which seems to work, but i don't know if the detection of ng-binding is good enough like this. I couldn't find a reference to the binding string in the $ngModelController
// find the ng-model bindings
var allElements = rows[i].getElementsByTagName('*');
for (var l = 0; l < allElements.length; l++) {
if (allElements[l].getAttribute('ng-model')) {
if (allElements[l].getAttribute('ng-model') === binding)
matches.push(allElements[l]);
}
}
added some testapp code to show the predicament and started a modest fix. Can someone tell me if I'm on the right track: https://github.com/Elexy/protractor/commit/f8cc7a229ab2e8b72716ce63fbe58837fbf7550c then I will keep going and make a PR
Hi! So as you've discovered, the column selector takes a string which matches bindings, not input ng-models. I'm considering whether it's worth merging the concept of binding to include ng-model attributes as well, but if we change this it should change everywhere (e.g in protractor.By.binding as well).
For now, you can solve this by chaining findElement calls (in JS because my coffeescript will be buggy):
catRows = ptor.findElements(
protractor.By.repeater('cat in pets'); // Note - this will only work with master, or once the 0.11.0 release is out.
).then(function(rows) {
for (var i = 0; i < rows.length; ++i) {
rows[i].findElement(protractor.By.input('cat.name')).<whatever you want to do here>
}
});
I agree if it´s done, it should be working for any king of binding lookup.
Good that there is a workaround, that probably puts this change a little lower on the list. I´ll see if i can extend this to work for all binding lookups.
keep you posted.
+1 It would be very nice to have this.
AIM TO ACCESS TEXT IN ANGULAR ITEMs
<div ng-repeat="todo in todos"> <span>{{todo.text}}</span> <input type="text" ng-model="todo.text"/> <input type="checkbox"></input> </div>
Plunkr
And My protractor Looks Like this //Protractor Code Starts describe("TODO", function() { it(' TODO TESTING', function() {
browser.get("http://embed.plnkr.co/3h4oSme1NVYAg101YNfe/preview");
browser.sleep(10000);
var TEXT = element(by.repeater('todo in todos').row(1).column('{{todo.text}}').getAttribute('value'))
console.log(TEXT)
})
//Protractor Code Ends
GIVES ERROR :
{ parentElementArrayFinder:
{ getWebElements: [Function],
actionResults_:
{ then: [Function: then],
cancel: [Function: cancel],
isPending: [Function: isPending] },
locator_:
{ findElementsOverride: [Function],
toString: [Function: toString] },
click: [Function],
sendKeys: [Function],
getTagName: [Function],
getCssValue: [Function],
getAttribute: [Function],
getText: [Function],
getSize: [Function],
getLocation: [Function],
isEnabled: [Function],
isSelected: [Function],
submit: [Function],
clear: [Function],
isDisplayed: [Function],
getOuterHtml: [Function],
getInnerHtml: [Function],
getId: [Function] },
elementArrayFinder_:
{ getWebElements: [Function],
actionResults_:
{ then: [Function: then],
cancel: [Function: cancel],
isPending: [Function: isPending] },
locator_:
{ findElementsOverride: [Function],
toString: [Function: toString] },
1) TODO TESTING
Message:
NoSuchElementError: No element found using locator: by.repeater("todo in todos").row("1").column("{{todo.text}}")
Stacktrace:
NoSuchElementError: No element found using locator: by.repeater("todo in todos").row("1").column("{{todo.text}}")
-----------------NOT ABLE TO FIND WHAT WRONG I AM DOING------------------
Got ths working
After trying for a long time I got this WORKING
Doubts :
1 : i know About "Angular promise..then" .i have nested three "then" one inside
.Another but don't know why use "then" in protractor.
element(by.repeater('todos')).evaluate('todos.length').then(function(itemLength)
{
for(var i = 0 ; i < itemLength ; i++)
{
var result= element(by.repeater('todo in todos').row(i));
result.then(function(arr)
{
/*FETCH TEXT*/
var m = arr.all(by.model("todo.text")).getAttribute('value');
m.then(function(l){
console.log(l);
});
/*CLEAR TEXT*/
arr.all(by.model("todo.text")).clear();
/*SET TEXT*/
arr.all(by.model("todo.text")).sendKeys('Hello');
});
};
});
Want to know is this the Best approach to access angular model properties.
Is this Protractor's standard way
I think this is all possible to do with element.all and filtering now. Closing.
HI All,
I have issue to validate the value using protractor. Please advice highly appreciated. Thanks
Failed: No element found using locator: by.model("ctrl.formData.branchAddressLine1")
code:
element(by.model('ctrl.formData.branchAddressLine1')).getAttribute('value').then(function (value) { expect(value).toEqual('Plaza Scotiabank'); })