20
20
public class TestdroidImageRecognition extends AbstractAppiumTest {
21
21
22
22
public Logger logger = LoggerFactory .getLogger (TestdroidImageRecognition .class );
23
-
24
- AkazeImageFinder imageFinder = new AkazeImageFinder ();
25
-
26
23
private String queryImageSubFolder = "" ;
27
- public boolean found = false ;
28
24
29
25
30
26
//If this method is called inside a test the script will check if the device has a resolution lower than 500x500 and if so will use
@@ -37,14 +33,6 @@ public void setQueryImageFolder() {
37
33
}
38
34
}
39
35
40
-
41
- /**
42
- * ======================================================================================
43
- * FINDING AN IMAGE ON SCREEN
44
- * ======================================================================================
45
- */
46
-
47
-
48
36
public Point [] findImageOnScreen (String image ) throws Exception {
49
37
ImageRecognitionSettingsDTO defaultSettings = new ImageRecognitionSettingsDTO ();
50
38
return findImageOnScreen (image , defaultSettings ).getImageRectangle ();
@@ -69,18 +57,6 @@ public void waitForImageToDisappearFromScreen(String image) throws Exception {
69
57
assert (hasImageDisappeared );
70
58
}
71
59
72
-
73
-
74
-
75
-
76
- /**
77
- * ======================================================================================
78
- * ADB UTILITIES
79
- * ======================================================================================
80
- */
81
-
82
-
83
- //Uses adb commands to get the screen size. To be used when appium methods fail. Only works on Android devices.
84
60
public Dimension getScreenSize () throws Exception {
85
61
log ("trying to get size from adb..." );
86
62
log ("------------------------------" );
@@ -91,7 +67,6 @@ public Dimension getScreenSize() throws Exception {
91
67
}
92
68
}
93
69
94
-
95
70
private Dimension getAndroidScreenSize () throws IOException , InterruptedException {
96
71
String adb = "adb" ;
97
72
String [] adbCommand = {adb , "shell" , "dumpsys" , "window" };
@@ -117,54 +92,6 @@ private Dimension getAndroidScreenSize() throws IOException, InterruptedExceptio
117
92
return screenSize ;
118
93
}
119
94
120
- public boolean findDeviceTypeADB () throws Exception {
121
- log ("trying to find device type ..." );
122
- log ("------------------------------" );
123
- if (platformName .equalsIgnoreCase ("iOS" )) {
124
- //TO Be added
125
- } else {
126
- String adb = "adb" ;
127
- String [] adbCommand = {adb , "shell" , "getprop" , "ro.build.characteristics" };
128
- try {
129
- ProcessBuilder p = new ProcessBuilder (adbCommand );
130
- Process proc = p .start ();
131
- InputStream stdin = proc .getInputStream ();
132
- InputStreamReader isr = new InputStreamReader (stdin );
133
- BufferedReader br = new BufferedReader (isr );
134
- String line = null ;
135
- String [] size = null ;
136
- while ((line = br .readLine ()) != null ) {
137
- if (line .contains ("tablet" )) {
138
- return true ;
139
- }
140
-
141
- }
142
- } catch (Throwable t ) {
143
- t .printStackTrace ();
144
- }
145
- }
146
- return false ;
147
- }
148
-
149
- public void processBuilder (String [] adbCommand ) {
150
- try {
151
- found = true ;
152
- ProcessBuilder p = new ProcessBuilder (adbCommand );
153
- Process proc = p .start ();
154
- InputStream stdin = proc .getInputStream ();
155
- InputStreamReader isr = new InputStreamReader (stdin );
156
- BufferedReader br = new BufferedReader (isr );
157
- String line = null ;
158
- while ((line = br .readLine ()) != null )
159
- System .out .print (line );
160
-
161
- proc .waitFor ();
162
-
163
- } catch (Throwable t ) {
164
- found = false ;
165
- t .printStackTrace ();
166
- }
167
- }
168
95
169
96
public String grabTextFromImage (String image ) throws Exception {
170
97
ImageRecognitionSettingsDTO settings = new ImageRecognitionSettingsDTO ();
@@ -173,35 +100,6 @@ public String grabTextFromImage(String image) throws Exception {
173
100
String text = ImageRecognition .getTextStringFromImage (imageSearch .getScreenshotFile ());
174
101
return text ;
175
102
}
176
-
177
-
178
-
179
103
180
-
181
-
182
- /**
183
- * ======================================================================================
184
- * OTHER UTILITIES
185
- * ======================================================================================
186
- */
187
-
188
- //TODO: experimental method
189
- public Point correctAndroidCoordinates (Point appium_coord ) throws Exception {
190
-
191
- Dimension appium_dimensions = driver .manage ().window ().getSize ();
192
- int appium_screenWidth = appium_dimensions .getWidth ();
193
- int appium_screenHeight = appium_dimensions .getHeight ();
194
-
195
- Dimension adb_dimension = getScreenSize ();
196
- int adb_screenWidth = adb_dimension .getWidth ();
197
- int adb_screenHeight = adb_dimension .getHeight ();
198
-
199
- double x_offset = appium_coord .x / appium_screenWidth ;
200
- double y_offset = appium_coord .y / appium_screenHeight ;
201
- log ("x_offset is : " + x_offset );
202
- log ("y_offset is : " + y_offset );
203
-
204
- return new Point (x_offset * adb_screenWidth , y_offset * adb_screenHeight );
205
- }
206
104
207
105
}
0 commit comments