Skip to content

Conversation

@Artur-
Copy link
Member

@Artur- Artur- commented Oct 7, 2025

Fixes #2033

When using ElementQuery with conditions like withPropertyValue(),
calling first() or get(index) would fail if the element at that
DOM position didn't match the condition.

This happened because the JavaScript [index] was applied before
Java-side condition filtering, so it would extract the wrong element
and then filter it out.

Fixed by:
- Modified get(int index) to check if conditions exist
- When conditions exist, fetch all elements and apply index after filtering
- When no conditions exist, use the optimized JavaScript [index] path

Added integration tests to verify withPropertyValue().first() and
withPropertyValue().get(0) work correctly.

Fixes #2033
@mshabarov
Copy link
Contributor

Fixes #2033.

@mshabarov mshabarov requested a review from tepi October 13, 2025 11:46
@tepi
Copy link
Contributor

tepi commented Nov 4, 2025

Needs formatting + some tests are failing

@Artur-
Copy link
Member Author

Artur- commented Nov 4, 2025

formatted and merged main, let's see if tests still fail

@github-actions
Copy link

github-actions bot commented Nov 4, 2025

Test Results

  134 files   -  33    134 suites   - 33   57s ⏱️ - 1h 3m 44s
  982 tests  - 169    961 ✅  - 182  1 💤  - 5  20 ❌ +20 
1 352 runs   - 250  1 331 ✅  - 260  1 💤  - 8  20 ❌ +20 

For more details on these failures, see this check.

Results for commit 5c5fcde. ± Comparison against base commit d623dc1.

This pull request removes 169 tests.
com.vaadin.testbench.unit.quarkus.QuarkusSecurityCustomizerTest ‑ hasRole_allRoles_authenticatedUser_getsTrue
com.vaadin.testbench.unit.quarkus.QuarkusSecurityCustomizerTest ‑ hasRole_anonymousUser_getsFalse
com.vaadin.testbench.unit.quarkus.QuarkusSecurityCustomizerTest ‑ hasRole_matchExactRole
com.vaadin.testbench.unit.quarkus.QuarkusUIUnitBaseClassTest ‑ extendingBaseClass_runTest_vaadinMockingIsSetup
com.vaadin.testbench.unit.quarkus.QuarkusUIUnitBaseClassTest ‑ extendingBaseClass_runTest_viewDependencyInjectionWorks
com.vaadin.testbench.unit.quarkus.QuarkusUnitSecurityTest ‑ witAnonymousUser_noAuthenticationInformation
com.vaadin.testbench.unit.quarkus.QuarkusUnitSecurityTest ‑ withAnonymousUser_navigateToProtectedView_redirectToLogin
com.vaadin.testbench.unit.quarkus.QuarkusUnitSecurityTest ‑ withAnonymousUser_redirectToLogin
com.vaadin.testbench.unit.quarkus.QuarkusUnitSecurityTest ‑ withMockUser_anyRoleProtectedView_roleNotAssigned_viewNotFound
com.vaadin.testbench.unit.quarkus.QuarkusUnitSecurityTest ‑ withMockUser_landOnProtectedHomeView
…

♻️ This comment has been updated with latest results.

Artur- and others added 2 commits November 4, 2025 15:10
When ElementQuery uses Java-side conditions (like withLabel, withText,
withPropertyValue, etc.), the JavaScript query must return ALL matching
elements so that Java can apply the predicates for filtering.

The tests were incorrectly expecting the script to end with ";return result[0]"
for all .first() calls. For queries with conditions, the script correctly
ends with ";return result" (all elements), and then Java applies filtering
and indexing.

Fixed by updating test helper methods findFirstConditionInElement() and
findFirstConditionInDocument() to expect SINGLE_RESULT_QUERY_SUFFIX instead
of FIRST_RESULT_QUERY_SUFFIX.

This fixes 20 failing tests in ElementQueryTest related to condition-based
queries.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
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

Successfully merging this pull request may close these issues.

ElementQuery#get not working with conditions

4 participants