Skip to content

Commit c58f019

Browse files
committed
Add RobotLog class for logging messages to Robot Framework log files
New RobotLog class replaces the HelperFunctions.robotLog method.
1 parent 5c2bd12 commit c58f019

25 files changed

+274
-378
lines changed

src/main/java/JavaFXLibrary.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import javafxlibrary.exceptions.JavaFXLibraryNonFatalException;
2626
import javafxlibrary.keywords.AdditionalKeywords.RunOnFailure;
2727
import javafxlibrary.utils.HelperFunctions;
28+
import javafxlibrary.utils.RobotLog;
2829
import javafxlibrary.utils.TestListener;
2930
import org.apache.commons.io.FileUtils;
3031
import org.robotframework.javalib.annotation.Autowired;
@@ -73,13 +74,13 @@ public Object runKeyword(String keywordName, Object[] args) {
7374
} catch (RuntimeException e) {
7475
runOnFailure.runOnFailure();
7576
if (e.getCause() instanceof JavaFXLibraryFatalException) {
76-
robotLog("DEBUG", "JavaFXLibrary: Caught JavaFXLibrary FATAL exception");
77+
RobotLog.debug("JavaFXLibrary: Caught JavaFXLibrary FATAL exception");
7778
throw e;
7879
} else if (e.getCause() instanceof JavaFXLibraryNonFatalException) {
79-
robotLog("DEBUG", "JavaFXLibrary: Caught JavaFXLibrary NON-FATAL exception");
80+
RobotLog.debug("JavaFXLibrary: Caught JavaFXLibrary NON-FATAL exception");
8081
throw e;
8182
} else {
82-
robotLog("DEBUG", "JavaFXLibrary: Caught JavaFXLibrary RUNTIME exception");
83+
RobotLog.debug("JavaFXLibrary: Caught JavaFXLibrary RUNTIME exception");
8384
throw e;
8485
}
8586
}

src/main/java/javafxlibrary/keywords/AdditionalKeywords/ApplicationLauncher.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import javafx.application.Application;
2121
import javafxlibrary.exceptions.JavaFXLibraryFatalException;
2222
import javafxlibrary.exceptions.JavaFXLibraryNonFatalException;
23-
import javafxlibrary.utils.HelperFunctions;
23+
import javafxlibrary.utils.RobotLog;
2424
import javafxlibrary.utils.TestFxAdapter;
2525
import org.robotframework.javalib.annotation.ArgumentNames;
2626
import org.robotframework.javalib.annotation.RobotKeyword;
@@ -33,7 +33,6 @@
3333

3434
import static javafxlibrary.utils.HelperFunctions.createWrapperApplication;
3535
import static javafxlibrary.utils.HelperFunctions.getMainClassFromJarFile;
36-
import static javafxlibrary.utils.HelperFunctions.robotLog;
3736

