Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3635cec

Browse files
authored
Merge pull request #48 from eficode/screenshot_and_other_fixes
Screenshot and other fixes
2 parents 4a16eb3 + 09054a9 commit 3635cec

File tree

13 files changed

+81
-469
lines changed

13 files changed

+81
-469
lines changed

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

+20-18
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,19 @@ private void _addPathToClassPath(String path) {
122122

123123
@RobotKeyword("Loads given path to classpath.\n\n"
124124
+ "``path`` is the path to add.\n\n"
125+
+ "``failIfNotFound`` is either True or False, default False. In case of False error is written as warning.\n\n"
125126
+ "If directory path has asterisk(*) after directory separator all jar files are added from directory.\n"
126127
+ "\nExample:\n"
127128
+ "| Set To Classpath | C:${/}users${/}my${/}test${/}folder | \n"
128-
+ "| Set To Classpath | C:${/}users${/}my${/}test${/}folder${/}* | \n")
129-
@ArgumentNames({ "path" })
130-
public void setToClasspath(String path) {
129+
+ "| Set To Classpath | C:${/}users${/}my${/}test${/}folder${/}* | \n"
130+
+ "| Set To Classpath | C:${/}users${/}my${/}test${/}folder2${/}* | failIfNotFound=${True} | \n")
131+
@ArgumentNames({ "path", "failIfNotFound=False" })
132+
public void setToClasspath(String path, boolean failIfNotFound) {
133+
RobotLog.info("Setting \"" + path + "\" to classpath, failIfNotFound=\"" + failIfNotFound + "\"");
131134
if (path.endsWith("*")) {
132135
path = path.substring(0, path.length() - 1);
133-
RobotLog.info("Adding all jars from directory: " + path);
136+
RobotLog.info("Adding all jars from directory.");
137+
String fullPath = FileSystems.getDefault().getPath(path).normalize().toAbsolutePath().toString();
134138

135139
try {
136140
File directory = new File(path);
@@ -143,11 +147,20 @@ public void setToClasspath(String path) {
143147
}
144148
}
145149
if (!jarsFound) {
146-
throw new JavaFXLibraryNonFatalException("No jar files found from classpath: "
147-
+ FileSystems.getDefault().getPath(path).normalize().toAbsolutePath().toString());
150+
String jarsNotFoundError = "No jar files found from classpath: " + fullPath;
151+
if (failIfNotFound) {
152+
throw new JavaFXLibraryNonFatalException(jarsNotFoundError);
153+
} else {
154+
RobotLog.warn(jarsNotFoundError);
155+
}
148156
}
149157
} catch (NullPointerException e) {
150-
throw new JavaFXLibraryFatalException("Directory not found: " + path + "\n" + e.getMessage(), e);
158+
String directoryNotFoundError = "Directory not found: " + fullPath;
159+
if (failIfNotFound) {
160+
throw new JavaFXLibraryFatalException(directoryNotFoundError);
161+
} else {
162+
RobotLog.warn(directoryNotFoundError);
163+
}
151164
}
152165
} else {
153166
_addPathToClassPath(path);
@@ -250,17 +263,6 @@ public String getCurrentApplication() {
250263
}
251264
}
252265

253-
@Deprecated
254-
@RobotKeyword("*DEPRECATED in version 0.6.0!* Use `Get Current Application` keyword instead.\n\n"
255-
+ "Returns the class name of currently active JavaFX Application\n")
256-
public String currentApplication() {
257-
try {
258-
return getCurrentSessionApplicationName();
259-
} catch (Exception e) {
260-
throw new JavaFXLibraryNonFatalException("Problem getting current application name.", e);
261-
}
262-
}
263-
264266
@RobotKeyword("Returns if JavaFXLibrary is started as java agent.")
265267
public boolean isJavaAgent() {
266268
return TestFxAdapter.isAgent;

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

+18-227
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,6 @@
5454
@RobotKeywords
5555
public class ConvenienceKeywords extends TestFxAdapter {
5656

57-
@Deprecated
58-
@RobotKeyword("*DEPRECATED in version 0.6.0!* Use keyword `Find` instead.\n\n" +
59-
"finder that mimics _xpath_ style search.\n\n"
60-
+ "``query`` is a query locator, see `3.1 Locator syntax`.\n\n"
61-
+ "``failIfNotFound`` specifies if keyword should fail if nothing is found. By default it's false and "
62-
+ "keyword returns null in case lookup returns nothing.\n\n"
63-
+ "\nExample:\n"
64-
+ " | ${node}= | Find With Path | .main-view[0] .split-pane[0] \\#node-id class=GridPane .toggle-button[3] sometext | ")
65-
@ArgumentNames({"query", "failIfNotFound=False"})
66-
public Object findWithPath(String query, boolean failIfNotFound){
67-
68-
try {
69-
return mapObject(findNode(query));
70-
71-
} catch (JavaFXLibraryNonFatalException e){
72-
if(failIfNotFound)
73-
throw new JavaFXLibraryNonFatalException("Unable to find anything with query: \"" + query + "\"");
74-
return "";
75-
76-
} catch (Exception e) {
77-
throw new JavaFXLibraryNonFatalException("Find operation failed for query: \"" + query + "\"", e);
78-
}
79-
}
80-
8157
@RobotKeyword("Brings the given stage to front\n\n"
8258
+ "``stage`` is an Object:Stage to be set in front of others, see `3.2 Using locators as keyword arguments`. \n\n")
8359
@ArgumentNames({ "stage" })
@@ -130,116 +106,6 @@ public void callObjectMethodInFxApplicationThread(Object object, String method,
130106
callMethod(object, method, finalArgs, true);
131107
}
132108

133-
@Deprecated
134-
@RobotKeyword("*DEPRECATED in version 0.6.0!* Use keyword `Find` instead.\n\n"
135-
+ "Returns the *first* node matching the query. \n\n"
136-
+ "``query`` is the Class name String to use in lookup.\n"
137-
+ "\nExample:\n"
138-
+ "| ${my node}= | Find | javafx.scene.control.Button | # button class |")
139-
@ArgumentNames({ "query" })
140-
public Object findClass(final String query) {
141-
try {
142-
Class<?> clazz = Class.forName(query);
143-
InstanceOfMatcher matcher = new InstanceOfMatcher(clazz);
144-
return mapObject(robot.lookup(matcher).query());
145-
} catch (Exception e) {
146-
RobotLog.trace("Problem has occurred during node lookup: " + e);
147-
return "";
148-
}
149-
}
150-
151-
@Deprecated
152-
@RobotKeyword("*DEPRECATED in version 0.6.0!* Use keyword `Find All` instead.\n\n"
153-
+ "Returns *all* descendant nodes of given node matching the query. \n\n"
154-
+ "``node`` is the starting point Object:Node from where to start looking, see `3.2 Using locators as keyword arguments`. \n\n"
155-
+ "``query`` is a query locator, see `3.1 Locator syntax`.\n\n"
156-
+ "``failIfNotFound`` specifies if keyword should fail if nothing is found. By default it's false and "
157-
+ "keyword returns null in case lookup returns nothing.\n\n"
158-
+ "\nExample:\n"
159-
+ "| ${my nodes}= | Find All From Node | ${some node} | .css | \n"
160-
+ "See keyword `Find` for further examples of query usage.\n")
161-
@ArgumentNames({ "node", "query", "failIfNotFound=False" })
162-
public List<Object> findAllFromNode(Object node, String query, boolean failIfNotFound) {
163-
try {
164-
if ( node instanceof Node ) {
165-
RobotLog.info("Trying to find all nodes with query: \"" + query + "\" that are under starting " +
166-
"point node: \"" + node + "\", failIfNotFound= \"" + failIfNotFound + "\"");
167-
return mapObjects(((Node) node).lookupAll(query));
168-
}
169-
// fail in case no valid node argument.
170-
failIfNotFound = true;
171-
throw new JavaFXLibraryNonFatalException("Illegal argument type for node.");
172-
} catch (JavaFXLibraryNonFatalException e){
173-
if(failIfNotFound)
174-
throw e;
175-
return Collections.emptyList();
176-
177-
} catch (Exception e) {
178-
throw new JavaFXLibraryNonFatalException("Find all from node operation failed for node: \"" + node.toString() +
179-
"\" and query: " + query, e);
180-
}
181-
}
182-
183-
@Deprecated
184-
@RobotKeyword("*DEPRECATED in version 0.6.0!* Use keyword `Find All` instead.\n\n"
185-
+ "Returns *all* nodes matching query AND given pseudo-class state. \r\n"
186-
+ "``query`` is a query locator, see `3.1 Locator syntax`.\n\n"
187-
+ "``pseudo`` is a String value specifying pseudo class value.\n\n"
188-
+ "``failIfNotFound`` specifies if keyword should fail if nothing is found. By default it's false and "
189-
+ "keyword returns null in case lookup returns nothing.\n\n"
190-
+ "\nExample:\n"
191-
+ "| ${my node}= | Find All With Pseudo Class | .check-box-tree-cell .check-box | selected | \n")
192-
@ArgumentNames({ "query", "pseudo", "failIfNotFound=False" })
193-
public List<Object> findAllWithPseudoClass(String query, String pseudo, boolean failIfNotFound) {
194-
RobotLog.info("Trying to find all nodes with query: \"" + query + "\" that has pseudoclass state as: \"" +
195-
pseudo + "\", failIfNotFound= \"" + failIfNotFound + "\"");
196-
try {
197-
Set<Node> nodes = robot.lookup(query).queryAll();
198-
Set<Node> matches = nodes.stream()
199-
.filter(n -> n.getPseudoClassStates().stream().
200-
map(PseudoClass::getPseudoClassName).anyMatch(pseudo::contains))
201-
.collect(Collectors.toSet());
202-
return mapObjects(matches);
203-
204-
} catch (JavaFXLibraryNonFatalException e){
205-
if(failIfNotFound)
206-
throw e;
207-
return Collections.emptyList();
208-
209-
} catch (Exception e) {
210-
throw new JavaFXLibraryNonFatalException("Find all with pseudo class operation failed for query: \"" +
211-
query + "\" and pseudo: \"" + pseudo + "\"", e);
212-
}
213-
}
214-
215-
@Deprecated
216-
@RobotKeyword("*DEPRECATED in version 0.6.0!* Use keyword `Find` instead.\n\n"
217-
+ "Returns the *first* descendant node of given node matching the query. \n\n"
218-
+ "``node`` is the starting point Object:Node from where to start looking, see `3.2 Using locators as keyword arguments`. \n\n"
219-
+ "``query`` is a query locator, see `3.1 Locator syntax`.\n\n"
220-
+ "``failIfNotFound`` specifies if keyword should fail if nothing is found. By default it's false and "
221-
+ "keyword returns null in case lookup returns nothing.\n\n"
222-
+ "\nExample:\n"
223-
+ "| ${my node}= | Find From Node | ${some node} | .css |\n"
224-
+ "See keyword `Find` for further examples of query usage.\n")
225-
@ArgumentNames({ "node", "query", "failIfNotFound=False" })
226-
public Object findFromNode(Node node, String query, boolean failIfNotFound) {
227-
RobotLog.info("Trying to find: \"" + query + "\" from node: \"" + node + "\", failIfNotFound= \"" + failIfNotFound + "\"");
228-
try {
229-
Node childNode = node.lookup(query);
230-
return mapObject(childNode);
231-
232-
} catch (JavaFXLibraryNonFatalException e){
233-
if(failIfNotFound)
234-
throw e;
235-
return "";
236-
237-
} catch (Exception e) {
238-
throw new JavaFXLibraryNonFatalException("Find from node operation failed for node: \"" + node +
239-
"\" and query: " + query, e);
240-
}
241-
}
242-
243109
@RobotKeyword("Lists methods available for given node.\n"
244110
+ "``node`` is the Object:Node which methods to list, see `3.2 Using locators as keyword arguments`. \n\n"
245111
+ "When working with custom components you may use this keyword to discover methods you can call "
@@ -390,40 +256,6 @@ public Set<PseudoClass> getPseudoClassStates(Object locator) {
390256
}
391257
}
392258

393-
// TODO: Should this be deleted? Find All From Node has the same functionality
394-
@Deprecated
395-
@RobotKeyword("*DEPRECATED in version 0.6.0!* Use keyword `Find` instead.\n\n"
396-
+ "Returns *all* descendant nodes of given node matching the given Java class name. \n\n"
397-
+ "``locator`` is either a _query_ or _Object_ for node whose children will be queried, see "
398-
+ "`3.2 Using locators as keyword arguments`. \n\n"
399-
+ "``className`` is the Java class name to look for.\n"
400-
+ "\nExample:\n"
401-
+ "| ${panes}= | Get Node Children By Class Name | ${some node} | BorderPane | \n"
402-
+ "Returns an empty list if none is found. \n")
403-
@ArgumentNames({ "node", "className" })
404-
public Set<Object> getNodeChildrenByClassName(Object locator, String className) {
405-
Node node = objectToNode(locator);
406-
RobotLog.info("Getting node: \"" + node + "\" children by class name: \"" + className + "\"");
407-
try {
408-
Set<Object> keys = new HashSet<>();
409-
Set childNodes = node.lookupAll("*");
410-
411-
for (Object o : childNodes) {
412-
Node childNode = (Node) o;
413-
if (childNode.getClass().getSimpleName().equals(className)) {
414-
RobotLog.trace("Classname: \"" + className + "\" found: \"" + childNode + "\"");
415-
keys.add(mapObject(childNode));
416-
}
417-
}
418-
return keys;
419-
} catch (Exception e) {
420-
if(e instanceof JavaFXLibraryNonFatalException)
421-
throw e;
422-
throw new JavaFXLibraryNonFatalException("Unable to get node children for node: \"" + node.toString() +
423-
"\" with class name: " + className, e);
424-
}
425-
}
426-
427259
@RobotKeyword("Returns text value of the Node. \n\n"
428260
+ "``locator`` is either a _query_ or _Object_ for a node whose getText method will be called, see "
429261
+ "`3. Locating JavaFX Nodes`. \n\n")
@@ -441,35 +273,6 @@ public String getNodeText(Object locator) {
441273
}
442274
}
443275

444-
@Deprecated
445-
@RobotKeyword("*DEPRECATED in version 0.6.0!* Use keyword `Find` instead.\n\n"
446-
+ "Returns height value of the node. \n\n"
447-
+ "``locator`` is either a _query_ or _Object_ for a node whose getHeight method will be called, see "
448-
+ "`3. Locating JavaFX Nodes`. \n\n")
449-
@ArgumentNames({ "locator" })
450-
public String getNodeHeight(Object locator) {
451-
Node node = objectToNode(locator);
452-
try {
453-
Method[] methods = node.getClass().getMethods();
454-
for (Method m : methods) {
455-
if (m.getName().equals("getHeight")) {
456-
try {
457-
Object result = m.invoke(node, (Object) null);
458-
return result.toString();
459-
} catch (Exception e) {
460-
throw new JavaFXLibraryNonFatalException("Problem calling method: .getHeight(): " + e.getMessage(), e);
461-
}
462-
}
463-
}
464-
throw new JavaFXLibraryNonFatalException(
465-
"Get node height failed for node: \"" + node.toString() + "\". Element has no method getHeight()");
466-
} catch (Exception e) {
467-
if (e instanceof JavaFXLibraryNonFatalException)
468-
throw e;
469-
throw new JavaFXLibraryNonFatalException("Unable to get node height for node: " + node.toString(), e);
470-
}
471-
}
472-
473276
@RobotKeyword("Returns image name and path of the node. \n\n"
474277
+ "``locator`` is either a _query_ or _Object_ for a node whose getHeight method will be called, see "
475278
+ "`3. Locating JavaFX Nodes`. \n\n"
@@ -535,31 +338,6 @@ public String getObjectClassName(Object locator) {
535338
}
536339
}
537340

538-
@Deprecated
539-
@RobotKeyword("*DEPRECATED in version 0.6.0!* Use keyword `Get Scene` instead.\n\n"
540-
+"Returns given locators Scene object. \n\n"
541-
+ "``locator`` is either a _query_ or a _Node_, see `3.2 Using locators as keyword arguments`\n\n")
542-
@ArgumentNames({ "locator" })
543-
public Object getNodesScene(Object locator) {
544-
try {
545-
if (locator instanceof Node){
546-
RobotLog.info("Getting a Scene object for a Node: \"" + locator + "\"");
547-
return mapObject(((Node) locator).getScene());
548-
} else if (locator instanceof String) {
549-
RobotLog.info("Getting a Scene object for a query: \"" + locator + "\"");
550-
Node node = objectToNode(locator);
551-
return mapObject(node.getScene());
552-
}
553-
554-
throw new JavaFXLibraryNonFatalException("Locator type is not a Node or a query string!");
555-
556-
} catch (Exception e) {
557-
if (e instanceof JavaFXLibraryNonFatalException)
558-
throw e;
559-
throw new JavaFXLibraryNonFatalException("Unable to get Scene object for locator: \"" + locator + "\"", e);
560-
}
561-
}
562-
563341
@RobotKeyword("Returns Scene of the given object. \n\n"
564342
+ "``locator`` is either a _query_, a _Node_ or a _Window_, see `3.2 Using locators as keyword arguments`\n\n")
565343
@ArgumentNames({ "locator" })
@@ -776,11 +554,24 @@ public int getTableColumnCount(Object locator){
776554
}
777555

778556
@RobotKeyword("Sets the screenshot directory for current application\n\n"
779-
+ "``directory`` is a path to a folder which is to be set as current screenshot directory")
780-
@ArgumentNames({ "directory" })
781-
public void setScreenshotDirectory(String dir){
782-
RobotLog.info("Setting new screenshot directory: " + dir);
783-
setCurrentSessionScreenshotDirectory(dir);
557+
+ "Notice that relative paths are from current work dir of JavaFXLibrary:\n"
558+
+ "- In case of Java Agent it comes from Application Under Test (AUT).\n"
559+
+ "- In case of JavaFXLibrary is started with \"java -jar *\" command it uses the current working directory as source.\n"
560+
+ "``directory`` is a path to a folder which is to be set as current screenshot directory in host where "
561+
+ "JavaFXLibrary is run.\n\n"
562+
+ "``logDirectory`` is a path that is put to log.html files that can be used after screenshots are moved "
563+
+ "from target system to e.g. CI workspace. Typically this is relative path.\n\n\n"
564+
+ "Example:\n"
565+
+ "| Set Screenshot Directory | /Users/robotuser/output/AUT-screenshots/ | ./output/AUT-screenshots/ | \n"
566+
+ "or\n"
567+
+ "| Set Screenshot Directory | ./output/AUT-screenshots/ | \n")
568+
@ArgumentNames({ "directory", "logDirectory=" })
569+
public void setScreenshotDirectory(String dir, String logDir){
570+
RobotLog.info("Setting screenshot directory to \"" + dir + "\".");
571+
if (logDir != null && !logDir.isEmpty()) {
572+
RobotLog.info("Log directory is set to \"" + logDir + "\"");
573+
}
574+
setCurrentSessionScreenshotDirectory(dir, logDir);
784575
}
785576

786577
@RobotKeyword("Gets the screenshot directory for current application")

0 commit comments

Comments
 (0)