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

Commit 1d35ba4

Browse files
author
Severi Haverila
committed
fix indentation and include editorconfig
1 parent 6c70ebc commit 1d35ba4

13 files changed

+477
-449
lines changed

example/.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# top-most EditorConfig file
2+
root = true
3+
4+
# Unix-style newlines with a newline ending every file
5+
[*]
6+
end_of_line = lf
7+
insert_final_newline = true
8+
9+
# Matches multiple files with brace expansion notation
10+
# Set default charset
11+
[*.{java,xml}]
12+
charset = utf-8
13+
indent_style = space
14+
indent_size = 4

example/src/main/java/AbstractAppiumTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ public static AppiumDriver getIOSDriver() throws Exception {
4646
appFile = "application.ipa";
4747
}
4848
if (platform == null) {
49-
platform = PlatformType.IOS;
49+
platform = PlatformType.IOS;
5050
}
5151
if (deviceName == null){
52-
deviceName = "device";
52+
deviceName = "device";
5353
}
5454
if (platformVersion == null){
55-
platformVersion = "";
55+
platformVersion = "";
5656
}
5757
// Use default "appium" automation for iOS
5858
automationName = "appium";
@@ -93,13 +93,13 @@ public static AppiumDriver getAndroidDriver() throws Exception {
9393
appFile = "application.apk";
9494
}
9595
if (platform == null) {
96-
platform = PlatformType.ANDROID;
96+
platform = PlatformType.ANDROID;
9797
}
9898
if (deviceName == null){
9999
deviceName = "device";
100100
}
101101
if (automationName == null){
102-
automationName = "appium";
102+
automationName = "appium";
103103
}
104104
screenshotsFolder = "target/reports/screenshots/android/";
105105
File dir = new File(screenshotsFolder);
@@ -169,6 +169,6 @@ public static void log(String message) {
169169
logger.info(message);
170170
}
171171

172-
172+
173173

174174
}

example/src/main/java/AppiumCommons.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import io.appium.java_client.MobileElement;
1313

1414
public class AppiumCommons {
15-
private static Logger logger = LoggerFactory.getLogger(AppiumCommons.class);
16-
15+
private static Logger logger = LoggerFactory.getLogger(AppiumCommons.class);
16+
1717
public static void hideKeyboard(AppiumDriver<MobileElement> driver) {
1818
try {
1919
driver.hideKeyboard();
@@ -22,18 +22,18 @@ public static void hideKeyboard(AppiumDriver<MobileElement> driver) {
2222
logger.debug(e.toString());
2323
}
2424
}
25-
25+
2626
public static void takeAppiumScreenshot(AppiumDriver<MobileElement> driver, String fullFileName) {
27-
File scrFile = driver.getScreenshotAs(OutputType.FILE);
28-
try {
29-
File testScreenshot = new File(fullFileName);
30-
FileUtils.copyFile(scrFile, testScreenshot);
31-
logger.info("Screenshot stored to {}", testScreenshot.getAbsolutePath());
32-
} catch (IOException e) {
33-
e.printStackTrace();
34-
}
35-
}
36-
27+
File scrFile = driver.getScreenshotAs(OutputType.FILE);
28+
try {
29+
File testScreenshot = new File(fullFileName);
30+
FileUtils.copyFile(scrFile, testScreenshot);
31+
logger.info("Screenshot stored to {}", testScreenshot.getAbsolutePath());
32+
} catch (IOException e) {
33+
e.printStackTrace();
34+
}
35+
}
36+
3737
public static void swipeUp(AppiumDriver<MobileElement> driver) {
3838
swipeUp(driver, 0.15f, 0.15f);
3939
}
@@ -140,5 +140,5 @@ public static void swipeRight(AppiumDriver<MobileElement> driver, Point rootLoca
140140
center.getY(),
141141
duration);
142142
}
143-
143+
144144
}

example/src/main/java/TestdroidImageRecognition.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ public void setQueryImageFolder() {
2929
}
3030

3131
public ImageLocation findImageOnScreen(String image) throws Exception {
32-
ImageRecognitionSettings defaultSettings = new ImageRecognitionSettings();
33-
return findImageOnScreen(image, defaultSettings).getImageLocation();
32+
ImageRecognitionSettings defaultSettings = new ImageRecognitionSettings();
33+
return findImageOnScreen(image, defaultSettings).getImageLocation();
3434
}
35-
35+
3636
public ImageSearchResult findImageOnScreen(String imageName, ImageRecognitionSettings settings) throws Exception {
37-
// queryImageFolder is "", unless set by setQueryImageFolder()
37+
// queryImageFolder is "", unless set by setQueryImageFolder()
3838
String queryImageFolder = "queryimages/" + queryImageSubFolder;
3939
String screenshotsFolder = "target/reports/screenshots/";
4040
String imageFile = queryImageFolder+imageName;
4141
log("Searching for: "+imageFile);
4242
Dimension screenSize = ImageRecognition.getScreenSize(platform, driver);
43-
ImageSearchResult foundImage = ImageRecognition.findImageOnScreen(imageFile, screenshotsFolder, settings, screenSize, platform);
43+
ImageSearchResult foundImage = ImageRecognition.findImageOnScreen(imageFile, screenshotsFolder, settings, screenSize, platform);
4444
return foundImage;
4545
}
4646

