Estoy tratando de hacer algunas afirmaciones en Playwright . Debo afirmar que en una lista de enlaces <a> todos ellos tienen el atributo href . Sin embargo, no sé cómo lograr eso con las funciones de Dramaturgo.
Mi código está aquí:
test.only('then a list of 44 links is displayed', async({ page }) => { const linkList = await page.locator('div#content > ul > li > a'); for(let i = 0; i < await linkList.count(); i++) { expect(await linkList.nth(i)).toHaveAttribute('href', ''); } await expect(linkList).toHaveCount(44); }) La función toHaveAttribute() necesita de 2 a 3 argumentos porque obtiene el atributo clave y el valor del atributo, pero solo necesito verificar si tiene el atributo href.
¿Cómo puedo lograr eso?
Este es el sitio web que se está probando: https://the-internet.herokuapp.com/
Después de probar algunas opciones, me doy cuenta de que puedo afirmar si al usar Locator.getAttribute('href') no devuelve un valor nulo, por lo que es un enlace. Así que implementé eso:
const linkList = await page.locator('div#content > ul > li > a'); for(let i = 0; i < await linkList.count(); i++) { expect(await linkList.nth(i).getAttribute('href')).not.toBeNull(); }