leancodepl / patrol

Flutter-first UI testing framework. Ready for action!
https://patrol.leancode.co
Apache License 2.0
814 stars 116 forks source link

allCandidates() function always returns candidates starting from root widget regardless of the selected PatrolFinder #2224

Closed SafronovA closed 2 weeks ago

SafronovA commented 2 weeks ago

Steps to reproduce

Common issue

Actual results

Description: I have 3 Cell on the screen (same widget class, different content) $(Cell).evaluate().length = 3 $(Cell).allCandidates.length = 600 <--- as I understand, each cell widget contains 200 child elements.

Then I'm trying to work with a separate cell (let it be the second cell): $(Cell).at(1).evaluate().length = 1 <--- expected. $(Cell).at(1).allCandidates.length = 600 <--- NOT expected. Why 600 again? I expect 200 here... =(


The use case: I'm trying to work with Widgets as Objects (as WebElements in Appium (Java)) and I need to cut pieces of page source code somehow.

Source code example: root: cellsList: cell: content cell: content cell: content

As a result, I want to have 3 pieces of source code (parent 'Cell' widget with its content) to init 3 objects of the "page object" class to work with each of the cells separately.

Logs

Logs Logs have no sense here

Patrol version

patrol_cli v2.7.0

Patrol Doctor output

Patrol Doctor output Patrol doctor: Patrol CLI version: 2.7.0 Flutter command: flutter Flutter 3.22.1 • channel stable Android: • Program adb found in /Users/me/Library/Android/sdk/platform-tools/adb • Env var $ANDROID_HOME set to /Users/me/Library/Android/sdk iOS / macOS: • Program xcodebuild found in /usr/bin/xcodebuild • Program ideviceinstaller found in /opt/homebrew/bin/ideviceinstaller

Flutter Doctor output

Flutter Doctor output Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.22.1, on macOS 14.5 23F79 darwin-arm64, locale en-PL) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 15.3) [✓] Chrome - develop for the web [✓] Android Studio (version 2023.1) [✓] IntelliJ IDEA Community Edition (version 2023.3.3) [✓] VS Code (version 1.90.0) [✓] Connected device (4 available) [✓] Network resources
jBorkowska commented 2 weeks ago

Hi @SafronovA ! This is correct behaviour. All candidates means all widgets that will be analyzed by this finder -> all widgets in current widget tree. The name maybe a bit misleading, but this method originates from flutter_test package, so there's nothing we can do. If you need to retrieve specific widgets, use $(something).evaluate().first.widget.

Closing the issue, if you need help with your use case please join our Discord channel: https://discord.gg/ukBK5t4EZg

SafronovA commented 2 weeks ago

Oh, got you... Unfortunately, after '$(something).evaluate()' there is no way how to continue finding elements by PatrolFinder. The only way I saw was using 'findInCandidates()' function, but it has lost sense if we can't get 'allCandidates()' from some specific widget

github-actions[bot] commented 1 week ago

This issue has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar problem, please file a new issue. Make sure to follow the template and provide all the information necessary to reproduce the issue.

jBorkowska commented 3 days ago

Hi, sorry for coming back late, I didn't see the comment :(

I'm interested why you need such a thing - if you want to find something that is inside another widget, you can just chain the finders like $(Center).$(Text). I don't quite understand what do you actually need. If you want to talk about it, let's meet on Discord :)