renatoathaydes / Automaton

Simple framework which allows the testing of Swing and JavaFX2 applications.
Apache License 2.0
100 stars 21 forks source link

Provide arguments to starting Application #39

Closed akabachkov closed 8 years ago

akabachkov commented 8 years ago

FXApp.startApp( Application app, String... args ) does not pass arguments to app.

renatoathaydes commented 8 years ago

It is not possible to pass the arguments to the actual application as the JavaFX API only allows for calling start(Stage stage) on an existing application instance... one solution would be to use the Groovy metaclass to override the getParameters() method of Application, which would work only from Groovy (not from Java code), so your Application would need to be written in Groovy.

Would that help you?

If not, the best I can do is make the parameters available from FXApp, but you probably won't be able to use it from the real App...

Would it be enough in your case?

akabachkov commented 8 years ago

What about add next line ParametersImpl.registerParameters(app, new ParametersImpl(Arrays.asList(params))); inside FXApp.startApp()?

renatoathaydes commented 8 years ago

Hm... that's undocumented behaviour and not part of the JavaFX API... so it could break in different OSs and different JavaFX versions... not sure it's worth it.

renatoathaydes commented 8 years ago

I decided to call this unsafe method in a kind of safe way (by reflection) so that if this class ParametersImpl does not exists in a JVM, FXAutomaton will still work, but the parameters will not be set... this is for Java Applications. For Groovy Applications, it will always work.