@@ -49,23 +49,23 @@ public void waitForImageToDisappearFromScreen(String image) throws Exception {
4949
String screenshotsFolder = "target/reports/screenshots/";
5050
Dimension screenSize = ImageRecognition.getScreenSize(platform, driver);
5151
String imageFile = queryImageFolder+image;
52-
boolean hasImageDisappeared = ImageRecognition.hasImageDissappearedFromScreenBeforeTimeout(imageFile, screenshotsFolder, screenSize, platform);
53-
assert(hasImageDisappeared);
52+
boolean hasImageDisappeared = ImageRecognition.hasImageDissappearedFromScreenBeforeTimeout(imageFile, screenshotsFolder, screenSize, platform);
53+
assert(hasImageDisappeared);
5454
}
5555

5656

5757
public String grabTextFromImage(String image) throws Exception {
58-
ImageSearchResult imageSearch = findAndCropImage(image);
58+
ImageSearchResult imageSearch = findAndCropImage(image);
5959
String text = ImageRecognition.getTextStringFromImage(imageSearch.getScreenshotFile());
60-
return text;
60+
return text;
6161
}
6262

63-
public ImageSearchResult findAndCropImage(String image) throws Exception {
64-
ImageRecognitionSettings settings = new ImageRecognitionSettings();
65-
settings.setCrop(true);
66-
ImageSearchResult imageSearch = findImageOnScreen(image, settings);
67-
return imageSearch;
68-
}
63+
public ImageSearchResult findAndCropImage(String image) throws Exception {
64+
ImageRecognitionSettings settings = new ImageRecognitionSettings();
65+
settings.setCrop(true);
66+
ImageSearchResult imageSearch = findImageOnScreen(image, settings);
67+
return imageSearch;
68+
}
6969

7070

7171
}

