In my code image is removed successfully if any, but when there are multiple images in the canvas, how do I know that I have to call Remove_image() function for how many times? my condition is if the body finds canvas is null then upload the image else remove the uploaded image.
This is my code
cy.get('body').each((body) => {
if (body.find(':nth-child(2) > .front-upload > :nth-child(2) > .table > .table-cell').length > 0) {
const filepath = "Front.jpg"
imageupload.fileuploadInput().attachFile(filepath, { subjectType: 'drag-n-drop' })
cy.wait(60000)
cy.Flip_image()
}
else {
// REMOVE ELEMENT
cy.log('Remove Image')
// There is 5 uploaded image that's why this function call 5 times But this is not right structure.
cy.Remove_image()
cy.Remove_image()
cy.Remove_image()
cy.Remove_image()
cy.Remove_image()
// UPLOAD IMAGE
cy.wait(1000)
const filepath = "Front.jpg"
imageupload.fileuploadInput().attachFile(filepath, { subjectType: 'drag-n-drop' })
cy.wait(60000)
cy.Flip_image()
}
})
This is how I'd approach it,
Assuming there are as many images as there are cells
cy.get(':nth-child(2) > .front-upload > :nth-child(2) > .table')
.then($table => {
const imageCount = $table.find('.table-cell').length;
for (let i = 0; i < imageCount; i++) {
cy.Remove_image()
})
// UPLOAD IMAGE
cy.wait(1000)
const filepath = "Front.jpg"
imageupload.fileuploadInput().attachFile(filepath, { subjectType: 'drag-n-drop' })
cy.wait(60000)
cy.Flip_image()
})
If some cells may be empty, you can count <img>
tags instead
const imageCount = $table.find('img').length;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.