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

Unable to interact with FileChooser #715

Open
aimran50 opened this issue Nov 30, 2020 · 3 comments
Open

Unable to interact with FileChooser #715

aimran50 opened this issue Nov 30, 2020 · 3 comments

Comments

@aimran50
Copy link

File chooser is declared inside the controller class:

  • FileChooser fileChooser = new FileChooser();

User clicks the add button which opens the file chooser. Returned files are then processed
public void add() {
List files = fileChooser.showOpenMultipleDialog(stage);
process(files);
}

After the file chooser is launched, TestFX is unable to interact with the file chooser. clickOn, doubleClickOn, press or write don't work. I am not even able to close the chooser dialog.

I need the test to select a file and return back. How can this be achieved?

Expected Behavior

Select a file and return

Actual Behavior

Does nothing

To get the fastest possible support, create a minimal example
and upload it to GitHub.

Specifications

  • Version:
  • Platform:
@ArchibaldBienetre
Copy link

ArchibaldBienetre commented Oct 10, 2021

Facing the same issue.

Googling, I found this variant of FileChooser, claiming to be testable using TestFX.

I don't know yet if it's any good, or if there are better options.
https://oliver-loeffler.github.io/FXFileChooser/
https://github.com/Oliver-Loeffler/FXFileChooser

@Oliver-Loeffler
Copy link
Contributor

Oliver-Loeffler commented Oct 11, 2021

I think, JavaFX uses the platforms native file chooser. Hence, the robot is not able to interact with these elements.
Other than writing an adapter class to the native file chooser, I also have no clue how to make a (most likely) native component testable.

May be this is something to be discussed also for JavaFX/OpenJFX in general.

Besides that, the FXFileChooser is currently kind of outdated and requires some more care to get it into shape. Nevertheless, its plain JavaFX inside and as such it can be tested using TestFX. But it's still on JavaFX8 and Java8.

@Isfirs
Copy link

Isfirs commented Oct 25, 2021

My solution was to abstract the file choosing logic away using an interface. When testing, I set up a mock instance which will return the file I want for this test. Works perfectly fine.

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

No branches or pull requests

4 participants