Mercurial > hg > ThermostatQA
changeset 177:e78173df9ba0
Added new code to Robot class to replace code from old GuiRobot class,
added 2s delay after gnome-keyring startup
author | Zdenek Zambersky <zzambers@redhat.com> |
---|---|
date | Tue, 31 Mar 2015 12:00:22 +0200 |
parents | 30e3eab8eecb |
children | 6310141695ae |
files | src/org/thermostat/qa2/framework/Robot.java src/org/thermostat/qa2/framework/ThermostatQAConfig.java src/org/thermostat/qa2/framework/services/GnomeKeyring.java |
diffstat | 3 files changed, 85 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/src/org/thermostat/qa2/framework/Robot.java Thu Mar 26 14:22:47 2015 +0100 +++ b/src/org/thermostat/qa2/framework/Robot.java Tue Mar 31 12:00:22 2015 +0200 @@ -30,68 +30,87 @@ */ package org.thermostat.qa2.framework; -import java.awt.AWTException; +import java.awt.Color; +import java.awt.Graphics2D; import java.awt.Rectangle; +import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.Arrays; -import org.thermostat.qa.common.Configuration; -import org.thermostat.qa.framework.GuiRobot; +import javax.imageio.ImageIO; +import org.thermostat.qa.framework.ImageProcessing; import static org.thermostat.qa2.framework.ThermostatQAConfig.getPatternsDir; import org.thermostat.qa2.framework.utils.CommonUtilities; +import org.thermostat.qa2.framework.utils.ProcessUtilities; /** * * @author Zdeněk Žamberský */ -// wrapper of original robot, to be used by gui tests public class Robot { - public Robot() throws AWTException { - Configuration c = new Configuration(null); - guiRobot = new GuiRobot(c); - } - - GuiRobot guiRobot; long delay = 500; long screenshotDelay = 5000; - public void pressDownKey() { - guiRobot.pressDownKey(); + BufferedImage screenCapture; + + public void pressUpKey() throws Exception { + ProcessUtilities.run("xdotool", "key", "--clearmodifiers", "Up"); CommonUtilities.sleep(delay); } - public void pressLeftKey() { - guiRobot.pressLeftKey(); + public void pressDownKey() throws Exception { + ProcessUtilities.run("xdotool", "key", "--clearmodifiers", "Down"); + CommonUtilities.sleep(delay); + } + + public void pressLeftKey() throws Exception { + ProcessUtilities.run("xdotool", "key", "--clearmodifiers", "Left"); + CommonUtilities.sleep(delay); + } + + public void pressRightKey() throws Exception { + ProcessUtilities.run("xdotool", "key", "--clearmodifiers", "Right"); CommonUtilities.sleep(delay); } - public void pressRightKey() { - guiRobot.pressRightKey(); - CommonUtilities.sleep(delay); - } - - public void pressEnterKey() { - guiRobot.pressEnterKey(); + public void pressEnterKey() throws Exception { + ProcessUtilities.run("xdotool", "key", "--clearmodifiers", "Return"); CommonUtilities.sleep(delay); } - public void clickOnRectangle(Rectangle rectangle) { - guiRobot.clickToRectangle(rectangle); + private void clickRaw(int x, int y) throws Exception { + ProcessUtilities.run("xdotool", "mousemove", Integer.toString(x), Integer.toString(y)); + ProcessUtilities.run("xdotool", "click", "--clearmodifiers", "1"); + } + + private void clickOnRectangleRaw(Rectangle rectangle) throws Exception { + int x = rectangle.x + rectangle.width / 2; + int y = rectangle.y + rectangle.height / 2; + clickRaw(x, y); + } + + public void clickOnRectangle(Rectangle rectangle) throws Exception { + clickOnRectangleRaw(rectangle); CommonUtilities.sleep(delay); } - public void doubleClickOnRectangle(Rectangle rectangle) { - guiRobot.clickToRectangle(rectangle); - guiRobot.clickToRectangle(rectangle); + public void doubleClickOnRectangle(Rectangle rectangle) throws Exception { + clickOnRectangleRaw(rectangle); + clickOnRectangleRaw(rectangle); CommonUtilities.sleep(delay); } - public void resize(Rectangle from, int xd, int yd) { - guiRobot.resize(from, xd, yd); + public void resize(Rectangle from, int xd, int yd) throws Exception { + ProcessUtilities.shellRun("win=`xdotool getactivewindow` ; xdotool windowsize $win " + (from.x + xd) + " " + (from.y + yd)); CommonUtilities.sleep(delay); } + private Rectangle findPatternRaw(String name) throws IOException { + BufferedImage marker = ImageIO.read(new File(name)); + return ImageProcessing.findPattern(marker, screenCapture); + } + public Rectangle findPattern(String name) throws IOException, Exception { System.out.println("INFO: searching for pattern: " + name); String patternName = getPatternsDir() + File.separator + name.replace("/", File.separator); @@ -100,7 +119,7 @@ String patternFile = patternName + ".png"; do { if (new File(patternFile).exists()) { - Rectangle rect = guiRobot.findPattern(patternFile); + Rectangle rect = findPatternRaw(patternFile); if (rect != null) { System.out.println("INFO: pattern: " + patternFile + ": FOUND"); return rect; @@ -121,7 +140,7 @@ if (rect == null) { throw new AssertionError("Pattern not found: " + name); } - guiRobot.highlightRectangle(rect); + highlightRectangle(screenCapture, rect); return rect; } @@ -137,13 +156,37 @@ throw new AssertionError("patterns: " + Arrays.toString(names) + "not found"); } - public void makeScreenshot(String name) throws IOException { + private static void highlightRectangle(BufferedImage testImage, Rectangle rect) { + Graphics2D graphics = (Graphics2D) testImage.getGraphics(); + Rectangle rect1 = getRectangleWithOffset(rect, 2); + Rectangle rect2 = getRectangleWithOffset(rect, 4); + graphics.setColor(Color.RED); + graphics.draw(rect1); + graphics.setColor(Color.BLACK); + graphics.draw(rect2); + graphics.dispose(); + } + + private static Rectangle getRectangleWithOffset(Rectangle rect, int offset) { + int x = rect.x - offset; + int y = rect.y - offset; + int width = rect.width + (offset << 1); + int height = rect.height + (offset << 1); + return new Rectangle(x, y, width, height); + } + + public void makeScreenshot(String name) throws Exception { CommonUtilities.sleep(screenshotDelay); - guiRobot.prepareScreenshot(name); + String path = "screenshots/" + name + ".png"; + System.out.println("INFO: making screenshot: " + path); + ProcessUtilities.run("import", "-window", "root", path); + screenCapture = ImageIO.read(new File(path)); } public void saveScreenshot(String name) throws IOException { - guiRobot.saveScreenshot(name); + String path = "screenshots/" + name + ".png"; + System.out.println("INFO: saving screenshot: " + path); + ImageIO.write(screenCapture, "png", new File(path)); } public void clickOnPattern(String name) throws Exception { @@ -166,8 +209,8 @@ doubleClickOnRectangle(rect); } - public void enterMainMenu() { - guiRobot.pressFNKey(10); + public void enterMainMenu() throws Exception { + ProcessUtilities.run("xdotool", "key", "--clearmodifiers", "F10"); CommonUtilities.sleep(delay); } @@ -186,8 +229,8 @@ checkForPattern("MainWindow/vm_icon_blue"); } - public void writeText(String text) { - guiRobot.writeSmallLettersText(text); + public void writeText(String text) throws Exception { + ProcessUtilities.run("xdotool", "type", "--clearmodifiers", text); } - + }
--- a/src/org/thermostat/qa2/framework/ThermostatQAConfig.java Thu Mar 26 14:22:47 2015 +0100 +++ b/src/org/thermostat/qa2/framework/ThermostatQAConfig.java Tue Mar 31 12:00:22 2015 +0200 @@ -198,7 +198,7 @@ } public static Login getCommandChannelLogin() { - return commandChannelLogin; + return clientLogin; } public static class Login {
--- a/src/org/thermostat/qa2/framework/services/GnomeKeyring.java Thu Mar 26 14:22:47 2015 +0100 +++ b/src/org/thermostat/qa2/framework/services/GnomeKeyring.java Tue Mar 31 12:00:22 2015 +0200 @@ -32,6 +32,7 @@ import org.thermostat.qa2.framework.NativeProcess; import org.thermostat.qa2.framework.ThermostatQAConfig; +import org.thermostat.qa2.framework.utils.CommonUtilities; /** * @@ -62,7 +63,8 @@ process.setLabel(getServiceName()); process.setEnvironmentVariable("XDG_DATA_HOME", configurationDirectory); process.start(); - process.waitFor(); + process.waitFor(); + CommonUtilities.sleep(2000); } @Override