Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isPresent command misleading, works same as waitUntilElementPresent #4185

Closed
reallymello opened this issue Apr 10, 2024 · 2 comments
Closed

Comments

@reallymello
Copy link
Contributor

Description of the bug/issue

When I use const elementIsHere = browser.element('#myElement').isPresent() I expect a boolean of true or false to be returned to the elementIsHere constant variable, but if the element is not present in the DOM within the timeout the test returns an element not found exception. Suppress not found errors does not help in this instance. It's implied through the name it should return true if present and false if not.

There are cases in our testing where we sometimes need to branch logic when there are A/B versions of the UI served so the test can handle it. So, for example, if "something" is present then do this / else do something else.

.isPresent in its current form works the same as .waitUntilElementPresent() which I'd argue serve or should serve different purposes--the former should handle cases where the element may never be present where the latter expects that it should eventually appear within the timeout.

As a workaround I end up using findElements with a compound selector of something guaranteed to be in the DOM and the selector I'm waiting for then I see if the length of the elements found is greater than 1 which works but not as direct.

Steps to reproduce

In a test use

const elementIsHere = browser.element('#this-doesnt-exist').isPresent()

The test will throw a not found exception instead of setting elementIsHere to false.

Sample test

No response

Command to run

No response

Verbose Output

No response

Nightwatch Configuration

No response

Nightwatch.js Version

3.5

Node Version

20

Browser

Chrome 123

Operating System

Windows 11

Additional Information

No response

@AutomatedTester
Copy link
Member

Looking at this, since you're using element(...) it's not really getting to the point where it does isPresent is called. element(...) will do auto waiting for you which leads to it acting like waitUntilElementPresent. This is

closing this as by design.

@garg3133
Copy link
Member

We also have #4055 that is going to serve exactly that purpose, it would only return true or false results instead of throwing an error when the element is not found.

There is already an active PR on the issue which we hope to merge and release soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants