Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check picture step #469

Merged
merged 6 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions backend/features/step_definitions/stepdefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,45 @@ Then(
}
);

Then('So the picture {string} has the name {string}', async function checkPicture(picture, name) {
const world = this;
const identifiers = [`//picture[source[contains(@srcset, '${picture}')] or img[contains(@src, '${picture}') or contains(@alt, '${picture}') or @id='${picture}' or contains(@title, '${picture}')]]`, `//img[contains(@src, '${picture}') or contains(@alt, '${picture}') or @id='${picture}' or contains(@title, '${picture}')]`, `${picture}`];
const promises = [];
for (const idString of identifiers) promises.push(driver.wait(until.elementLocated(By.xpath(idString)), searchTimeout, `Timed out after ${searchTimeout} ms`, 100));
const domain = (await driver.getCurrentUrl()).split('/').slice(0, 3).join('/');
let finSrc = '';
await Promise.any(promises)
.then(async (elem) => {
if (await elem.getTagName() === 'picture') {
const childSourceElems = await elem.findElements(By.xpath('.//source'));
const elementWithSrcset = await childSourceElems.find(async (element) => {
const srcsetValue = await element.getAttribute('srcset');
return srcsetValue && srcsetValue.includes(name);
});
finSrc = await elementWithSrcset.getAttribute('srcset');
}
const primSrc = await elem.getAttribute('src');
const secSrc = await elem.getAttribute('srcset');
if (!finSrc && primSrc && primSrc.includes(name)) finSrc = primSrc;
if (!finSrc && secSrc && secSrc.includes(name)) finSrc = secSrc;
finSrc = finSrc.split(' ').filter((substring) => substring.includes(name));
})
.catch(async (e) => {
await driver.takeScreenshot().then(async (buffer) => {
world.attach(buffer, 'image/png');
});
throw Error(e);
});
await fetch(domain + finSrc, { method: 'HEAD' })
.then(response => {
if (!response.ok) throw Error(`Image ${finSrc} not Found`);
})
.catch(e => {
throw Error(`Image Availabel check Request Error to ${domain + finSrc} `, e);
});
await driver.sleep(100 + currentParameters.waitTime);
});

// Search if a text isn't in html code
Then('So I can\'t see the text: {string}', async function checkIfTextIsMissing(expectedText) {
const world = this;
Expand Down
10 changes: 10 additions & 0 deletions backend/src/database/stepTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,16 @@ function stepDefs() {
'',
''
]
}, {
id: 3,
stepType: 'then',
type: 'Check Image',
pre: 'So the picture',
mid: 'has the name ',
values: [
'',
''
]
}
];
}
Expand Down
Loading