I have a test where I am trying to check and see if a modal is open or not. If modally open, the test runs fine when it is not open, the test ends with an exception NoSuchElementError.
Here is my current version of my test:
fit('Share is actually shared', () => {
console.log(`\n ### Share is actually shared ${entity.name} ### \n`)
listView.clickSharing(entity.name)
const sharedWithBefore = sharing.sharedUsers.count()
sharing.createShare(sharee)
sharing.shareButton.click()
const isPresent = browser.isElementPresent(sharing.modal.getWebElement())
isPresent.then(result => {
console.log('is the modal present: ' + result)
if (result) {
sharing.modalAcceptButton.click()
}
})
const sharedWithAfter = sharing.sharedUsers.count()
Promise.all([sharedWithBefore, sharedWithAfter]).then(results => {
expect(results[0] != results[1]).toBe(true)
})
sharing.title.click()
common.escapeFromBody()
})
The problem is in the block after the comment // HandleShare with Everyone.
I tried to do the following, and none of them work, if the modal does not appear, it just fails.
const isPresent = sharing.modal.isPresent()
if (isPresent) {
sharing.modalAcceptButton.click()
}
const isPresent = sharing.modal.isPresent()
isPresent.then(result => {
if (result) {
sharing.modalAcceptButton.click()
}
})
const isPresent = sharing.modal.isPresent()
const isDisplayed = sharing.modal.isDisplayed()
if (isPresent && isDisplayed) {
sharing.modalAcceptButton.click()
}
const isPresent = browser.isElementPresent(sharing.modal.getWebElement())
isPresent.then(present => {
if (present) {
sharing.modalAcceptButton.click()
const sharedWithAfter = sharing.sharedUsers.count()
Promise.all([sharedWithBefore, sharedWithAfter]).then(results => {
expect(results[0] != results[1]).toBe(true)
})
} else {
const sharedWithAfter = sharing.sharedUsers.count()
Promise.all([sharedWithBefore, sharedWithAfter]).then(results => {
expect(results[0] != results[1]).toBe(true)
})
}
})
const isPresent = browser.isElementPresent(sharing.modal.getWebElement())
isPresent.then(present => {
try {
if (present) {
sharing.modalAcceptButton.click()
const sharedWithAfter = sharing.sharedUsers.count()
Promise.all([sharedWithBefore, sharedWithAfter]).then(results => {
expect(results[0] != results[1]).toBe(true)
})
}
} catch (NoSuchElementError) {
console.log('The Modal is not present continuing')
const sharedWithAfter = sharing.sharedUsers.count()
Promise.all([sharedWithBefore, sharedWithAfter]).then(results => {
expect(results[0] != results[1]).toBe(true)
})
}
})
I'm not quite sure what to try from here. If there is no modal, then the test simply fails. What am I doing wrong?
source
share