0

app.component.html

<div class="student-list" *ngFor="let student of students">
    <p>{{student.name}}</p>
</div>

I want to test whether all students have name. But students is a list which is getting set in app.component.ts.

Now how should I set the students from protractor?

I have done following

element(by.binding('students')).sendKeys(['abc', 'xyz']);

But this is not working, it throws Failed: unknown error: angular is not defined. What is the correct way?

Sanket Achari
  • 480
  • 1
  • 6
  • 20

2 Answers2

2

angular selectors such as by.model and by.binding are not supported Angular2 and above versions.

As per the docs

Protractor works with AngularJS versions greater than 1.0.6/1.1.4, and is compatible with Angular applications. Note that for Angular apps, the by.binding() and by.model() locators are not supported. We recommend using by.css().

you can see the examples here

https://angular.io/guide/upgrade#e2e-tests

EDIT

To solve your issue you can use Id

HTML

<div  *ngFor="let student of students" id="students">
    <p  class="student-list"> {{student.name}}</p>
</div>

test

var students = element.all(by.id('students')).all(by.css('student-list'));
var firstOrg = organizations.get(0);
it('should have an org with specific name', function() {
    expect(firstOrg.getText()).toEqual('Name you expect');
});
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
0
<div class="student-list" *ngFor="let student of students">
    <p *ngIf="student.name">{{student.name}}</p>
</div>

This is one of the way using which you can display only those users who has name.

AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57