aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog20
-rw-r--r--tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java6
-rw-r--r--tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java36
-rw-r--r--tests/test-extensions/net/sourceforge/jnlp/awt/imagesearch/ImageSeeker.java77
4 files changed, 120 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index ce3c8de..4508a31 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2013-04-29 Jiri Vanek <[email protected]>
+
+ More granular initialization of AwtHelper
+ * tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java: added
+ (executeBrowser) which can work upon fully constructed url
+ * tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java:
+ (captureScreenAndFindAppletByIconTryKTimes) split to three:
+ (captureScreenAndFindAppletByIconTryKTimes) - unchanged, now using following
+ (initialiseOnScreenshot) initialize from given buffered image, creating area
+ (initialiseOnScreenshotAndArea) initialize from two given buffered images
+
+2013-04-29 Jiri Vanek <[email protected]>
+
+ Improved performance of scanning images, added masking of images
+ * tests/test-extensions/net/sourceforge/jnlp/awt/imagesearch/ImageSeeker.java:
+ (findExactImage) now using masks and is iterating over rows
+ (getMaskImage) new method to visualize mask
+ (getMask) new method to create mask
+ (getPixels) method to extract pixels from image to int array
+
2013-04-29 Jana Fabrikova <[email protected]>
* tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java:
diff --git a/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java b/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java
index 55ec17a..7d3b3d7 100644
--- a/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java
+++ b/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java
@@ -598,7 +598,11 @@ public class ServerAccess {
}
public ProcessResult executeBrowser(List<String> otherargs, String resource) throws Exception {
- ProcessWrapper rpw = new ProcessWrapper(getBrowserLocation(), otherargs, getUrlUponThisInstance(resource));
+ return executeBrowser(otherargs, getUrlUponThisInstance(resource));
+ }
+
+ public ProcessResult executeBrowser(List<String> otherargs, URL url) throws Exception {
+ ProcessWrapper rpw = new ProcessWrapper(getBrowserLocation(), otherargs, url);
rpw.setReactingProcess(getCurrentBrowser());//current browser may be null, but it does not metter
return rpw.execute();
}
diff --git a/tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java b/tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java
index 8a888d4..faced3a 100644
--- a/tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java
+++ b/tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java
@@ -354,24 +354,42 @@ public abstract class AWTHelper extends RulesFolowingClosingListener implements
int count = 0;
appletFound = false;
while ((count < K) && !appletFound) {
- robot.delay(defaultWaitForApplet);
- screenshot = robot.createScreenCapture( new Rectangle( Toolkit.getDefaultToolkit().getScreenSize() ) );
- screenshotTaken = true;
- actionArea = ComponentFinder.findWindowByIcon(icon, iconPosition, width, height, screenshot);
- if (ImageSeeker.isRectangleValid(actionArea)) {
- appletFound = true;
- }
- count++;
+ robot.delay(defaultWaitForApplet);
+ try {
+ screenshot = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
+ initialiseOnScreenshot(icon, iconPosition, width, height, screenshot);
+ } catch (ComponentNotFoundException ex) {
+ //keeping silent and try more-times
+ }
+ count++;
}
if (ImageSeeker.isRectangleValid(actionArea)) {
appletFound = true;
} else {
- throw new ComponentNotFoundException("Applet not found in the screenshot!");
+ throw new ComponentNotFoundException("Object not found in the screenshot!");
}
}
+ public void initialiseOnScreenshot(BufferedImage icon, Point iconPosition, int width, int height, BufferedImage screenshot) throws ComponentNotFoundException {
+ Rectangle r = ComponentFinder.findWindowByIcon(icon, iconPosition, width, height, screenshot);
+ initialiseOnScreenshotAndArea(screenshot, r);
+
+ }
+
+ public void initialiseOnScreenshotAndArea(BufferedImage screenshot, Rectangle actionArea) throws ComponentNotFoundException {
+ this.screenshot = screenshot;
+ screenshotTaken = true;
+ this.actionArea = actionArea;
+ if (ImageSeeker.isRectangleValid(actionArea)) {
+ appletFound = true;
+ } else {
+ throw new ComponentNotFoundException("set invalid area!");
+ }
+ }
+
+
/**
* auxiliary method writeAppletScreen for writing Buffered image into png
*
diff --git a/tests/test-extensions/net/sourceforge/jnlp/awt/imagesearch/ImageSeeker.java b/tests/test-extensions/net/sourceforge/jnlp/awt/imagesearch/ImageSeeker.java
index 88d6604..c8e42c6 100644
--- a/tests/test-extensions/net/sourceforge/jnlp/awt/imagesearch/ImageSeeker.java
+++ b/tests/test-extensions/net/sourceforge/jnlp/awt/imagesearch/ImageSeeker.java
@@ -50,17 +50,28 @@ public class ImageSeeker
return findExactImage(marker, screen, new Rectangle(0,0,screen.getWidth(), screen.getHeight()));
}
- public static Rectangle findExactImage(BufferedImage marker, BufferedImage screen, Rectangle actionArea){
- Rectangle result = new Rectangle(0,0,0,0);
+ public static Rectangle findExactImage(BufferedImage marker /*usually small*/, BufferedImage screen, Rectangle actionArea) {
+ Rectangle result = new Rectangle(0, 0, 0, 0);
boolean found = false;
boolean ok = true;
-
- for(int x = actionArea.x; (x < (actionArea.x + actionArea.width - marker.getWidth()) ) && !found; x++){
- for(int y= actionArea.y; (y < (actionArea.y + actionArea.height - marker.getHeight()) ) && !found; y++){
-
- for(int mx = 0; (mx < marker.getWidth()) && ok; mx++){
- for(int my = 0; (my < marker.getHeight()) && ok; my++){
- if(marker.getRGB(mx, my) != screen.getRGB(x+mx,y+my)){
+ //to filter out values with alpha
+ boolean[][] mask = getMask(marker);
+ //accessing those too often, copying
+ int[][] markerPixels = getPixels(marker);
+ int mw = marker.getWidth();
+ int mh = marker.getHeight();
+ for (int y = actionArea.y; (y < (actionArea.y + actionArea.height - marker.getHeight())) && !found; y++) {
+ for (int x = actionArea.x; (x < (actionArea.x + actionArea.width - marker.getWidth())) && !found; x++) {
+
+
+ for (int my = 0; (my < mh) && ok; my++) {
+ for (int mx = 0; (mx < mw) && ok; mx++) {
+
+ //ignore masked (having alpha) values
+ if (!mask[mx][my]) {
+ continue;
+ }
+ if (markerPixels[mx][my] != screen.getRGB(x + mx, y + my)) {
ok = false;
}
}
@@ -325,4 +336,52 @@ public class ImageSeeker
return (r.width != 0)&&(r.height != 0)&&(r.x != Integer.MIN_VALUE)&&(r.y != Integer.MIN_VALUE);
}
+ public static BufferedImage getMaskImage(BufferedImage icon) {
+ int w = icon.getWidth();
+ int h = icon.getHeight();
+ boolean[][] b = getMask(icon);
+ BufferedImage mask = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_BINARY);
+ for (int y = 0; y < h; y++) {
+ for (int x = 0; x < w; x++) {
+ if (b[x][y]) {
+ mask.setRGB(x, y, Color.white.getRGB());
+ } else {
+ mask.setRGB(x, y, Color.black.getRGB());
+ }
+ }
+ }
+ return mask;
+ }
+
+ public static boolean[][] getMask(BufferedImage icon) {
+ int w = icon.getWidth();
+ int h = icon.getHeight();
+ boolean[][] r = new boolean[w][h];
+ for (int y = 0; y < h; y++) {
+ for (int x = 0; x < w; x++) {
+ int i = icon.getRGB(x, y);
+ int alpha = (i >> 24) & 0xff;
+ if (alpha == 255) {
+ r[x][y] = true;
+ } else {
+ r[x][y] = false;
+ }
+ }
+ }
+ return r;
+ }
+
+ public static int[][] getPixels(BufferedImage icon) {
+ int w = icon.getWidth();
+ int h = icon.getHeight();
+ int[][] r = new int[w][h];
+ for (int x = 0; x < w; x++) {
+ for (int y = 0; y < h; y++) {
+ int i = icon.getRGB(x, y);
+ //remove mask? not yet...
+ r[x][y] = i;
+ }
+ }
+ return r;
+ }
}