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

Checks for disabled select/option when using selectOption* methods #1553

Closed
wants to merge 3 commits into from

Conversation

bereg2k
Copy link
Contributor

@bereg2k bereg2k commented Sep 4, 2021

Changes

Before:

SelenideElement.selectOption* methods used underlying Selenium's Select.setSelected() method that simply clicked on the option. If <select> element was disabled or the selected <option> was disabled , no exceptions were raised, and the test continued.

Now:

All SelenideElement.selectOption* methods will throw InvalidStateException if the test selects an option either from disabled <select> element or the <option> itself is disabled.

@bereg2k bereg2k marked this pull request as ready for review September 4, 2021 09:52
@asolntsev asolntsev self-requested a review September 9, 2021 05:46
@asolntsev asolntsev self-assigned this Sep 9, 2021
@asolntsev
Copy link
Member

asolntsev commented Sep 9, 2021

@bereg2k The implementation looks good.
I am in doubt because of 2 things:

  1. These additional checks will make tests slower (every call to isEnabled etc. executes additional http request)
    (though, the current implementation already executes quite a lot of http requests).
  2. Now Selenide code contains some lines copied from Selenium projects (all these xpaths for searching options by index/texts) which may be changed on Selenium side at any moment. By the way, they are already different (see select.selectByVisibleText implementation).

NB! Probably we should just implement the whole Select logic in JavaScript? Then we don't bother about performance, and can use extendable implementation for supporting all those Bootstrap, Vue.js and other frameworks (which have own select implementations).

@bereg2k
Copy link
Contributor Author

bereg2k commented Sep 9, 2021

@asolntsev

  1. I checked the metrics on the checks of the recent pull request that doesn't add anything similar under the hood, and they are no different in the execution time. See Enhance closest() and ancestor() methods to search by attribute and attribute w/ value #1554 Is it really that slow to bother?
  2. Selenium version 3 had no updates in years. And doesn't Selenide project control the version of Selenium library that it uses via its dependencies? It can stay on the older version as long as needed to implement any additional changes in changed (by Selenium) methods.

@bereg2k
Copy link
Contributor Author

bereg2k commented Sep 9, 2021

Regarding JS implementation.
Will it solve the issue with checking for enabled/disabled states too? My JS skills are pretty basic to get it.

@asolntsev
Copy link
Member

@bereg2k After a long delay, I returned back to this PR.
I tried to implement these checks with JavaScript - it was not trivial. Probably I will finish it some day, but not know.

But I realised that the check for disabled should be implemented on Selenium side, right?
I prepared a PR for Selenium, let's see if they accept it: SeleniumHQ/selenium#10814

Anyway, I am going to merge your PR - at least to have these tests in our test suite.

@bereg2k
Copy link
Contributor Author

bereg2k commented Jun 26, 2022

@asolntsev I think it was a great idea to implement these checks on the Selenium side.
However, we are at crossroads now:

  1. If your CR is approved and merged then my MR is irrelevant. All the exceptions will be thrown by Selenium. Selenide's exception throwing will never be reached. The unit tests in this MR will even fail because your implementation for Selenium is different than mine here.

  2. If your CR is declined and not merged then my MR is serving its original purpose. But everything else is true what you've mentioned here: it copies the Selenium code that might be changed/outdated, especially in ver. 4 (I haven't checked it yet); it might slow down the tests, etc. Maybe it would be better to proceed with your JS-implementation idea.

@asolntsev
Copy link
Member

@bereg2k No problems in both cases. :)

  1. If the PR gets merged (it will likely happen), it's still good to have your tests. We will just need to refactor them a bit.
  2. Yes, these checks might slow down the tests, but it's better to have slow correct tests than fast incorrect. If this PR gets rejected, I would create another PR to extract some pieces of Select into smaller methods, so that we could reuse/call them in Selenide.

Yes, I will try to continue my work with JS implementation. We'll see how easy it is.

@bereg2k
Copy link
Contributor Author

bereg2k commented Jun 27, 2022

@asolntsev Ok, if you mean to make changes to this PR so it would work somehow, then yes, it's totally reasonable.

And if you need me to make any specific changes to this feature, let me know.

asolntsev added a commit that referenced this pull request Jun 29, 2022
+ check that neither select nor option is disabled
@asolntsev
Copy link
Member

@bereg2k I have committed my JS implementation for review: #1876

@asolntsev
Copy link
Member

@bereg2k The PR has been merged in Selenium. Apparently will be released soon.

asolntsev added a commit that referenced this pull request Oct 8, 2022
asolntsev added a commit that referenced this pull request Oct 8, 2022
# Conflicts:
#	statics/src/test/java/integration/SelectsTest.java
asolntsev added a commit that referenced this pull request Oct 8, 2022
@asolntsev
Copy link
Member

@bereg2k FYI The check for disabled attribute of <select> and <option> was added in Selenium 4.5.0 (Selenide 6.9.0).
See commit ff88671fb8c and 25b30ffa665.

Though the implementation is a bit different from yours (it throws UnsupportedOperationException with not-so-readable error message. And it doesn't allow negative checks (because it throws exception right from constructor).

Let's leave this PR open because the discussion continues...

@bereg2k
Copy link
Contributor Author

bereg2k commented Oct 9, 2022

@asolntsev Thanks for the heads-up.
They went in the weird direction when removing the "assert" methods and placing that check into the Select constructor...

Would it be reasonable to catch such exceptions, and handle them a bit more gracefully to provide the ability for negative checks and readable assertion error messages?

@asolntsev
Copy link
Member

@bereg2k Let's for wait the discussion result.
If it doesn't end up as we expect, we can always copy Select class and change it, or go on with JS implementation.

asolntsev added a commit that referenced this pull request Oct 12, 2022
now select is implemented with JS code, and this functionality is covered by integration tests.
asolntsev added a commit that referenced this pull request Oct 14, 2022
asolntsev added a commit that referenced this pull request Nov 2, 2022
+ check that neither select nor option is disabled
asolntsev added a commit that referenced this pull request Nov 2, 2022
asolntsev added a commit that referenced this pull request Nov 2, 2022
now select is implemented with JS code, and this functionality is covered by integration tests.
asolntsev added a commit that referenced this pull request Nov 2, 2022
asolntsev added a commit that referenced this pull request Nov 2, 2022
+ check that neither select nor option is disabled
asolntsev added a commit that referenced this pull request Nov 2, 2022
asolntsev added a commit that referenced this pull request Nov 2, 2022
now select is implemented with JS code, and this functionality is covered by integration tests.
asolntsev added a commit that referenced this pull request Nov 2, 2022
@asolntsev
Copy link
Member

Overseeded by #1876

@asolntsev asolntsev closed this Nov 2, 2022
@asolntsev asolntsev added this to the 6.10.0 milestone Nov 2, 2022
@bereg2k bereg2k deleted the check_select_enabled branch November 2, 2022 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants