|
31 | 31 | import java.net.URLClassLoader;
|
32 | 32 | import java.util.*;
|
33 | 33 |
|
| 34 | +import static javafxlibrary.utils.HelperFunctions.createThreadedWrapperApplication; |
34 | 35 | import static javafxlibrary.utils.HelperFunctions.createWrapperApplication;
|
35 | 36 | import static javafxlibrary.utils.HelperFunctions.getMainClassFromJarFile;
|
36 | 37 |
|
@@ -66,21 +67,40 @@ public void launchJavafxApplication(String appName, String... appArgs) {
|
66 | 67 | @ArgumentNames({"appName", "*args"})
|
67 | 68 | public void launchSwingApplication(String appName, String... appArgs) {
|
68 | 69 | RobotLog.info("Starting application:" + appName);
|
69 |
| - Class c; |
| 70 | + Class c = getMainClass(appName); |
| 71 | + Application app = createWrapperApplication(c, appArgs); |
| 72 | + createNewSession(app); |
| 73 | + RobotLog.info("Application: " + appName + " started."); |
| 74 | + } |
| 75 | + |
| 76 | + @RobotKeyword("Creates a wrapper application the same way as in `Launch Swing Application`, but starts it in a new " + |
| 77 | + "thread. This is required when main method of the test application is blocked and execution does not " + |
| 78 | + "return after calling it until the application gets closed. Be sure to set the library timeout with " + |
| 79 | + "`Set Timeout` so that the test application will have enough time to load, as the test execution will " + |
| 80 | + "continue instantly after calling the main method.\n\n" |
| 81 | + + "``appName`` is the name of the application to launch. \n\n" |
| 82 | + + "``appArgs`` is a list of arguments to be passed for the application. \n\n" |
| 83 | + + "Example:\n" |
| 84 | + + "| Launch Swing Application In Separate Thread | _javafxlibrary.testapps.SwingApplication |\n" |
| 85 | + + "| Launch Swing Application In Separate Thread | _TestApplication.jar_ |\n") |
| 86 | + @ArgumentNames({"appName", "*args"}) |
| 87 | + public void launchSwingApplicationInSeparateThread(String appName, String... appArgs) { |
| 88 | + RobotLog.info("Starting application:" + appName); |
| 89 | + Class c = getMainClass(appName); |
| 90 | + Application app = createThreadedWrapperApplication(c, appArgs); |
| 91 | + createNewSession(app); |
| 92 | + RobotLog.info("Application: " + appName + " started."); |
| 93 | + } |
70 | 94 |
|
| 95 | + private Class getMainClass(String appName) { |
71 | 96 | try {
|
72 | 97 | if (appName.endsWith(".jar"))
|
73 |
| - c = getMainClassFromJarFile(appName); |
| 98 | + return getMainClassFromJarFile(appName); |
74 | 99 | else
|
75 |
| - c = Class.forName(appName); |
76 |
| - |
| 100 | + return Class.forName(appName); |
77 | 101 | } catch (ClassNotFoundException e) {
|
78 | 102 | throw new JavaFXLibraryNonFatalException("Unable to launch application: " + appName, e);
|
79 | 103 | }
|
80 |
| - |
81 |
| - Application app = createWrapperApplication(c, appArgs); |
82 |
| - createNewSession(app); |
83 |
| - RobotLog.info("Application: " + appName + " started."); |
84 | 104 | }
|
85 | 105 |
|
86 | 106 | private void _addPathToClassPath(String path) {
|
|
0 commit comments