3837
@RobotKeywords
3938
public class ApplicationLauncher extends TestFxAdapter {
@@ -47,10 +46,9 @@ public class ApplicationLauncher extends TestFxAdapter {
4746
@ArgumentNames({"appName", "*args"})
4847
public void launchJavafxApplication(String appName, String... appArgs) {
4948
try {
50-
HelperFunctions.robotLog("INFO", "Starting application:" + appName);
49+
RobotLog.info("Starting application:" + appName);
5150
createNewSession(appName, appArgs);
52-
HelperFunctions.robotLog("INFO", "Application: " + appName + " started.");
53-
51+
RobotLog.info("Application: " + appName + " started.");
5452
} catch (Exception e) {
5553
throw new JavaFXLibraryNonFatalException("Unable to launch application: " + appName, e);
5654
}
@@ -67,7 +65,7 @@ public void launchJavafxApplication(String appName, String... appArgs) {
6765
+ "| Launch Swing Application | _TestApplication.jar_ |\n")
6866
@ArgumentNames({"appName", "*args"})
6967
public void launchSwingApplication(String appName, String... appArgs) {
70-
HelperFunctions.robotLog("INFO", "Starting application:" + appName);
68+
RobotLog.info("Starting application:" + appName);
7169
Class c;
7270

7371
try {
@@ -82,15 +80,15 @@ public void launchSwingApplication(String appName, String... appArgs) {
8280

8381
Application app = createWrapperApplication(c, appArgs);
8482
createNewSession(app);
85-
HelperFunctions.robotLog("INFO", "Application: " + appName + " started.");
83+
RobotLog.info("Application: " + appName + " started.");
8684
}
8785

8886
private void _addPathToClassPath(String path) {
8987
URLClassLoader classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
9088

91-
HelperFunctions.robotLog("INFO", "Setting following path to Classpath: " + path );
89+
RobotLog.info("Setting following path to Classpath: " + path);
9290

93-
try{
91+
try {
9492
Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
9593
method.setAccessible(true);
9694
method.invoke(classLoader, (new File(path)).toURI().toURL() );
@@ -110,10 +108,12 @@ private void _addPathToClassPath(String path) {
110108
public void setToClasspath(String path) {
111109
if (path.endsWith("*")) {
112110
path = path.substring(0, path.length() - 1);
113-
HelperFunctions.robotLog("INFO", "Adding all jars from directory: " + path );
111+
RobotLog.info("Adding all jars from directory: " + path);
112+
114113
try {
115114
File directory = new File(path);
116115
File[] fileList = directory.listFiles();
116+
117117
for (File file : fileList) {
118118
if (file.getName().endsWith(".jar"))
119119
_addPathToClassPath(file.getAbsolutePath());
@@ -132,10 +132,9 @@ public void logApplicationClasspath() {
132132
try {
133133
ClassLoader cl = ClassLoader.getSystemClassLoader();
134134
URL[] urls = ((URLClassLoader) cl).getURLs();
135-
HelperFunctions.robotLog("INFO", "Printing out classpaths: \n");
136-
for (URL url : urls) {
137-
HelperFunctions.robotLog("INFO", url.getFile());
138-
}
135+
RobotLog.info("Printing out classpaths: \n");
136+
for (URL url : urls)
137+
RobotLog.info(url.getFile());
139138
} catch (Exception e) {
140139
throw new JavaFXLibraryNonFatalException("Unable to log application classpaths", e);
141140
}
@@ -174,7 +173,7 @@ public void logSystemProperties() {
174173
while (keys.hasMoreElements()) {
175174
String key = (String) keys.nextElement();
176175
String value = (String) p.get(key);
177-
HelperFunctions.robotLog("INFO", key + "=" + value);
176+
RobotLog.info(key + "=" + value);
178177
}
179178
} catch (Exception e) {
180179
throw new JavaFXLibraryNonFatalException("Unable to log system properties", e);
@@ -187,9 +186,9 @@ public void logSystemProperties() {
187186
public void closeJavafxApplication() {
188187

189188
try {
190-
HelperFunctions.robotLog("INFO", "Closing application...");
189+
RobotLog.info("Closing application...");
191190
deleteSession();
192-
HelperFunctions.robotLog("INFO", "Application closed.");
191+
RobotLog.info("Application closed.");
193192
} catch (Exception e) {
194193
throw new JavaFXLibraryNonFatalException("Unable to close Java FX application.", e);
195194
}
@@ -200,17 +199,17 @@ public void closeJavafxApplication() {
200199
+ "| Close Swing Application | \n")
201200
public void closeSwingApplication() {
202201
try {
203-
HelperFunctions.robotLog("INFO", "Closing application...");
202+
RobotLog.info("Closing application...");
204203
deleteSwingSession();
205-
HelperFunctions.robotLog("INFO", "Application closed.");
204+
RobotLog.info("Application closed.");
206205
} catch (Exception e) {
207206
throw new JavaFXLibraryNonFatalException("Unable to close JavaFXLibrary Swing Wrapper application.", e);
208207
}
209208
}
210209

211210
@RobotKeyword("Clears internal book keeping of all java objects.")
212211
public void clearObjectMap() {
213-
robotLog("INFO", "Clearing " + objectMap.size() + " objects from objectMap.");
212+
RobotLog.info("Clearing " + objectMap.size() + " objects from objectMap.");
214213
objectMap.clear();
215214
}
216215

0 commit comments

Comments
 (0)