example/src/test/java/AndroidSample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public static void tearDown() {
5151
public void mainPageTest() throws Exception {
5252
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
5353
log("Image Recognition sample script started.");
54-
// takeScreenshot("Before hideKeyboard");
55-
54+
// takeScreenshot("Before hideKeyboard");
55+
5656
AppiumCommons.hideKeyboard(driver);
5757

5858
findAndCropImage("test.png");

example/src/test/java/iOSSample.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public iOSSample() throws Exception {
3030

3131
@BeforeClass
3232
public static void setUp() throws Exception {
33-
ImageRecognition.setUp();
33+
ImageRecognition.setUp();
3434
driver = getIOSDriver();
3535
}
3636

@@ -50,13 +50,13 @@ public void mainPageTest() throws Exception {
5050
log("Image Recognition sample script started.");
5151

5252
try {
53-
driver.hideKeyboard();
53+
driver.hideKeyboard();
5454
} catch (Exception e) {
55-
log("Keyboard not present; going forward.");
55+
log("Keyboard not present; going forward.");
5656
}
5757

5858
findAndCropImage("test.png");
59-
// waitForImageToDisappearFromScreen("bitbar_logo.png");
59+
// waitForImageToDisappearFromScreen("bitbar_logo.png");
6060
log("Success.");
6161
}
6262
}

library/.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# top-most EditorConfig file
2+
root = true
3+
4+
# Unix-style newlines with a newline ending every file
5+
[*]
6+
end_of_line = lf
7+
insert_final_newline = true
8+
9+
# Matches multiple files with brace expansion notation
10+
# Set default charset
11+
[*.{java,xml}]
12+
charset = utf-8
13+
indent_style = space
14+
indent_size = 4

library/src/main/java/imagerecognition/AkazeImageFinder.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ protected double getSceneHeight(String sceneFile) {
3434
}
3535

3636
protected double getSceneWidth(String sceneFile) {
37-
Mat img_scene = Highgui.imread(sceneFile, Highgui.CV_LOAD_IMAGE_UNCHANGED);
38-
double scene_width = img_scene.cols();
39-
return scene_width;
37+
Mat img_scene = Highgui.imread(sceneFile, Highgui.CV_LOAD_IMAGE_UNCHANGED);
38+
double scene_width = img_scene.cols();
39+
return scene_width;
4040
}
4141

4242
protected ImageLocation findImage(String queryImageFile, String sceneFile, double tolerance) {
@@ -45,7 +45,7 @@ protected ImageLocation findImage(String queryImageFile, String sceneFile, doubl
4545
Mat img_object = Highgui.imread(queryImageFile, Highgui.CV_LOAD_IMAGE_UNCHANGED);
4646
Mat img_scene = Highgui.imread(sceneFile, Highgui.CV_LOAD_IMAGE_UNCHANGED);
4747

48-
48+
4949
double scene_height = img_scene.rows();
5050
double scene_width = img_scene.cols();
5151
//logger.info("Scene height and width: " + scene_height + ", " + scene_width);
@@ -64,7 +64,7 @@ protected ImageLocation findImage(String queryImageFile, String sceneFile, doubl
6464
img_scene = Highgui.imread(sceneFile, Highgui.CV_LOAD_IMAGE_UNCHANGED);
6565
logger.info("Image was resized, resize factor is: " + resizeFactor);
6666
} else{
67-
resizeFactor = 1;
67+
resizeFactor = 1;
6868
}
6969

7070
String jsonResults = null;
@@ -189,15 +189,15 @@ protected ImageLocation findImage(String queryImageFile, String sceneFile, doubl
189189
logger.info("==> Image finder took: " + difference + " secs.");
190190

191191
if (checkFoundImageDimensions(top_left, top_right, bottom_left, bottom_right, tolerance)){
192-
return null;
192+
return null;
193193
}
194194
if (checkFoundImageSizeRatio(initial_height, initial_width, top_left, top_right, bottom_left, bottom_right, initial_ratio, found_ratio1, found_ratio2, tolerance)){
195-
return null;
195+
return null;
196196
}
197197

198198
//calculate points in original orientation
199199
Point[] points = new Point[5];
200-
200+
201201

202202
if (rotationAngle == 1.0) {
203203
points[0] = new Point(scene_height / resizeFactor - bottom_left.y, bottom_left.x);
@@ -229,7 +229,7 @@ protected ImageLocation findImage(String queryImageFile, String sceneFile, doubl
229229
points[2] = new Point(points[2].x * resizeFactor, points[2].y * resizeFactor);
230230
points[3] = new Point(points[3].x * resizeFactor, points[3].y * resizeFactor);
231231
points[4] = centerOriginal;
232-
232+
233233
logger.info("Image found at coordinates: " + (int) points[4].x + ", " + (int) points[4].y + " on screen.");
234234
logger.info("All corners: " + points[0].toString() + " " + points[1].toString() + " " + points[2].toString() + " " + points[4].toString());
235235

@@ -240,26 +240,26 @@ protected ImageLocation findImage(String queryImageFile, String sceneFile, doubl
240240
location.setBottomLeft(points[3]);
241241
location.setCenter(centerOriginal);
242242
location.setResizeFactor(resizeFactor);
243-
243+
244244
return location;
245245
}
246246

247247
protected void cropImage(ImageSearchResult imageDto) {
248-
double x = imageDto.getImageLocation().getTopLeft().x;
249-
double y = imageDto.getImageLocation().getTopLeft().y;
250-
double width = imageDto.getImageLocation().getWidth();
251-
double height = imageDto.getImageLocation().getHeight();
252-
String scene_filename = imageDto.getScreenshotFile();
253-
int scaleFactor = imageDto.getImageLocation().getScaleFactor();
254-
double resizeFactor = imageDto.getImageLocation().getResizeFactor();
255-
248+
double x = imageDto.getImageLocation().getTopLeft().x;
249+
double y = imageDto.getImageLocation().getTopLeft().y;
250+
double width = imageDto.getImageLocation().getWidth();
251+
double height = imageDto.getImageLocation().getHeight();
252+
String scene_filename = imageDto.getScreenshotFile();
253+
int scaleFactor = imageDto.getImageLocation().getScaleFactor();
254+
double resizeFactor = imageDto.getImageLocation().getResizeFactor();
255+
256256
Mat img_object = Highgui.imread(scene_filename);
257-
258-
int x_resized = (int) (x / resizeFactor)*scaleFactor;
259-
int y_resized = (int) (y / resizeFactor)*scaleFactor;
260-
int width_resized = (int) (width / resizeFactor)*scaleFactor;
261-
int height_resized = (int) (height / resizeFactor)*scaleFactor;
262-
Rect croppedRect = new Rect(x_resized, y_resized, width_resized, height_resized);
257+
258+
int x_resized = (int) (x / resizeFactor)*scaleFactor;
259+
int y_resized = (int) (y / resizeFactor)*scaleFactor;
260+
int width_resized = (int) (width / resizeFactor)*scaleFactor;
261+
int height_resized = (int) (height / resizeFactor)*scaleFactor;
262+
Rect croppedRect = new Rect(x_resized, y_resized, width_resized, height_resized);
263263
log(img_object.toString());
264264
log(croppedRect.toString());
265265
Mat croppedImage = new Mat(img_object, croppedRect);

0 commit comments

Comments
 (0)