Skip to content

Instantly share code, notes, and snippets.

@sergtimosh
Last active July 4, 2020 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergtimosh/1bf5d33a0d3eb929ffbca2bc8d5c8076 to your computer and use it in GitHub Desktop.
Save sergtimosh/1bf5d33a0d3eb929ffbca2bc8d5c8076 to your computer and use it in GitHub Desktop.
//Assertions
async isElementVisible(css, timeout = 50) {
let visibility = true
await page
.waitForSelector(css, { visible: true, timeout: timeout })
.catch(() => {
visibility = false;
})
return visibility
},
async isElementDisplayedByClass(css, timeout = 50) {
let visibility = true
await page
.waitForSelector(css + '.displayNone', { timeout: timeout })
.catch(() => {
visibility = false;
})
return visibility
},
async isElementVisibleByWidth(css, timeout = 2000) {
let visible = true
await page.waitFor(css =>
[...(document.querySelectorAll(css))]
.filter(el => el.offsetHeight !== 0)
.length !== 0
, { timeout: timeout }, css)
.catch(() => {
visible = false
})
return visible
},
async isElementPresent(selector, timeout = 2000) {
let isPresent = true
await page.waitForSelector(selector, { timeout: timeout })
.catch(() =>
isPresent = false
)
console.log(`element is present - ${isPresent}`)
return isPresent
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment