Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

98
Visualizações
Protractor - ngFor loop

I'm using latest Angular and latest Protractor version and I'm wondering how to work with ngFor loop in my tests.

In past in my AngularJS app it was simple. I just used something like by.repeater and magic was done behind.

However now in Angular 4 APP I'm not that lucky. Based on this ticket it is not supported yet. At another hand I saw a stackoverflow ticket when somone is already working with it.

Anyway my HTML is:

<div *ngFor="let org of userOrgList; count as count">
   <button class="btn btn-default btn-lg col-xs-12" type="submit"  (click)="selectOrg(org.id)">{{org.name}}</button>
</div>

And my test looks like:

var organizations = element.all(by.repeater('org of userOrgList'));

it('should have an org with specific name', function() {
    expect(organizations.get(0).getText()).toEqual('myOrgName');
});

And I get an error:

Failed: Index out of bound. Trying to access element at index: 0, but there are only 0 elements that match locator by.rep eater("let org of userOrgList; count as count")

My question is: How to work with ngFor inside my protractor test

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Solution I found that works for me but still not as clean as it was with repeater

// HTML FILE: Added id to DIV 
<div *ngFor="let org of userOrgList; count as count" id="organizations">
    <button class="btn btn-default btn-lg col-xs-12" type="submit"  (click)="selectOrg(org.id)">{{org.name}}</button>
</div>

//TEST FILE:
var organizations = element.all(by.id('organizations')).all(by.css('button'));
var firstOrg = organizations.get(0);
it('should have an org with specific name', function() {
    expect(firstOrg.getText()).toEqual('Name you expect');
});

With a standard table repeater it may looks like:

var data = element.all(by.css('table[name='' + TableName + '']')).all(by.css('tr td'));
expect(data.get(0).getText()).toEqual('0');
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda