Skip to content
This repository was archived by the owner on Dec 7, 2020. It is now read-only.

Commit bb41e58

Browse files
author
Severi Haverila
committed
refactoring
1 parent d489233 commit bb41e58

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

library/src/main/java/imagerecognition/ImageRecognition.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,7 @@ private static void takeAndroidScreenshot(String screenShotFilePath) throws IOEx
226226
}
227227

228228
private static void takeIDeviceScreenshot(String screenShotFilePath) throws Exception {
229-
String udid = System.getenv("UDID");
230-
if (udid==null){
231-
throw new Exception("$UDID was null, set UDID environment variable and try again");
232-
}
229+
String udid = getIosUdid();
233230
String[] cmd = new String[]{"idevicescreenshot", "-u", udid, screenShotFilePath};
234231
Process p = Runtime.getRuntime().exec(cmd);
235232
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
@@ -258,10 +255,13 @@ private static Dimension getScreenSize(PlatformType platform) throws Exception {
258255
}
259256

260257
private static Dimension getIosScreenSize() throws Exception {
261-
String udid = System.getenv("UDID");
262-
if (udid==null){
263-
throw new Exception("$UDID was null, set UDID environment variable and try again");
264-
}
258+
String udid = getIosUdid();
259+
String productType = getIosProductType(udid);
260+
Dimension screenSize = getIosScreenSizePointsFromPropertiesFile(productType);
261+
return screenSize;
262+
}
263+
264+
private static String getIosProductType(String udid) throws IOException, InterruptedException, Exception {
265265
String[] cmd = new String[]{"ideviceinfo", "-u", udid, "--key", "ProductType"};
266266
Process p = Runtime.getRuntime().exec(cmd);
267267
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
@@ -271,7 +271,18 @@ private static Dimension getIosScreenSize() throws Exception {
271271
throw new Exception("ideviceinfo process exited with value: " + exitVal);
272272
}
273273
String productType = in.readLine();
274-
274+
return productType;
275+
}
276+
277+
private static String getIosUdid() throws Exception {
278+
String udid = System.getenv("UDID");
279+
if (udid==null){
280+
throw new Exception("$UDID was null, set UDID environment variable and try again");
281+
}
282+
return udid;
283+
}
284+
285+
private static Dimension getIosScreenSizePointsFromPropertiesFile(String productType) throws Exception {
275286
Properties screenSizeProperties = fetchProperties();
276287
String screenDimensionString = (String) screenSizeProperties.get(productType);
277288
if (screenDimensionString == null){

0 commit comments

Comments
 (0)