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

User can safely call addRequestFilter/addResponseFilter with the same filter #2617

Closed
asolntsev opened this issue Jan 24, 2024 · 0 comments · Fixed by #2630
Closed

User can safely call addRequestFilter/addResponseFilter with the same filter #2617

asolntsev opened this issue Jan 24, 2024 · 0 comments · Fixed by #2630
Assignees
Milestone

Comments

@asolntsev
Copy link
Member

The problem

Every time when I call open(url) in my tests, I want to add a proxy filter.
But Selenide doesn't allow adding multiple filters with the same name.
So I need to add an IF like this:

open();
if (getSelenideProxy().requestFilter("request-logger") == null) {
  getSelenideProxy().addRequestFilter("request-logger", MY_LOGGER);
}

Solution

Method addRequestFilter could silently ignore without throwing an error IF the filter is exactly the same instance as previously.
Then I could safely add getSelenideProxy().addRequestFilter("request-logger", MY_CONSTANT_LOGGER); all over my tests.

@asolntsev asolntsev added this to the 7.1.0 milestone Jan 28, 2024
asolntsev added a commit that referenced this issue Jan 28, 2024
it's convenient to store a filter into a constant, and add it before every `open(url)` - without checking if it was already added earlier.

```
var MY_CONSTANT_LOGGER = new RequestFilter() {...}
getSelenideProxy().addRequestFilter("request-logger", MY_CONSTANT_LOGGER);
```
@asolntsev asolntsev linked a pull request Jan 28, 2024 that will close this issue
@asolntsev asolntsev self-assigned this Jan 28, 2024
asolntsev added a commit that referenced this issue Jan 29, 2024
it's convenient to store a filter into a constant, and add it before every `open(url)` - without checking if it was already added earlier.

```
var MY_CONSTANT_LOGGER = new RequestFilter() {...}
getSelenideProxy().addRequestFilter("request-logger", MY_CONSTANT_LOGGER);
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant