nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.85k stars 1.34k forks source link

Fix #4223: Restrict suppressNotFoundErrors to NoSuchElementError #4294

Open Vaibhavsahu2810 opened 2 weeks ago

Vaibhavsahu2810 commented 2 weeks ago

Description

This pull request addresses issue #4223. The suppressNotFoundErrors property in the new Element API previously suppressed all errors encountered by the WebDriver, including errors like InvalidSelectorError. This behavior was unintended, as suppressNotFoundErrors should ideally only suppress NoSuchElementError.

Changes Made

Updated scoped-element.js to catch and handle NoSuchElementError specifically when suppressNotFoundErrors is enabled. Modified the logic to allow other errors, like InvalidSelectorError, to propagate as expected.

Steps to Reproduce the Issue

Use an invalid selector in a test command: await browser.element.find({ selector: '@something', suppressNotFoundErrors: true }); Observe that InvalidSelectorError is no longer suppressed and propagates as intended.

Proof of Work

Terminal Output The attached screenshot shows the updated terminal output, where an InvalidSelectorError is correctly thrown when an invalid selector is provided.

Screenshot 2024-11-09 at 1 04 26 AM

Unit Test A unit test was added to ecosia.js to validate this behavior. The test checks that an invalid selector throws InvalidSelectorError instead of suppressing it.

Screenshot 2024-11-09 at 1 04 50 AM

Thanks in advance for your contribution. Please follow the below steps in submitting a pull request, as it will help us with reviewing it quicker.

CLAassistant commented 2 weeks ago

CLA assistant check
All committers have signed the CLA.

garg3133 commented 1 week ago

Once this is fixed, the next step would be to provide more information along with the error so that the user can easily figure out where this error is coming from. In its current state, the error itself does not tell anything about its origin and which command/selector went wrong.

image

Vaibhavsahu2810 commented 6 days ago

@garg3133 is this okay now, I have made all the changes that are needed Thanks!