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

Commit 8758e8d

Browse files
author
Severi Haverila
committed
use x3 retina if ios-device is not listed in the screensize file
1 parent 8a06f2f commit 8758e8d

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

example/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<dependency>
1010
<groupId>com.testdroid</groupId>
1111
<artifactId>mobile-opencv-image-recognition-library</artifactId>
12-
<version>0.1</version>
12+
<version>0.2</version>
1313
</dependency>
1414
<dependency>
1515
<groupId>ch.qos.logback</groupId>

library/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.testdroid</groupId>
66
<artifactId>mobile-opencv-image-recognition-library</artifactId>
7-
<version>0.1</version>
7+
<version>0.2</version>
88
<packaging>jar</packaging>
99
<name>OpenCV Mobile Image Recognition Library</name>
1010
<description>Library for image recognition that can be used in mobile testing with for example Appium</description>

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static ImageLocation findImage(String searchedImageFilePath, String scene
5858
ImageLocation imgLocation = imageFinder.findImage(searchedImageFilePath, sceneImageFilePath, settings.getTolerance());
5959

6060
if (imgLocation != null) {
61-
Dimension screenSize = getScreenSize(platform);
61+
Dimension screenSize = getScreenSize(platform, sceneImageFilePath);
6262
if (platform.equals(PlatformType.IOS)) {
6363
imgLocation = scaleImageRectangleForIos(screenSize, imgLocation, sceneImageFilePath);
6464
}
@@ -280,19 +280,28 @@ private static void takeIDeviceScreenshot(String screenShotFilePath) throws Exce
280280
}
281281
}
282282

283-
private static Dimension getScreenSize(PlatformType platform) throws Exception {
283+
private static Dimension getScreenSize(PlatformType platform, String sceneImageFilePath) throws Exception {
284284
if (platform.equals(PlatformType.IOS)) {
285-
return getIosScreenSize();
285+
return getIosScreenSize(sceneImageFilePath);
286286
} else {
287287
return getAndroidScreenSize();
288288
}
289289
}
290290

291-
private static Dimension getIosScreenSize() throws Exception {
291+
private static Dimension getIosScreenSize(String sceneImageFilePath) throws Exception {
292292
String udid = getIosUdid();
293293
String productType = getIosProductType(udid);
294-
Dimension screenSize = getIosScreenSizePointsFromPropertiesFile(productType);
295-
return screenSize;
294+
try {
295+
Dimension screenSize = getIosScreenSizePointsFromPropertiesFile(productType);
296+
return screenSize;
297+
} catch(UnsupportedOperationException e){
298+
logger.warn("Current device not included in the ios-screen-size.properties-file. Assuming x3 Retina display.");
299+
logger.warn("Add the devices screen size information to the ios-screen-size.properties-file");
300+
int screenHeight = (int) (imageFinder.getSceneHeight(sceneImageFilePath)/3);
301+
int screenWidth = (int) (imageFinder.getSceneWidth(sceneImageFilePath)/3);
302+
Dimension screenSize = new Dimension(screenWidth, screenHeight);
303+
return screenSize;
304+
}
296305
}
297306

298307
private static String getIosProductType(String udid) throws IOException, InterruptedException, Exception {
@@ -316,11 +325,11 @@ private static String getIosUdid() throws Exception {
316325
return udid;
317326
}
318327

319-
private static Dimension getIosScreenSizePointsFromPropertiesFile(String productType) throws Exception {
328+
private static Dimension getIosScreenSizePointsFromPropertiesFile(String productType) throws UnsupportedOperationException, Exception {
320329
Properties screenSizeProperties = fetchProperties();
321330
String screenDimensionString = (String) screenSizeProperties.get(productType);
322331
if (screenDimensionString == null){
323-
throw new Exception("ios-screen-size.properties is missing entry for: " + productType);
332+
throw new UnsupportedOperationException("ios-screen-size.properties is missing entry for: " + productType);
324333
}
325334
String screenDimensions[] = screenDimensionString.split(" x ");
326335
if (screenDimensions.length!=2){

0 commit comments

Comments
 (0)