According to the Protractor docs the .map()
function that is available on element.all
result returns a Promise that resolves to an array.
So you need to await
for it:
it('test if templates are downloadable', async () => {
const links = element.all(by.xpath('//button//img[@src="url_here"]'));
const urls = await links.map(link => link.getAttribute('src')); // await here
const requests = await urls.map(url => fetch(url)); // and await here
const responses = await Promise.all(requests);
const statusCodes = responses.map(response => response.status);
statusCodes.forEach(statusCode => {
expect(statusCode).toBeLessThan(400);
});
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…