@@ -47,27 +47,25 @@ public void setQueryImageFolder() {
47
47
48
48
public Point [] findImageOnScreen (String image ) throws Exception {
49
49
ImageRecognitionSettingsDTO defaultSettings = new ImageRecognitionSettingsDTO ();
50
- return findImageOnScreen (image , defaultSettings );
50
+ return findImageOnScreen (image , defaultSettings ). getImageRectangle () ;
51
51
}
52
52
53
- public Point [] findImageOnScreen (String image , ImageRecognitionSettingsDTO settings ) throws Exception {
54
- ImageSearchDTO dto = findImageOnScreen2 (image , settings );
55
- return dto .getImageRectangle ();
56
- }
57
-
58
- private ImageSearchDTO findImageOnScreen2 (String imageName , ImageRecognitionSettingsDTO settings ) throws Exception {
53
+ public ImageSearchDTO findImageOnScreen (String imageName , ImageRecognitionSettingsDTO settings ) throws Exception {
59
54
// queryImageFolder is "", unless set by setQueryImageFolder()
60
55
String queryImageFolder = "queryimages/" + queryImageSubFolder ;
61
56
String screenshotsFolder = "target/reports/screenshots/" ; //TODO Severi remove this
62
- ImageSearchDTO foundImage = ImageRecognition .findImageOnScreen (imageName , queryImageFolder , screenshotsFolder , settings , getScreenSizeADB (), platformName );
57
+ String imageFile = queryImageFolder +imageName ;
58
+ log ("Searching for: " +imageFile );
59
+ ImageSearchDTO foundImage = ImageRecognition .findImageOnScreen (imageFile , screenshotsFolder , settings , getScreenSize (), platformName );
63
60
return foundImage ;
64
61
}
65
62
66
63
public void waitForImageToDisappearFromScreen (String image ) throws Exception {
67
64
String queryImageFolder = "queryimages/" + queryImageSubFolder ; //TODO Severi remove this
68
65
String screenshotsFolder = "target/reports/screenshots/" ; //TODO Severi remove this
69
- Dimension screenSize = getScreenSizeADB (); //TODO Severi remove this
70
- boolean hasImageDisappeared = ImageRecognition .hasImageDissappearedFromScreenBeforeTimeout (image , queryImageFolder , screenshotsFolder , screenSize , platformName );
66
+ Dimension screenSize = getScreenSize (); //TODO Severi remove this
67
+ String imageFile = queryImageFolder +image ;
68
+ boolean hasImageDisappeared = ImageRecognition .hasImageDissappearedFromScreenBeforeTimeout (imageFile , screenshotsFolder , screenSize , platformName );
71
69
assert (hasImageDisappeared );
72
70
}
73
71
@@ -83,43 +81,42 @@ public void waitForImageToDisappearFromScreen(String image) throws Exception {
83
81
84
82
85
83
//Uses adb commands to get the screen size. To be used when appium methods fail. Only works on Android devices.
86
- public Dimension getScreenSizeADB () throws Exception {
84
+ public Dimension getScreenSize () throws Exception {
87
85
log ("trying to get size from adb..." );
88
86
log ("------------------------------" );
89
87
if (platformName .equalsIgnoreCase ("iOS" )) {
90
88
return driver .manage ().window ().getSize ();
91
89
} else {
92
- String adb = "adb" ;
93
- String [] adbCommand = {adb , "shell" , "dumpsys" , "window" };
94
- try {
95
- ProcessBuilder p = new ProcessBuilder (adbCommand );
96
- Process proc = p .start ();
97
- InputStream stdin = proc .getInputStream ();
98
- InputStreamReader isr = new InputStreamReader (stdin );
99
- BufferedReader br = new BufferedReader (isr );
100
- String line = null ;
101
- String [] size = null ;
102
- while ((line = br .readLine ()) != null ) {
103
- if (!line .contains ("OriginalmUnrestrictedScreen" )) { //we do this check for devices with android 5.x+ The adb command returns an extra line with the values 0x0 which must be filtered out.
104
- if (line .contains ("mUnrestrictedScreen" )) {
105
- proc .waitFor ();
106
- String [] tmp = line .split ("\\ ) " );
107
- size = tmp [1 ].split ("x" );
108
- }
109
- }
110
- }
111
- int width = Integer .parseInt (size [0 ]);
112
- int height = Integer .parseInt (size [1 ]);
113
- Dimension screenSize = new Dimension (width , height );
114
- return screenSize ;
115
-
116
- } catch (Throwable t ) {
117
- t .printStackTrace ();
118
- }
90
+ return getAndroidScreenSize ();
119
91
}
120
- return null ;
121
92
}
122
93
94
+
95
+ private Dimension getAndroidScreenSize () throws IOException , InterruptedException {
96
+ String adb = "adb" ;
97
+ String [] adbCommand = {adb , "shell" , "dumpsys" , "window" };
98
+ ProcessBuilder p = new ProcessBuilder (adbCommand );
99
+ Process proc = p .start ();
100
+ InputStream stdin = proc .getInputStream ();
101
+ InputStreamReader isr = new InputStreamReader (stdin );
102
+ BufferedReader br = new BufferedReader (isr );
103
+ String line = null ;
104
+ String [] size = null ;
105
+ while ((line = br .readLine ()) != null ) {
106
+ if (!line .contains ("OriginalmUnrestrictedScreen" )) { //we do this check for devices with android 5.x+ The adb command returns an extra line with the values 0x0 which must be filtered out.
107
+ if (line .contains ("mUnrestrictedScreen" )) {
108
+ proc .waitFor ();
109
+ String [] tmp = line .split ("\\ ) " );
110
+ size = tmp [1 ].split ("x" );
111
+ }
112
+ }
113
+ }
114
+ int width = Integer .parseInt (size [0 ]);
115
+ int height = Integer .parseInt (size [1 ]);
116
+ Dimension screenSize = new Dimension (width , height );
117
+ return screenSize ;
118
+ }
119
+
123
120
public boolean findDeviceTypeADB () throws Exception {
124
121
log ("trying to find device type ..." );
125
122
log ("------------------------------" );
@@ -172,7 +169,7 @@ public void processBuilder(String[] adbCommand) {
172
169
public String grabTextFromImage (String image ) throws Exception {
173
170
ImageRecognitionSettingsDTO settings = new ImageRecognitionSettingsDTO ();
174
171
settings .setCrop (true );
175
- ImageSearchDTO imageSearch = findImageOnScreen2 (image , settings );
172
+ ImageSearchDTO imageSearch = findImageOnScreen (image , settings );
176
173
String text = ImageRecognition .getTextStringFromImage (imageSearch .getScreenshotFile ());
177
174
return text ;
178
175
}
@@ -195,7 +192,7 @@ public Point correctAndroidCoordinates(Point appium_coord) throws Exception {
195
192
int appium_screenWidth = appium_dimensions .getWidth ();
196
193
int appium_screenHeight = appium_dimensions .getHeight ();
197
194
198
- Dimension adb_dimension = getScreenSizeADB ();
195
+ Dimension adb_dimension = getScreenSize ();
199
196
int adb_screenWidth = adb_dimension .getWidth ();
200
197
int adb_screenHeight = adb_dimension .getHeight ();
201
198
0 commit comments