intern icon indicating copy to clipboard operation
intern copied to clipboard

Check if / assert an element is not present

Open jiayexie opened this issue 9 years ago • 1 comments

Hi,

Is there a way in intern to assert that an element does not exist on the page without waiting, or just check if the element is present? It looks like there are multiple ways of doing this in Selenium (isElementPresent(), findElements(..).size()), but I just didn't find any way in intern to do this.

To be specific, here is a use case: if my website runs into any error, I print that out to a div overlaying the entire page. After each of my test case I would like to assert that div did not show up.

Thanks in advance!

jiayexie avatar Nov 21 '17 23:11 jiayexie

Hi! As the "New Issue" instructions mention, we'd really like to keep this tracker focused on bug reports or feature requests. General usage questions should be directed to Stack Overflow (using the 'intern' keyword), or to our gitter channel.

That said, the two most common ways to do this are 1) set the find timeout to something very short, search for the element, and catch a "not found" error, or 2) set the find timeout to something short and do a "findAll", then check that the resulting array has zero length (like your findElements(..).size() example).

this.remote
    .get('page.html')
    .setFindTimeout(10)
    .findByCssSelector('.errorDiv')
    .then(() => {
        throw new Error('element should not exist');
    }, () => {})
    .setFindTimeout(5000)
    // continue

or

this.remote
    .get('page.html')
    .setFindTimeout(10)
    .findAllByCssSelector('.errorDiv')
    .then(elements => {
        assert.lengthOf(elements, 0);
    })
    .setFindTimeout(5000)
    // continue

jason0x43 avatar Nov 22 '17 02:11 jason0x43