18
18
package javafxlibrary .keywords .Keywords ;
19
19
20
20
import javafx .embed .swing .SwingFXUtils ;
21
+ import javafx .scene .Scene ;
21
22
import javafx .geometry .Bounds ;
23
+ import javafx .geometry .Rectangle2D ;
22
24
import javafxlibrary .exceptions .JavaFXLibraryNonFatalException ;
25
+ import javafxlibrary .keywords .AdditionalKeywords .ConvenienceKeywords ;
26
+ import javafxlibrary .keywords .AdditionalKeywords .Find ;
23
27
import javafxlibrary .utils .RobotLog ;
24
28
import javafxlibrary .utils .TestFxAdapter ;
25
29
import org .apache .commons .io .IOUtils ;
29
33
import org .robotframework .javalib .annotation .RobotKeywords ;
30
34
import javafx .scene .image .Image ;
31
35
import javax .imageio .ImageIO ;
36
+
37
+ import java .awt .GraphicsDevice ;
38
+ import java .awt .GraphicsEnvironment ;
32
39
import java .awt .image .BufferedImage ;
33
40
import java .io .*;
34
41
import java .net .MalformedURLException ;
@@ -58,13 +65,25 @@ else if (value.toLowerCase().equals("diskonly"))
58
65
throw new JavaFXLibraryNonFatalException ("Value \" " + value + "\" is not supported! Value must be either " +
59
66
"\" EMBEDDED\" or \" DISKONLY\" " );
60
67
}
68
+
69
+ @ RobotKeyword ("Returns a screenshot from whole primary screen. Note that this shows also other applications that are open." )
70
+ public Object capturePrimaryScreen () {
71
+ GraphicsDevice gd = GraphicsEnvironment .getLocalGraphicsEnvironment ().getDefaultScreenDevice ();
72
+ return this .captureImage (new Rectangle2D (0 , 0 , gd .getDisplayMode ().getWidth (), gd .getDisplayMode ().getHeight ()));
73
+ }
74
+
75
+ @ RobotKeywordOverload
76
+ public Object captureImage () {
77
+ return captureImage (robot .targetWindow ());
78
+ }
61
79
62
80
@ RobotKeywordOverload
63
81
public Object captureImage (Object locator ){
64
82
return captureImage (locator , true );
65
83
}
66
84
67
- @ RobotKeyword ("Returns a screenshot of the given locator.\n \n "
85
+ @ RobotKeyword ("Returns a screenshot of the given locator, or if not given from whole active window.\n \n "
86
+ + "Note that active window might only be part of the visible window, it e.g. dialog is active.\n \n "
68
87
+ "``locator`` is either a _query_ or _Object:Bounds, Node, Point2D, Rectangle, PointQuery, Scene, Window_ for identifying the element, see "
69
88
+ "`3. Locating or specifying UI elements`. \n \n "
70
89
+ "Argument ``logImage`` is a boolean value that specifies whether a captured image is also printed to test execution log. \n \n "
@@ -73,8 +92,9 @@ public Object captureImage(Object locator){
73
92
+ "| ${capture}= | Capture Image | ${region} | \n "
74
93
+ "| ${capture}= | Capture Image | ${node} | \n "
75
94
+ "| ${capture}= | Capture Image | ${window} | \n "
95
+ + "| ${capture}= | Capture Image | | \n "
76
96
+ "| ${capture}= | Capture Image | \\ #id | logImage=False |\n " )
77
- @ ArgumentNames ({"locator" , "logImage=True" })
97
+ @ ArgumentNames ({"locator=target window " , "logImage=True" })
78
98
public Object captureImage (Object locator , boolean logImage ){
79
99
if (locator == null )
80
100
throw new JavaFXLibraryNonFatalException ("Unable to capture image, given locator was null!" );
@@ -118,6 +138,16 @@ public Object captureImage(Object locator, boolean logImage){
118
138
throw new JavaFXLibraryNonFatalException ("Unable to take capture : \" " + locator + "\" " , e );
119
139
}
120
140
}
141
+
142
+ @ RobotKeyword ("Returns a screenshot of the scene conatining given locator.\n \n "
143
+ + "``locator`` is a query locator, see `3.1 Using queries`.\n \n "
144
+ + "\n Example:\n "
145
+ + "| ${capture}= | Capture Scene Containing Node | ${node} | \n " )
146
+ @ ArgumentNames ({"locator" , "logImage=True" })
147
+ public Object captureSceneContainingNode (Object locator ) {
148
+ Scene scene = (Scene ) useMappedObject (new ConvenienceKeywords ().getScene (locator ));
149
+ return this .captureImage (scene );
150
+ }
121
151
122
152
@ RobotKeyword ("Loads an image from the given _path_ in hard drive \n \n "
123
153
+ "``path`` is the source path for image in local hard drive. \n \n "
0 commit comments