Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Protractor invisibilityOf flakiness, throwing NoSuchElementError #2138

Closed
@hgted

Description

@hgted

I am testing a non angular app where I have a login helper function in my tests similar to the following:

function login() {
        return waitUntilVisible($('#txtUsername'))
            .then(function () {
                $('#txtUsername').sendKeys('tom');
            })
            .then(function () {
                $('#txtPassword').sendKeys('*');
            })
            .then(function () {
                $('#btnLogin').click();
            })
            .then(function () {
                // this is the flaky line
                return browser.wait(protractor.ExpectedConditions.invisibilityOf($('#txtUsername')), 20000, 'Element never disappeared');
            });
    }

Where browser.wait(protractor.ExpectedConditions.invisibilityOf($('#txtUsername')), 20000, 'Element never disappeared') waits for a bootstrap modal containing the login form to close. However, this line is proving to be very flaky, occasionally failing with:

NoSuchElementError: No element found using locator: By.cssSelector("#txtUsername")

Or even:

StaleElementReferenceError: stale element reference: element is not attached to the page document

My first though was that the modal was closing before the line was called, however, the docs for invisibilityOf suggest it should handle the element not being present, stating it as:

An expectation for checking that an element is either invisible or not present on the DOM.

How can I make this line robust?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions