ISSUE :
While using the code provided in the EXAMPLE section, the expect block inside the forEach loop always passes, which is not the expected behavior.
For instance, here is a scenario along with a screenshot of the test report:
expect('bt bt-primary').toContain('btn');
https://i.sstatic.net/Oky53.png
WHAT I NEED :
- I am looking to extract a list of all buttons present on a page in order to conduct E2E test cases for custom CSS functionalities.
- The test code should be easily reusable across multiple test files for different pages.
- To achieve this, I have disabled the selenium promise manager and implemented the async/await method.
- However, I am facing a challenge while trying to accomplish this task.
SAMPLE CODE :
describe('Login form', () => {
it('should navigate to page with login form', async () => {
await expect(browser.getCurrentUrl()).toEqual(
'http://localhost:4200/#/login'
);
});
it('should check for buttons with bootstrap classes', async () => {
const buttons = await page.getAllButtons();
buttons.forEach(async (button) => {
const classAttribute = await button.getAttribute('class');
expect(classAttribute).toContain('btn');
});
});
});
QUERY :
Can anyone assist me in resolving this issue? I aim to retrieve a list of elements and perform tests on them in a loop, page by page.