如果规范在循环内,量角器测试总是通过

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

问题:

我的要求:

代码:

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');
      });
    });
  });

问题:

有人可以帮我解决这个问题吗?我需要获取元素列表并逐页循环测试它。

对于每个只触发这些命令,而不是等到它们解决

改用for循环

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');
      } 
    });