Neyo
Neyo

Reputation: 624

Protractor test always passes, if the spec is inside a loop

PROBLEM :

test report

MY REQUIREMENT :

CODE :

describe('Login form', () => {
    it('should navigate to page containing login form', async () => {
      await expect(browser.getCurrentUrl()).toEqual(
        'http://localhost:4200/#/login'
      );
    });

    it('should contain buttons with bootstrap classes', async () => {
      const buttons = await page.getAllButtons();
      buttons.forEach(async (button) => {
        const classAttribute = await button.getAttribute('class');
        expect(classAttribute).toContain('btn');
      });
    });
  });

QUESTION :

Can someone help me on how to solve this issue ? I need to get list of elements and test it in a loop page by page.

Upvotes: 2

Views: 106

Answers (1)

Sergey Pleshakov
Sergey Pleshakov

Reputation: 8948

For each just fires of these commands and doesn't wait until their resolution

Use for loop instead

it('should contain buttons with bootstrap classes', async () => {
      const buttons = page.getAllButtons();
      for (let i = 0; i<buttons.length; i++) {
        const classAttribute = await buttons.get(i).getAttribute('class');
        expect(classAttribute).toContain('btn');
      } 
    });

Upvotes: 3

Related Questions