# HG changeset patch # User Jana Fabrikova # Date 1396357748 -7200 # Node ID 3d06e2d323cbdba92c16e98b1d9b6578100a0eb3 # Parent 44af5584ec5938bb095f85830c25e90f98890bf8 refactoring of the framework+testsuites for gui tests so Xvfb+fluxbox may be used diff -r 44af5584ec59 -r 3d06e2d323cb ChangeLog --- a/ChangeLog Tue Apr 01 14:50:03 2014 +0200 +++ b/ChangeLog Tue Apr 01 15:09:08 2014 +0200 @@ -1,3 +1,34 @@ +2014-04-01 Jana Fabrikova + + * test.properties: + adding property screenshot_source which can have value dummy,normal,xvfb + for using pregenerated screenshots, normal screenshots from display :0, + or screenshots from display :1, if Xvfb+fluxbox runs prior to the tests + and DISPLAY is set to :1 + * src/org/thermostat/qa/common/ScreenshotSourceType.java: + adding new class - type of expected screenshots input for the gui testsuites + * src/org/thermostat/qa/common/Configuration.java: + modifying the Configuration class according to above changes + * Makefile: + adding new common class (ScreenshotSourceType) to the list of classes + * src/org/thermostat/qa/framework/Patterns.java: + modifying the icon list so it suits possible usage of xvfb+fluxbox for tests + * src/org/thermostat/qa/framework/GuiRobot.java: + * src/org/thermostat/qa/framework/ThermostatGuiTest.java: + * src/org/thermostat/qa/framework/ThermostatUtilities.java: + refactoring the framework - most of the logic (deciding about loading + pregenerated screenshots, or generating screenshots using AWT robot, + or generating screenshots using xdotool in Xvfb on display :1), is located + in the framework now, so the testsuites do not have to distinguish among + these three cases + * src/org/thermostat/qa/testsuites/DBGuiHeapDumpTest.java: + * src/org/thermostat/qa/testsuites/GuiClientDBModifWebStorageTest.java: + * src/org/thermostat/qa/testsuites/GuiClientDBModificationsSmokeTest.java: + * src/org/thermostat/qa/testsuites/GuiClientSmokeTest.java: + * src/org/thermostat/qa/testsuites/GuiClientWebStorageTest.java: + * src/org/thermostat/qa/testsuites/GuiHostViewSmokeTest.java: + refactoring the gui testsuites according to the above changes in the framework + 2014-04-01 Jana Fabrikova * patterns/1.1.0/noAA/AboutDialog/about_text_lower_part.png: diff -r 44af5584ec59 -r 3d06e2d323cb Makefile --- a/Makefile Tue Apr 01 14:50:03 2014 +0200 +++ b/Makefile Tue Apr 01 15:09:08 2014 +0200 @@ -58,6 +58,7 @@ $(BUILD_DIR)/$(ANNOTATIONS_PACKAGE)/StorageTypes.class \ $(BUILD_DIR)/$(ANNOTATIONS_PACKAGE)/StorageType.class \ $(BUILD_DIR)/$(COMMON_PACKAGE)/Configuration.class \ + $(BUILD_DIR)/$(COMMON_PACKAGE)/ScreenshotSourceType.class \ $(BUILD_DIR)/$(REPORTER_PACKAGE)/TestResult.class \ $(BUILD_DIR)/$(REPORTER_PACKAGE)/StringUtils.class \ $(BUILD_DIR)/$(REPORTER_PACKAGE)/FileUtils.class \ @@ -81,6 +82,8 @@ $(BUILD_DIR)/$(FRAMEWORK_PACKAGE)/ThermostatOutputTextsGenerator.class \ $(BUILD_DIR)/$(FRAMEWORK_PACKAGE)/GuiRobot.class \ $(BUILD_DIR)/$(FRAMEWORK_PACKAGE)/Patterns.class \ + $(BUILD_DIR)/$(FRAMEWORK_PACKAGE)/IconCut.class \ + $(BUILD_DIR)/$(FRAMEWORK_PACKAGE)/PatternDefinitionsGenerator.class \ $(BUILD_DIR)/$(TEST_PACKAGE)/AgentTest.class \ $(BUILD_DIR)/$(TEST_PACKAGE)/CliClientSmokeTest.class \ $(BUILD_DIR)/$(TEST_PACKAGE)/GuiClientSmokeTest.class \ @@ -133,6 +136,14 @@ mkdir -p outputtexts/`cat test.properties | grep thermostat_version | sed -e 's/^.*=//g;s/$$//g'` java -cp $(BUILD_DIR) org.thermostat.qa.framework.ThermostatOutputTextsGenerator +#make icons in given dir smaller / remove unnecessary pixels +cuticons: $(ALL_CLASSES) + java -cp $(BUILD_DIR) org.thermostat.qa.framework.IconCut + +#generate pattern defs on std output +patternsdef: $(ALL_CLASSES) + java -cp $(BUILD_DIR) org.thermostat.qa.framework.PatternDefinitionsGenerator + # targets for all test suites TESTSUITES = $(shell ls -1 $(SOURCE_DIR)/$(TEST_PACKAGE) | sed -n -e 's/\([A-Za-z0-9]*\)\.java/\1/p') @@ -151,6 +162,8 @@ cp -u $(TEMPLATE_DIR)/style.css $(REPORT_DIR)/style.css cp -r $(TEMPLATE_DIR)/flotr $(REPORT_DIR) $(JAVA) -cp $(BUILD_DIR) org.thermostat.qa.reporter.Reporter -template-dir=$(TEMPLATE_DIR) -log-dir=$(LOGS_DIR) -report-dir=$(REPORT_DIR) -date=$(DATE) -tests="$(TESTS)" + sed -i 's/ignored/not applicable/g' $(REPORT_DIR)/log_$(DATE).html + sed -i 's/IGNORED/NOT APPLICABLE/g' $(REPORT_DIR)/log_$(DATE).html links -dump $(REPORT_DIR)/index.html 2>/dev/null > $(REPORT_DIR)/$(DAILY_REPORT_NAME) || \ w3m -dump $(REPORT_DIR)/index.html 2>/dev/null > $(REPORT_DIR)/$(DAILY_REPORT_NAME) || \ lynx -dump $(REPORT_DIR)/index.html -force_html 2>/dev/null > $(REPORT_DIR)/$(DAILY_REPORT_NAME) diff -r 44af5584ec59 -r 3d06e2d323cb src/org/thermostat/qa/common/Configuration.java --- a/src/org/thermostat/qa/common/Configuration.java Tue Apr 01 14:50:03 2014 +0200 +++ b/src/org/thermostat/qa/common/Configuration.java Tue Apr 01 15:09:08 2014 +0200 @@ -51,10 +51,10 @@ private String thermostatUserHome = null; private String apacheTomcatHome = null; private boolean performCleaningAfterGuiTests = false; + + //the way how the screenshots will be provided + private ScreenshotSourceType screenshotsSource = null; - // if true -> gfx tests would be run against pre-generated screenshots - private static boolean dummyGfxTests = false; - public Configuration(String[] args) { readConfiguration(); @@ -110,9 +110,30 @@ this.thermostatUserHome = properties.getProperty("thermostat_user_home"); this.apacheTomcatHome = properties.getProperty("apache_tomcat_home"); + String str = properties.getProperty("screenshot_source"); + if( str.equals("dummy") ){ + this.screenshotsSource = ScreenshotSourceType.DUMMY; + }else if( str.equals("normal")){ + this.screenshotsSource = ScreenshotSourceType.NORMAL; + }else if( str.equals("xvfb")){ + this.screenshotsSource = ScreenshotSourceType.XVFB; + } + this.performCleaningAfterGuiTests = properties.getProperty("clean_after_gui_test").equals("true"); } + public ScreenshotSourceType getScreenshotsSource() { + return screenshotsSource; + } + + public boolean useDummyScreenshots(){ + return (this.screenshotsSource == ScreenshotSourceType.DUMMY); + } + + public boolean useRealScreenshots(){ + return (this.screenshotsSource != ScreenshotSourceType.DUMMY); + } + public String getThermostatVersion() { return this.thermostatVersion; @@ -143,21 +164,8 @@ return this.apacheTomcatHome; } - public boolean useDummyGfxTests() - { - return dummyGfxTests; - } - public boolean useRealGfxTests() - { - return !dummyGfxTests; - } - - public void setDummyGfxTests(boolean dummyGfxTests) - { - Configuration.dummyGfxTests = dummyGfxTests; - } - + public boolean getPerformCleaningAfterGuiTests() { return performCleaningAfterGuiTests; } diff -r 44af5584ec59 -r 3d06e2d323cb src/org/thermostat/qa/common/ScreenshotSourceType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/thermostat/qa/common/ScreenshotSourceType.java Tue Apr 01 15:09:08 2014 +0200 @@ -0,0 +1,49 @@ +/* + + ThermostatQA - test framework for Thermostat Monitoring Tool + + Copyright 2014 Red Hat, Inc. + +This file is part of ThermostatQA + +ThermostatQA is distributed under the GNU General Public License, +version 2 or any later version (with a special exception described +below, commonly known as the "Classpath Exception"). + +A copy of GNU General Public License (GPL) is included in this +distribution, in the file COPYING. + +Linking ThermostatQA code with other modules is making a combined work +based on ThermostatQA. Thus, the terms and conditions of the GPL +cover the whole combination. + +As a special exception, the copyright holders of ThermostatQA give you +permission to link this code with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on ThermostatQA code. If you modify ThermostatQA, you may +extend this exception to your version of the software, but you are +not obligated to do so. If you do not wish to do so, delete this +exception statement from your version. +*/ + +package org.thermostat.qa.common; + +/** + * Type ScreenshotSourceType specifies how the screenshots will be provided, + * the possibilities are: + *
    + *
  • DUMMY - load a pregenerated screenshot, + *
  • NORMAL - capture the classic screen, + *
  • XVFB - capture the Xvfb display. + *
+ */ +public enum ScreenshotSourceType +{ + DUMMY, + NORMAL, + XVFB +} diff -r 44af5584ec59 -r 3d06e2d323cb src/org/thermostat/qa/framework/GuiRobot.java --- a/src/org/thermostat/qa/framework/GuiRobot.java Tue Apr 01 14:50:03 2014 +0200 +++ b/src/org/thermostat/qa/framework/GuiRobot.java Tue Apr 01 15:09:08 2014 +0200 @@ -43,6 +43,14 @@ import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.util.LinkedList; +import java.util.List; + + + + + + @@ -50,6 +58,17 @@ + + + + + + +import org.thermostat.qa.common.Configuration; +import org.thermostat.qa.common.ScreenshotSourceType; + + + /** * Class used for automatic mouse and keyboard system events generation. This * class also contains methods for capturing the screenshot and for finding some @@ -73,10 +92,15 @@ Robot robot = null; BufferedImage screenCapture = null; + + Configuration config = null; + ScreenshotSourceType scrSource = null; - public GuiRobot() throws AWTException + public GuiRobot(Configuration c) throws AWTException { this.robot = new Robot(); + this.config = c; + this.scrSource = c.getScreenshotsSource(); } /** @@ -103,6 +127,24 @@ return this.screenCapture; } + + + public Configuration getConfig() { + return config; + } + + public void setConfig(Configuration config) { + this.config = config; + } + + public ScreenshotSourceType getScrSource() { + return scrSource; + } + + public void setScrSource(ScreenshotSourceType scrSource) { + this.scrSource = scrSource; + } + /** * @param screenCapture the screenCapture to set */ @@ -111,7 +153,33 @@ this.screenCapture = screenCapture; } - public void createScreenCapture() + public void prepareScreenshot(String fileName) throws IOException + { + switch(scrSource){ + case DUMMY: + loadScreenshot(fileName); + break; + case NORMAL: + createScreenCapture(); + saveScreenshot(fileName); + break; + case XVFB: + createXvbfScreenCaptureFile(fileName); + loadScreenshot(fileName); + break; + }; + } + + /*using import command*/ + private void createXvbfScreenCaptureFile(String fileName) throws IOException + { + //import -display :1 -window root screenshots/fileName.png + List content = new LinkedList(); + content.add("import -display :1 -window root screenshots/"+fileName+".png"); + ThermostatUtilities.runBashScriptWithContent("xvfbScreenCapture.sh", content); + } + + private void createScreenCapture() { Rectangle screenRectangle = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); setScreenCapture(getRobot().createScreenCapture(screenRectangle)); @@ -161,34 +229,69 @@ } /** + * Method click has + * 3 cases - for NORMAL screenshot source moves the regular mouse, + * for XVFB uses the import command, for DUMMY does nothing + * * @param x * @param y */ private void click(int x, int y) { - this.robot.mouseMove(x, y); - this.robot.delay(ROBOT_DELAY); - this.robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); - this.robot.delay(ROBOT_DELAY); - this.robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + + switch(scrSource){ + case DUMMY: + //do nothing + break; + + case NORMAL: + //operate with the mouse on regular display + this.robot.mouseMove(x, y); + this.robot.delay(ROBOT_DELAY); + this.robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + this.robot.delay(ROBOT_DELAY); + this.robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + break; + + case XVFB: + //use xdotool to click on xvfb screen + //export DISPLAY=:1 + //xdotool mousemove x y + //xdotool click --clearmodifiers 1 + List content = new LinkedList(); + content.add("export DISPLAY=:1"); + content.add("xdotool mousemove "+x+" "+y); + content.add("xdotool click --clearmodifiers 1"); + try + { + ThermostatUtilities.runBashScriptWithContent("xvfbScreenCapture.sh", content); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + break; + }; } - public void pressKey(int keycode) - { - robot.keyPress(keycode); - robot.delay(KEY_PRESS_DELAY); - robot.keyRelease(keycode); + private void pressAWTKey(int keycode) + { //send keys via awt robot + robot.keyPress(keycode); + robot.delay(KEY_PRESS_DELAY); + robot.keyRelease(keycode); } /** - * Method press2Keys - * presses key2 while key1 is pressed, then release both. + * Method press2Keys uses AWT robot to + * press key2 while key1 is pressed, then release both. * Can be used e.g. to press key1=CTRL and key2=S to get CTRL+S. * * @param key1 * @param key2 */ - public void press2Keys(int key1, int key2) + public void press2AWTKeys(int key1, int key2) { + //send keys via awt robot robot.keyPress(key1); robot.delay(KEY_PRESS_DELAY); robot.keyPress(key2); @@ -198,17 +301,54 @@ robot.keyRelease(key1); } - public void pressCtrlPlusKey(int keycode) + /** + * Method pressCtrlPlusSmallLetter + * gets one parameter - char letter, works for both normal screenshots + * (then it uses AWT robot) and for Xvfb (then xdotool is used). + * + * @param c + */ + public void pressCtrlPlusSmallLetter(char c) { - press2Keys(KeyEvent.VK_CONTROL, keycode); + switch(scrSource){ + case DUMMY: + //do nothing + break; + + case NORMAL: + //send keys via awt robot + int keycode = KeyEvent.VK_A + c - 'a'; + press2AWTKeys(KeyEvent.VK_CONTROL, keycode); + break; + + case XVFB: + //TODO - does this work with the given keycodes? + //use xdotool to type for xvfb + List content = new LinkedList(); + content.add("export DISPLAY=:1"); + content.add("xdotool key Ctrl+"+(char)c); + try + { + ThermostatUtilities.runBashScriptWithContent("xvfbPressCtrlAndSmallLetter.sh", content); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + break; + }; + } /** * Method resize - * gets a small rectangle where the right lower corner of the gui is, + * 3 cases - does nothing if screenshot config is DUMMY, + * - gets a small rectangle where the right lower corner of the gui is, * and number of x and y pixels by which the window should be resized. * It uses mouse and resizes the gui window, while adding sufficient - * time delays between the mouse actions. + * time delays between the mouse actions, + * - uses xdotool to resize the active window * * @param from * @param xd @@ -216,19 +356,46 @@ */ public void resize(Rectangle from, int xd, int yd) { - int x = from.x + from.width - 4; - int y = from.y + from.height - 4; - robot.mouseMove(x, y); - robot.delay(ROBOT_DELAY); - x += 4; - y += 4; - robot.mouseMove(x, y); - robot.delay(ROBOT_DELAY); - robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); - robot.delay(ROBOT_DELAY); - robot.mouseMove(x+xd, y+yd); - robot.delay(ROBOT_DELAY); - robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + switch(scrSource){ + case DUMMY: + //do nothing + break; + + case NORMAL: + //send keys via awt robot + int x = from.x + from.width - 4; + int y = from.y + from.height - 4; + robot.mouseMove(x, y); + robot.delay(ROBOT_DELAY); + x += 4; + y += 4; + robot.mouseMove(x, y); + robot.delay(ROBOT_DELAY); + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.delay(ROBOT_DELAY); + robot.mouseMove(x+xd, y+yd); + robot.delay(ROBOT_DELAY); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + break; + + case XVFB: + //TODO - insert code with xdotool for (activating and) + //resizing the thermostat window + List content = new LinkedList(); + content.add("export DISPLAY=:1"); + //content.add("xdotool click "+(from.x + from.width<<1)+" "+(from.y + from.height<<1)); + content.add("xdotool windowsize --usehints getactivewindow "+(from.width + xd)+" "+(from.height + yd)); + try + { + ThermostatUtilities.runBashScriptWithContent("xvfbResize.sh", content); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + break; + }; } /** @@ -269,4 +436,258 @@ graphics.draw(rect2); } + public void pressFNKey(int N) { + + switch(scrSource){ + case DUMMY: + //do nothing + break; + + case NORMAL: + //send keys via awt robot + int keycode = KeyEvent.VK_F1 + N -1; + pressAWTKey(keycode); + break; + + case XVFB: + //xdotool command for entering FN + List content = new LinkedList(); + content.add("export DISPLAY=:1"); + content.add("xdotool key -clearmodifiers F"+N); + try + { + ThermostatUtilities.runBashScriptWithContent("xvfbResize.sh", content); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + break; + }; + } + + public void pressRightKey() { + switch(scrSource){ + case DUMMY: + //do nothing + break; + + case NORMAL: + //send keys via awt robot + pressAWTKey(KeyEvent.VK_RIGHT); + break; + + case XVFB: + //TODO - does this work with the given keycodes? + //use xdotool to type for xvfb + //export DISPLAY=:1 + //xdotool key right + List content = new LinkedList(); + content.add("export DISPLAY=:1"); + content.add("xdotool key -clearmodifiers Right"); + try + { + ThermostatUtilities.runBashScriptWithContent("xvfbPressRightKey.sh", content); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + break; + }; + + } + + public void pressLeftKey() { + switch(scrSource){ + case DUMMY: + //do nothing + break; + + case NORMAL: + //send keys via awt robot + pressAWTKey(KeyEvent.VK_LEFT); + break; + + case XVFB: + //TODO - does this work with the given keycodes? + //use xdotool to type for xvfb + //export DISPLAY=:1 + //xdotool key right + List content = new LinkedList(); + content.add("export DISPLAY=:1"); + content.add("xdotool key -clearmodifiers Left"); + try + { + ThermostatUtilities.runBashScriptWithContent("xvfbPressLeftKey.sh", content); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + break; + }; + } + + public void pressDownKey() { + switch(scrSource){ + case DUMMY: + //do nothing + break; + + case NORMAL: + //send keys via awt robot + pressAWTKey(KeyEvent.VK_DOWN); + break; + + case XVFB: + //TODO - does this work with the given keycodes? + //use xdotool to type for xvfb + List content = new LinkedList(); + content.add("export DISPLAY=:1"); + content.add("xdotool key -clearmodifiers Down"); + try + { + ThermostatUtilities.runBashScriptWithContent("xvfbPressDownKey.sh", content); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + break; + }; + } + + public void pressEnterKey() { + switch(scrSource){ + case DUMMY: + //do nothing + break; + + case NORMAL: + //send keys via awt robot + pressAWTKey(KeyEvent.VK_ENTER); + break; + + case XVFB: + //TODO - does this work with the given keycodes? + //use xdotool to type for xvfb + List content = new LinkedList(); + content.add("export DISPLAY=:1"); + content.add("xdotool key -clearmodifiers Return"); + try + { + ThermostatUtilities.runBashScriptWithContent("xvfbPressEnterKey.sh", content); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + break; + }; + } + + public void writeSmallLettersText(String string) { + // TODO vyzkouset + switch(scrSource) + { + case DUMMY: + //do nothing; + break; + case NORMAL: + //type letters successively using awt robot + for(int i=0; i content = new LinkedList(); + content.add("export DISPLAY=:1"); + content.add("xdotool type -clearmodifiers "+string); + try + { + ThermostatUtilities.runBashScriptWithContent("xvfbWriteSmallLettersText.sh", content); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + break; + } + } + + public void writeSpecialChar(char c) { + // TODO vyzkouset, jak to funguje + switch(scrSource) + { + case DUMMY: + //do nothing; + break; + case NORMAL: + switch(c){ + case '-': + pressAWTKey(KeyEvent.VK_MINUS); + break; + } + break; + case XVFB: + //type the character using xdotool + List content = new LinkedList(); + content.add("export DISPLAY=:1"); + content.add("xdotool type -clearmodifiers "+(char)c); + try + { + ThermostatUtilities.runBashScriptWithContent("xvfbWriteSpecialChar.sh", content); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + break; + } + } + + public void writeNumbersText(String string) { + // TODO vyzkouset + switch(scrSource) + { + case DUMMY: + //do nothing; + break; + case NORMAL: + //type letters successively using awt robot + for(int i=0; i content = new LinkedList(); + content.add("export DISPLAY=:1"); + content.add("xdotool type -clearmodifiers "+string); + try + { + ThermostatUtilities.runBashScriptWithContent("xvfbWriteNumbersText.sh", content); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + break; + } + } + } diff -r 44af5584ec59 -r 3d06e2d323cb src/org/thermostat/qa/framework/Patterns.java --- a/src/org/thermostat/qa/framework/Patterns.java Tue Apr 01 14:50:03 2014 +0200 +++ b/src/org/thermostat/qa/framework/Patterns.java Tue Apr 01 15:09:08 2014 +0200 @@ -37,7 +37,7 @@ public static class FailureToConnectToStorageDialog { public static final String ERROR_ICON = "FailureToConnectToStorageDialog/error_icon"; - public static final String CONFIGURE_BUTTON = "FailureToConnectToStorageDialog/configure_button"; + public static final String CONFIGURE_BUTTON[] = {"FailureToConnectToStorageDialog/configure_button", "FailureToConnectToStorageDialog/configure_button2","FailureToConnectToStorageDialog/configure_button3"}; public static final String[] QUIT_BUTTON = {"FailureToConnectToStorageDialog/quit_button", "FailureToConnectToStorageDialog/quit_button_mouseover"}; } @@ -93,7 +93,7 @@ public static final String THERMOSTAT_LOGO = "AboutDialog/thermostat_logo"; public static final String THERMOSTAT_TITLE = "AboutDialog/thermostat_title"; public static final String UPPER_TEXT = "AboutDialog/about_text_upper_part"; - public static final String[] LOWER_TEXT = {"AboutDialog/about_text_lower_part3", "AboutDialog/about_text_lower_part","AboutDialog/about_text_lower_part2"}; + public static final String[] LOWER_TEXT = {"AboutDialog/about_text_lower_part", "AboutDialog/about_text_lower_part3","AboutDialog/about_text_lower_part2"}; } public static class SummaryTab diff -r 44af5584ec59 -r 3d06e2d323cb src/org/thermostat/qa/framework/ThermostatGuiTest.java --- a/src/org/thermostat/qa/framework/ThermostatGuiTest.java Tue Apr 01 14:50:03 2014 +0200 +++ b/src/org/thermostat/qa/framework/ThermostatGuiTest.java Tue Apr 01 15:09:08 2014 +0200 @@ -35,10 +35,20 @@ import java.awt.AWTException; import java.awt.Rectangle; import java.awt.RenderingHints; +import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.io.IOException; import java.lang.reflect.Method; + + +import java.util.LinkedList; +import java.util.List; + + + +import org.thermostat.qa.framework.ThermostatUtilities.AgentThread; + public abstract class ThermostatGuiTest extends ThermostatTest { private static final String PATTERNS_DIRECTORY = "patterns"; @@ -98,14 +108,83 @@ return false; } } + + public void setupForGuiTests() + { + switch(this.configuration.getScreenshotsSource()){ + case DUMMY: + //do nothing + break; + + case NORMAL: + //do nothing + break; + + case XVFB: + //TODO - run script that starts Xvfb and fluxbox + //export DISPLAY=:1 + //Xvfb :1 -screen 0 1024x768x24 & + //fluxbox & + List content = new LinkedList(); + content.add("export DISPLAY=:1"); + content.add("Xvfb :1 -screen 0 1024x768x24 &"); + content.add("fluxbox 2>err &"); + try + { + ThermostatUtilities.runBashScriptWithContent("xvfbStart.sh", content); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + break; + }; + } + + public void tearDownGuiTests() + { + switch(this.configuration.getScreenshotsSource()){ + case DUMMY: + //do nothing + break; + + case NORMAL: + //do nothing + break; + + case XVFB: + //TODO - run script that stops Xvfb and fluxbox + //killall Xvfb + //killall fluxbox + List content = new LinkedList(); + content.add("killall fluxbox"); + content.add("killall Xvfb"); + try + { + ThermostatUtilities.runBashScriptWithContent("xvfbStop.sh", content); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + break; + }; + } /** * Start Thermostat GUI client in a new thread. */ protected void runThermostatGuiInANewThread() { - new GuiThread().start(); - logInfo("runThermostatGuiInANewThread", "Thermostat GUI started"); + if(this.configuration.useRealScreenshots()) + { + new GuiThread().start(); + logInfo("runThermostatGuiInANewThread", "Thermostat GUI started"); + }else{ + logInfo("runThermostatGuiInANewThread", "Thermostat GUI not started, because using dummy screenshots"); + } } /** @@ -113,7 +192,7 @@ */ protected GuiRobot startStorageOnly() throws AWTException { - GuiRobot robot = new GuiRobot(); + GuiRobot robot = new GuiRobot(this.configuration); startStorage(); return robot; } @@ -121,19 +200,18 @@ /** * Start Thermostat storage and also Thermostat GUI client in a new thread. */ - protected GuiRobot startThermostatAndStorage(String screenshotName) throws AWTException, IOException + protected GuiRobot startThermostatAndStorage() throws AWTException, IOException { - GuiRobot robot = new GuiRobot(); + GuiRobot robot = new GuiRobot(this.configuration); - if (this.configuration.useDummyGfxTests()) - { - robot.loadScreenshot(screenshotName); - } - else + if (this.configuration.useRealScreenshots()) { startStorage(); runThermostatGuiInANewThread(); + logInfo("runThermostatGuiInANewThread", "Thermostat GUI+storage started"); sleep(FIVE_SEC); + }else{ + logInfo("runThermostatGuiInANewThread", "Thermostat GUI+storage not started, because using dummy screenshots"); } return robot; } @@ -142,19 +220,18 @@ * Start Thermostat web storage and also Thermostat GUI client in a new * thread. */ - protected GuiRobot startThermostatAndWebStorage(String screenshotName) throws AWTException, IOException + protected GuiRobot startThermostatAndWebStorage() throws AWTException, IOException { - GuiRobot robot = new GuiRobot(); + GuiRobot robot = new GuiRobot(this.configuration); - if (this.configuration.useDummyGfxTests()) - { - robot.loadScreenshot(screenshotName); - } - else + if (this.configuration.useRealScreenshots()) { startWebStorage(); runThermostatGuiInANewThread(); + logInfo("runThermostatGuiInANewThread", "Thermostat GUI+web storage started"); sleep(FIVE_SEC); + }else{ + logInfo("runThermostatGuiInANewThread", "Thermostat GUI+web storage not started, because using dummy screenshots"); } return robot; } @@ -245,7 +322,7 @@ */ protected void stopThermostatAndStorage(GuiRobot robot) throws IOException { - if (this.configuration.useRealGfxTests()) + if (this.configuration.useRealScreenshots()) { stopStorage(); stopGUI(robot); @@ -257,7 +334,7 @@ */ protected void stopThermostatAndWebStorage(GuiRobot robot) throws IOException { - if (this.configuration.useRealGfxTests()) + if (this.configuration.useRealScreenshots()) { stopWebStorage(); stopGUI(robot); @@ -265,21 +342,87 @@ } /** - * Create screenshot after some slight delay. + * Method createScreenshot distinguishes 3 cases from the configuration + *
    + *
  • loading a gtx screenshot, + *
  • creating a new screenshot in a classical way from the visible + * display, + *
  • creating a new screenshot using Xvbf + *
+ * + * @param robot + * @param screenshotName + * @throws IOException */ - protected void createScreenshot(GuiRobot robot, String screenshotName) throws IOException + protected void prepareScreenshot(GuiRobot robot, String screenshotName) throws IOException { sleep(ONE_SEC); - robot.createScreenCapture(); - robot.saveScreenshot(screenshotName); + robot.prepareScreenshot(screenshotName); } + public void sleepIfRealScreen(int ms) + { + if(this.configuration.useRealScreenshots()) + { + sleep(ms); + } + } + /** * Move focus to the Thermostat GUI client main menu by simulating F10 key press action. */ protected void enterMainMenu(GuiRobot robot) { - robot.pressKey(KeyEvent.VK_F10); + robot.pressFNKey(10); + } + + /** + * Method clickOnVMView starts the gui and activates the VM view. + * This method distinguishes between the case when we need real + * screenshots and dummy screenshots. The if statements are not that + * necessary, they only cut the delays created by (sleep) when dummy + * screenshots are being used. + * + * @return + * @throws IOException + * @throws AWTException + */ + protected GuiRobot clickOnVMView() throws IOException, AWTException{ + //start storage + GuiRobot robot = startStorageOnly(); + //start agent + new AgentThread().start(); + logInfo("runAgentThread", "Thermostat Agent started"); + + //start gui + runThermostatGuiInANewThread(); + sleepIfRealScreen(15000); + + robot.prepareScreenshot("GuiStarted1"); + + //if only host icon is visible, click the '>' icon to see all its vms + Rectangle r = findPattern(robot, Patterns.MainWindow.HOST_ICON_WITH_ARROW, "host view icon with arrow"); + if(r != null) + { + r.width = 6; + robot.clickToRectangle(r); + sleepIfRealScreen(ONE_SEC); + } + robot.prepareScreenshot("GuiStarted2"); + + r = checkForPattern(robot, Patterns.MainWindow.VM_VIEW_ICON, "vm view icon"); + + if(r != null) + { + robot.clickToRectangle(r); + sleepIfRealScreen(2000); + } + robot.prepareScreenshot("VMViewActive1"); + + checkForPattern(robot, Patterns.MainWindow.VM_VIEW_ICON_ACTIVE, "vm view active icon"); + robot.saveScreenshot("VMViewActive2"); + + return robot; } } diff -r 44af5584ec59 -r 3d06e2d323cb src/org/thermostat/qa/framework/ThermostatUtilities.java --- a/src/org/thermostat/qa/framework/ThermostatUtilities.java Tue Apr 01 14:50:03 2014 +0200 +++ b/src/org/thermostat/qa/framework/ThermostatUtilities.java Tue Apr 01 15:09:08 2014 +0200 @@ -244,7 +244,7 @@ * @return * @throws IOException */ - public List readProcessOutput(Process process) throws IOException + public static List readProcessOutput(Process process) throws IOException { List out = new ArrayList(); BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(process.getInputStream())); @@ -263,7 +263,7 @@ * @return * @throws IOException */ - protected Process runProcess(String... cmd) throws IOException + protected static Process runProcess(String... cmd) throws IOException { return Runtime.getRuntime().exec(cmd); } @@ -301,7 +301,7 @@ * @param flags * @return */ - private boolean useFlags(String... flags) + private static boolean useFlags(String... flags) { return !(flags == null || flags.length == 0 || flags[0] == null); } @@ -312,7 +312,7 @@ * @return * @throws IOException */ - protected List runHelperBashScript(String scriptName, String... params) throws IOException + public static List runHelperBashScript(String scriptName, String... params) throws IOException { String readScriptName = "./scripts/" + scriptName; @@ -336,7 +336,7 @@ * @param scriptName * @throws IOException */ - protected void makeScriptExecutable(String scriptName) throws IOException + protected static void makeScriptExecutable(String scriptName) throws IOException { String[] cmdArray = new String[]{"chmod","+x","./scripts/"+scriptName}; Runtime.getRuntime().exec(cmdArray); @@ -354,7 +354,7 @@ * @return * @throws IOException */ - protected List runBashScriptWithContent(String scriptName, List content, String... params) throws IOException + public static List runBashScriptWithContent(String scriptName, List content, String... params) throws IOException { //write content into a file in ./scripts FileUtils.writeTextFile("./scripts/"+scriptName, content); @@ -507,7 +507,7 @@ protected void stopGUI(GuiRobot robot) { - robot.pressCtrlPlusKey(KeyEvent.VK_Q); + robot.pressCtrlPlusSmallLetter('q'); } protected void startWebStorage() throws IOException diff -r 44af5584ec59 -r 3d06e2d323cb src/org/thermostat/qa/testsuites/DBGuiHeapDumpTest.java --- a/src/org/thermostat/qa/testsuites/DBGuiHeapDumpTest.java Tue Apr 01 14:50:03 2014 +0200 +++ b/src/org/thermostat/qa/testsuites/DBGuiHeapDumpTest.java Tue Apr 01 15:09:08 2014 +0200 @@ -71,57 +71,6 @@ private List scriptOutput; private GuiRobot robot; - private GuiRobot clickOnVMView() throws IOException, AWTException{ - //start storage - GuiRobot robot = startStorageOnly(); - //start agent - new AgentThread().start(); - logInfo("runAgentThread", "Thermostat Agent started"); - - if (this.configuration.useDummyGfxTests()) - { - robot.loadScreenshot("GuiStarted1"); - } - else - { - //start gui - runThermostatGuiInANewThread(); - sleep(15000); - robot.createScreenCapture(); - robot.saveScreenshot("GuiStarted1"); - } - - //if only host icon is visible, click the '>' icon to see all its vms - Rectangle r = findPattern(robot, Patterns.MainWindow.HOST_ICON_WITH_ARROW, "host view icon with arrow"); - if(r != null) - { - r.width = 6; - robot.clickToRectangle(r); - sleep(ONE_SEC); - robot.createScreenCapture(); - robot.saveScreenshot("GuiStarted2"); - } - - r = checkForPattern(robot, Patterns.MainWindow.VM_VIEW_ICON, "vm view icon"); - robot.clickToRectangle(r); - - if (this.configuration.useDummyGfxTests()) - { - robot.loadScreenshot("VMViewActive1"); - } - else - { - sleep(2000); - robot.createScreenCapture(); - robot.saveScreenshot("VMViewActive1"); - } - - checkForPattern(robot, Patterns.MainWindow.VM_VIEW_ICON_ACTIVE, "vm view active icon"); - robot.saveScreenshot("VMViewActive2"); - - return robot; - } - private GuiRobot dumpAHeap() throws IOException, AWTException { robot = clickOnVMView(); @@ -130,16 +79,9 @@ Rectangle r = checkForPattern(robot, Patterns.VMView.HEAP_ANALYZER_TAB, "heap analyzer tab"); robot.clickToRectangle(r); - if (this.configuration.useDummyGfxTests()) - { - robot.loadScreenshot("VMViewHeapAnalyzer1"); - } - else - { - sleep(2000); - robot.createScreenCapture(); - robot.saveScreenshot("VMViewHeapAnalyzer1"); - } + sleepIfRealScreen(2000); + robot.prepareScreenshot("VMViewHeapAnalyzer1"); + checkForPattern(robot, Patterns.VMView.HEAP_ANALYZER_TAB_CHOSEN, "heap analyzer tab chosen"); robot.saveScreenshot("VMViewHeapAnalyzer2"); diff -r 44af5584ec59 -r 3d06e2d323cb src/org/thermostat/qa/testsuites/GuiClientDBModifWebStorageTest.java --- a/src/org/thermostat/qa/testsuites/GuiClientDBModifWebStorageTest.java Tue Apr 01 14:50:03 2014 +0200 +++ b/src/org/thermostat/qa/testsuites/GuiClientDBModifWebStorageTest.java Tue Apr 01 15:09:08 2014 +0200 @@ -120,23 +120,23 @@ // start gui runThermostatGuiInANewThread(); - sleep(7000); + sleepIfRealScreen(7000); // see agent in the list of all agents enterMainMenu(robot); - robot.pressKey(KeyEvent.VK_RIGHT); - robot.pressKey(KeyEvent.VK_RIGHT); - robot.pressKey(KeyEvent.VK_DOWN); - sleep(500); - robot.pressKey(KeyEvent.VK_ENTER); + robot.pressRightKey(); + robot.pressRightKey(); + robot.pressDownKey(); + sleepIfRealScreen(500); + robot.pressEnterKey(); - createScreenshot(robot, "testAddAgentAndSeeItInGUITest1"); + prepareScreenshot(robot, "testAddAgentAndSeeItInGUIWSTest1"); Rectangle r1 = findPattern(robot, Patterns.AllAgentsDialog.ADDED_AGENT, "all agents dialog/added agent"); Assert.assertNotNull(r1, "all agents dialog/added agent cannot be found"); - robot.saveScreenshot("testAddAgentAndSeeItInGUITest2"); + robot.saveScreenshot("testAddAgentAndSeeItInGUIWSTest2"); // close all agents view // we need to click on "Close" button that does not have focus :-/ @@ -154,7 +154,7 @@ Assert.assertNotNull(rect, "Close button can't be found!"); - robot.saveScreenshot("testAllAgentsDialogTest2"); + robot.saveScreenshot("testAllAgentsDialogTestWS2"); } public static void main(String[] args) { diff -r 44af5584ec59 -r 3d06e2d323cb src/org/thermostat/qa/testsuites/GuiClientDBModificationsSmokeTest.java --- a/src/org/thermostat/qa/testsuites/GuiClientDBModificationsSmokeTest.java Tue Apr 01 14:50:03 2014 +0200 +++ b/src/org/thermostat/qa/testsuites/GuiClientDBModificationsSmokeTest.java Tue Apr 01 15:09:08 2014 +0200 @@ -117,12 +117,12 @@ // see agent in the list of all agents enterMainMenu(robot); - robot.pressKey(KeyEvent.VK_RIGHT); - robot.pressKey(KeyEvent.VK_RIGHT); - robot.pressKey(KeyEvent.VK_DOWN); - robot.pressKey(KeyEvent.VK_ENTER); + robot.pressRightKey(); + robot.pressRightKey(); + robot.pressDownKey(); + robot.pressEnterKey(); - createScreenshot(robot, "testAddAgentAndSeeItInGUITest1"); + prepareScreenshot(robot, "testAddAgentAndSeeItInGUITest1"); Rectangle r1 = findPattern(robot, Patterns.AllAgentsDialog.ADDED_AGENT, "all agents dialog/added agent"); diff -r 44af5584ec59 -r 3d06e2d323cb src/org/thermostat/qa/testsuites/GuiClientSmokeTest.java --- a/src/org/thermostat/qa/testsuites/GuiClientSmokeTest.java Tue Apr 01 14:50:03 2014 +0200 +++ b/src/org/thermostat/qa/testsuites/GuiClientSmokeTest.java Tue Apr 01 15:09:08 2014 +0200 @@ -32,15 +32,11 @@ package org.thermostat.qa.testsuites; - - import java.awt.AWTException; import java.awt.Rectangle; import java.awt.event.KeyEvent; import java.io.IOException; - - import org.thermostat.qa.annotations.TestType; import org.thermostat.qa.annotations.TestTypes; import org.thermostat.qa.framework.Assert; @@ -49,6 +45,7 @@ import org.thermostat.qa.framework.ThermostatGuiTest; import org.thermostat.qa.annotations.TillVersion; import org.thermostat.qa.annotations.SinceVersion; +import org.thermostat.qa.common.ScreenshotSourceType; @@ -66,13 +63,13 @@ @Override protected void setUp() { - // TODO Auto-generated method stub + //setupForGuiTests(); } @Override protected void tearDown() { - // TODO Auto-generated method stub + //tearDownGuiTests(); } /** @@ -91,30 +88,19 @@ */ public void testStartGUIWithoutStorage() throws IOException, AWTException { - GuiRobot robot = new GuiRobot(); + GuiRobot robot = new GuiRobot(this.configuration); - if (this.configuration.useDummyGfxTests()) - { - robot.loadScreenshot("FailureToConnectToStorageDialog1"); - } - else - { - runThermostatGuiInANewThread(); - sleep(FIVE_SEC); - robot.createScreenCapture(); - robot.saveScreenshot("FailureToConnectToStorageDialog1"); - } - + runThermostatGuiInANewThread(); + sleepIfRealScreen(FIVE_SEC); + prepareScreenshot(robot, "FailureToConnectToStorageDialog1"); + checkForPattern(robot, Patterns.FailureToConnectToStorageDialog.ERROR_ICON, "error icon"); checkForPattern(robot, Patterns.FailureToConnectToStorageDialog.CONFIGURE_BUTTON, "configure button"); Rectangle rectQuitButton = checkForPattern(robot, Patterns.FailureToConnectToStorageDialog.QUIT_BUTTON, "quit button"); robot.saveScreenshot("FailureToConnectToStorageDialog2"); - if (this.configuration.useRealGfxTests()) - { - robot.clickToRectangle(rectQuitButton); - } + robot.clickToRectangle(rectQuitButton); } /** @@ -136,12 +122,9 @@ @TillVersion("0.14.0") public void testStartGUIWithStorageBasicTest() throws IOException, AWTException { - GuiRobot robot = startThermostatAndStorage("testStartGUIWithStorageBasicTest1"); - if (!this.configuration.useDummyGfxTests()) - { - createScreenshot(robot, "testStartGUIWithStorageBasicTest1"); - } - + GuiRobot robot = startThermostatAndStorage(); + prepareScreenshot(robot,"testStartGUIWithStorageBasicTest1"); + checkForPattern(robot, Patterns.MainWindow.MAGNIFY_ICON, "magnify icon"); checkForPattern(robot, Patterns.MainWindow.ISSUES_LABEL, "issues label"); checkForPattern(robot, Patterns.MainWindow.SUMMARY_LABEL, "summary label"); @@ -167,12 +150,9 @@ //@SinceVersion("0.16.0") public void testStartGUIWithStorageBasicTest2() throws IOException, AWTException { - GuiRobot robot = startThermostatAndStorage("testStartGUIWithStorageBasicTest1"); - if (!this.configuration.useDummyGfxTests()) - { - createScreenshot(robot, "testStartGUIWithStorageBasicTest1"); - } - + GuiRobot robot = startThermostatAndStorage(); + prepareScreenshot(robot, "testStartGUIWithStorageBasicTest1"); + checkForPattern(robot, Patterns.MainWindow.MAGNIFY_ICON, "magnify icon"); checkForPattern(robot, Patterns.MainWindow.MAIN_MENU, "main menu"); @@ -198,12 +178,9 @@ */ public void testStartGUIWithStorageMenuTest() throws IOException, AWTException { - GuiRobot robot = startThermostatAndStorage("testStartGUIWithStorageMenuTest1"); - if (!this.configuration.useDummyGfxTests()) - { - createScreenshot(robot, "testStartGUIWithStorageMenuTest1"); - } - + GuiRobot robot = startThermostatAndStorage(); + prepareScreenshot(robot, "testStartGUIWithStorageMenuTest1"); + checkForPattern(robot, Patterns.MainWindowMenuBar.FILE_MENU, "file menu"); checkForPattern(robot, Patterns.MainWindowMenuBar.EDIT_MENU, "edit menu"); checkForPattern(robot, Patterns.MainWindowMenuBar.VIEW_MENU, "view menu"); @@ -225,10 +202,10 @@ */ public void testStartGUIWithStorageMenuFileTest() throws IOException, AWTException { - GuiRobot robot = startThermostatAndStorage("testStartGUIWithStorageMenuFileTest1"); - + GuiRobot robot = startThermostatAndStorage(); + enterMainMenu(robot); - createScreenshot(robot, "testStartGUIWithStorageMenuFileTest1"); + prepareScreenshot(robot, "testStartGUIWithStorageMenuFileTest1"); checkForPattern(robot, Patterns.MainWindowMenuFile.EXIT, "file/exit menu item"); @@ -252,13 +229,13 @@ @TillVersion("0.15.0") public void testStartGUIWithStorageMenuEditTest() throws IOException, AWTException { - GuiRobot robot = startThermostatAndStorage("testStartGUIWithStorageMenuEditTest1"); - + GuiRobot robot = startThermostatAndStorage(); + enterMainMenu(robot); - robot.pressKey(KeyEvent.VK_RIGHT); - robot.pressKey(KeyEvent.VK_LEFT); - robot.pressKey(KeyEvent.VK_RIGHT); - createScreenshot(robot, "testStartGUIWithStorageMenuEditTest1"); + robot.pressRightKey(); + robot.pressLeftKey(); + robot.pressRightKey(); + prepareScreenshot(robot, "testStartGUIWithStorageMenuEditTest1"); checkForPattern(robot, Patterns.MainWindowMenuEdit.CLIENT_PREFERENCES, "edit/client preferences"); checkForPattern(robot, Patterns.MainWindowMenuEdit.ENABLE_HISTORY_MODE, "edit/enable history mode"); @@ -271,13 +248,13 @@ @SinceVersion("0.16.0") public void testStartGUIWithStorageMenuEditTest2() throws IOException, AWTException { - GuiRobot robot = startThermostatAndStorage("testStartGUIWithStorageMenuEditTest1"); + GuiRobot robot = startThermostatAndStorage(); enterMainMenu(robot); - robot.pressKey(KeyEvent.VK_RIGHT); - robot.pressKey(KeyEvent.VK_LEFT); - robot.pressKey(KeyEvent.VK_RIGHT); - createScreenshot(robot, "testStartGUIWithStorageMenuEditTest1"); + robot.pressRightKey(); + robot.pressLeftKey(); + robot.pressRightKey(); + prepareScreenshot(robot, "testStartGUIWithStorageMenuEditTest1"); checkForPattern(robot, Patterns.MainWindowMenuEdit.CLIENT_PREFERENCES, "edit/client preferences"); checkForPattern(robot, Patterns.MainWindowMenuEdit.SHOW_UNCONNECTED_HOSTS, "edit/show unconnected hosts"); @@ -298,12 +275,12 @@ */ public void testStartGUIWithStorageMenuViewTest() throws IOException, AWTException { - GuiRobot robot = startThermostatAndStorage("testStartGUIWithStorageMenuViewTest1"); + GuiRobot robot = startThermostatAndStorage(); enterMainMenu(robot); - robot.pressKey(KeyEvent.VK_RIGHT); - robot.pressKey(KeyEvent.VK_RIGHT); - createScreenshot(robot, "testStartGUIWithStorageMenuViewTest1"); + robot.pressRightKey(); + robot.pressRightKey(); + prepareScreenshot(robot, "testStartGUIWithStorageMenuViewTest1"); checkForPattern(robot, Patterns.MainWindowMenuView.VIEW_ALL_AGENTS, "view/all agents"); @@ -322,14 +299,14 @@ */ public void testStartGUIWithStorageMenuHelpTest() throws IOException, AWTException { - GuiRobot robot = startThermostatAndStorage("testStartGUIWithStorageMenuHelpTest1"); + GuiRobot robot = startThermostatAndStorage(); enterMainMenu(robot); for (int i = 0; i < 3; i++) { - robot.pressKey(KeyEvent.VK_RIGHT); + robot.pressRightKey(); } - createScreenshot(robot, "testStartGUIWithStorageMenuHelpTest1"); + prepareScreenshot(robot, "testStartGUIWithStorageMenuHelpTest1"); checkForPattern(robot, Patterns.MainWindowMenuHelp.ABOUTS, "help/about"); @@ -348,17 +325,17 @@ */ public void testStartGUIWithStorageMenuHelpAboutTest() throws IOException, AWTException { - GuiRobot robot = startThermostatAndStorage("testStartGUIWithStorageMenuHelpAboutTest1"); + GuiRobot robot = startThermostatAndStorage(); enterMainMenu(robot); for (int i = 0; i < 3; i++) { - robot.pressKey(KeyEvent.VK_RIGHT); + robot.pressRightKey(); } - robot.pressKey(KeyEvent.VK_DOWN); - robot.pressKey(KeyEvent.VK_ENTER); + robot.pressDownKey(); + robot.pressEnterKey(); - createScreenshot(robot, "testStartGUIWithStorageMenuHelpAboutTest1"); + prepareScreenshot(robot, "testStartGUIWithStorageMenuHelpAboutTest1"); checkForPattern(robot, Patterns.AboutDialog.CLOSE_BUTTON, "about dialog/close button"); checkForPattern(robot, Patterns.AboutDialog.THERMOSTAT_LOGO, "about dialog/Thermostat logo"); @@ -369,7 +346,7 @@ robot.saveScreenshot("testStartGUIWithStorageMenuHelpAboutTest2"); // leave the About dialog - robot.pressKey(KeyEvent.VK_ENTER); + robot.pressEnterKey(); stopThermostatAndStorage(robot); } @@ -393,11 +370,8 @@ @TillVersion("0.14.0") public void testSummaryTab() throws IOException, AWTException { - GuiRobot robot = startThermostatAndStorage("testSummaryTabTest1"); - if (!this.configuration.useDummyGfxTests()) - { - createScreenshot(robot, "testSummaryTabTest1"); - } + GuiRobot robot = startThermostatAndStorage(); + prepareScreenshot(robot, "testSummaryTabTest1"); checkForPattern(robot, Patterns.SummaryTab.SUMMARY_LABEL, "summary label on summary tab"); checkForPattern(robot, Patterns.SummaryTab.TOTAL_MACHINES_LABEL, "total machines label on summary tab"); @@ -432,19 +406,16 @@ */ public void testEditClientPreferences() throws IOException, AWTException { - GuiRobot robot = startThermostatAndStorage("testEditClientPreferencesTest1"); + GuiRobot robot = startThermostatAndStorage(); enterMainMenu(robot); - robot.pressKey(KeyEvent.VK_RIGHT); - robot.pressKey(KeyEvent.VK_DOWN); - robot.pressKey(KeyEvent.VK_ENTER); + robot.pressRightKey(); + robot.pressDownKey(); + robot.pressEnterKey(); - if (!this.configuration.useDummyGfxTests()) - { - createScreenshot(robot, "testEditClientPreferencesTest1"); - } + prepareScreenshot(robot, "testEditClientPreferencesTest1"); - robot.pressKey(KeyEvent.VK_ENTER); + robot.pressEnterKey(); stopThermostatAndStorage(robot); checkForPattern(robot, Patterns.ClientPreferencesDialog.OK_BUTTON, "ok button"); @@ -471,19 +442,16 @@ */ public void testAllAgentsDialog() throws IOException, AWTException { - GuiRobot robot = startThermostatAndStorage("testAllAgentsDialogTest1"); + GuiRobot robot = startThermostatAndStorage(); enterMainMenu(robot); - robot.pressKey(KeyEvent.VK_RIGHT); - robot.pressKey(KeyEvent.VK_RIGHT); - robot.pressKey(KeyEvent.VK_DOWN); - robot.pressKey(KeyEvent.VK_ENTER); + robot.pressRightKey(); + robot.pressRightKey(); + robot.pressDownKey(); + robot.pressEnterKey(); - if (!this.configuration.useDummyGfxTests()) - { - createScreenshot(robot, "testAllAgentsDialogTest1"); - } - + prepareScreenshot(robot, "testAllAgentsDialogTest1"); + // we need to click on "Close" button that does not have focus :-/ Rectangle rect = findPattern(robot, Patterns.AllAgentsDialog.CLOSE_BUTTON, "all agents dialog/close button"); robot.clickToRectangle(rect); diff -r 44af5584ec59 -r 3d06e2d323cb src/org/thermostat/qa/testsuites/GuiClientWebStorageTest.java --- a/src/org/thermostat/qa/testsuites/GuiClientWebStorageTest.java Tue Apr 01 14:50:03 2014 +0200 +++ b/src/org/thermostat/qa/testsuites/GuiClientWebStorageTest.java Tue Apr 01 15:09:08 2014 +0200 @@ -181,10 +181,7 @@ checkForPattern(robot, Patterns.FailureToConnectToStorageDialog.CONFIGURE_BUTTON, "configure button"); Rectangle rectQuitButton = checkForPattern(robot, Patterns.FailureToConnectToStorageDialog.QUIT_BUTTON, "quit button"); - if (this.configuration.useRealGfxTests()) - { - robot.clickToRectangle(rectQuitButton); - } + robot.clickToRectangle(rectQuitButton); } /** @@ -219,20 +216,15 @@ { startTomcat(); - GuiRobot robot = new GuiRobot(); + GuiRobot robot = new GuiRobot(this.configuration); - if (this.configuration.useDummyGfxTests()) - { - robot.loadScreenshot("FailureToConnectToWebStorageDialog01"); - } - else + if(this.configuration.useRealScreenshots()) { runThermostatGuiInANewThread(); sleep(FIVE_SEC+3000); - robot.createScreenCapture(); - robot.saveScreenshot("FailureToConnectToWebStorageDialog01"); } - + robot.prepareScreenshot("FailureToConnectToWebStorageDialog01"); + checkForErrorIconAndClickQuit(robot); robot.saveScreenshot("FailureToConnectToWebStorageDialog02"); @@ -279,20 +271,15 @@ { startStorage(); - GuiRobot robot = new GuiRobot(); + GuiRobot robot = new GuiRobot(this.configuration); - if (this.configuration.useDummyGfxTests()) - { - robot.loadScreenshot("FailureToConnectToWebStorageDialog11"); - } - else + if (this.configuration.useRealScreenshots()) { runThermostatGuiInANewThread(); sleep(FIVE_SEC); - robot.createScreenCapture(); - robot.saveScreenshot("FailureToConnectToWebStorageDialog11"); } - + robot.prepareScreenshot("FailureToConnectToWebStorageDialog11"); + checkForErrorIconAndClickQuit(robot); robot.saveScreenshot("FailureToConnectToWebStorageDialog12"); @@ -335,20 +322,15 @@ sleep(FIVE_SEC); - GuiRobot robot = new GuiRobot(); + GuiRobot robot = new GuiRobot(this.configuration); - if (this.configuration.useDummyGfxTests()) - { - robot.loadScreenshot("GuiWithWebStorage1"); - } - else + if (this.configuration.useRealScreenshots()) { runThermostatGuiInANewThread(); sleep(FIVE_SEC); - robot.createScreenCapture(); - robot.saveScreenshot("GuiWithWebStorage1"); } - + robot.prepareScreenshot("GuiWithWebStorage1"); + //some time to let the logs appear - let us check the patterns meanwhile checkForPattern(robot, Patterns.MainWindow.MAGNIFY_ICON, "magnify icon"); checkForPattern(robot, Patterns.MainWindow.ISSUES_LABEL, "issues label"); @@ -420,19 +402,14 @@ sleep(FIVE_SEC); - GuiRobot robot = new GuiRobot(); + GuiRobot robot = new GuiRobot(this.configuration); - if (this.configuration.useDummyGfxTests()) - { - robot.loadScreenshot("GuiWithWebStorage1"); - } - else + if (this.configuration.useRealScreenshots()) { runThermostatGuiInANewThread(); sleep(7000); - robot.createScreenCapture(); - robot.saveScreenshot("GuiWithWebStorage1"); } + robot.prepareScreenshot("GuiWithWebStorage1"); //some time to let the logs appear - let us check the patterns meanwhile checkForPattern(robot, Patterns.MainWindow.MAIN_MENU, "main menu"); @@ -497,14 +474,9 @@ prepareWebStorageBadClientLoginFile(); //try to run - GuiRobot robot = startThermostatAndWebStorage("testSummaryTabWSTest1"); - if (!this.configuration.useDummyGfxTests()) - { - sleep(3000); - createScreenshot(robot, "guiWSBadLogin"); - } - robot.saveScreenshot("guiWSBadLogin"); - + GuiRobot robot = startThermostatAndWebStorage(); + sleepIfRealScreen(3000); + robot.prepareScreenshot("guiWSBadLogin"); stopThermostatAndWebStorage(robot); checkForErrorIconAndClickQuit(robot); robot.saveScreenshot("guiWSBadLogin2"); @@ -579,81 +551,43 @@ prepareWebStorageBadClientLoginFile(); //try to run - GuiRobot robot = startThermostatAndWebStorage("testSummaryTabWSTest1"); - if (!this.configuration.useDummyGfxTests()) - { - sleep(3000); - createScreenshot(robot, "guiWSBadLogin"); - } - robot.saveScreenshot("guiWSBadLogin"); + GuiRobot robot = startThermostatAndWebStorage(); + sleepIfRealScreen(3000); + prepareScreenshot(robot, "guiWSBadLogin"); //find "configuration" Rectangle rectConfigureButton = checkForPattern(robot, Patterns.FailureToConnectToStorageDialog.CONFIGURE_BUTTON, "configure button"); - if (this.configuration.useRealGfxTests()) - { - robot.clickToRectangle(rectConfigureButton); - } + robot.clickToRectangle(rectConfigureButton); - if (!this.configuration.useDummyGfxTests()) - { - sleep(3000); - createScreenshot(robot, "guiWSConfigure"); - } - robot.saveScreenshot("guiWSConfigure"); + sleepIfRealScreen(3000); + prepareScreenshot(robot, "guiWSConfigure"); //find editing dialog checkForPattern(robot, Patterns.ClientPreferencesDialog.WEB_STORAGE_CONNECTION_INFO, "web storage connection info"); Rectangle rectUserNameEdit = checkForPattern(robot, Patterns.ClientPreferencesDialog.BAD_LOGIN_USER_NAME, "user name"); //click username //edit - if (this.configuration.useRealGfxTests()) - { - robot.clickToRectangle(rectUserNameEdit); - robot.clickToRectangle(rectUserNameEdit); - robot.pressKey(KeyEvent.VK_C); - robot.pressKey(KeyEvent.VK_L); - robot.pressKey(KeyEvent.VK_I); - robot.pressKey(KeyEvent.VK_E); - robot.pressKey(KeyEvent.VK_N); - robot.pressKey(KeyEvent.VK_T); - robot.pressKey(KeyEvent.VK_MINUS); - robot.pressKey(KeyEvent.VK_T); - robot.pressKey(KeyEvent.VK_E); - robot.pressKey(KeyEvent.VK_S); - robot.pressKey(KeyEvent.VK_T); - robot.pressKey(KeyEvent.VK_E); - robot.pressKey(KeyEvent.VK_R); - } + robot.clickToRectangle(rectUserNameEdit); + robot.clickToRectangle(rectUserNameEdit); + robot.writeSmallLettersText("client"); + robot.writeSpecialChar('-'); + robot.writeSmallLettersText("tester"); Rectangle rectPasswordEdit = checkForPattern(robot, Patterns.ClientPreferencesDialog.PASSWORD_EDIT_AND_LABEL, "password edit"); //click password //edit - if (this.configuration.useRealGfxTests()) - { - robot.clickToRectangle(rectPasswordEdit); - robot.clickToRectangle(rectPasswordEdit); - robot.pressKey(KeyEvent.VK_H); - robot.pressKey(KeyEvent.VK_E); - robot.pressKey(KeyEvent.VK_S); - robot.pressKey(KeyEvent.VK_L); - robot.pressKey(KeyEvent.VK_O); - robot.pressKey(KeyEvent.VK_2); - } + robot.clickToRectangle(rectPasswordEdit); + robot.clickToRectangle(rectPasswordEdit); + robot.writeSmallLettersText("heslo"); + robot.writeNumbersText("2"); Rectangle rectOkButton = checkForPattern(robot, Patterns.ClientPreferencesDialog.OK_BUTTON, "client preferences ok button"); //click ok - if (this.configuration.useRealGfxTests()) - { - robot.clickToRectangle(rectOkButton); - } + robot.clickToRectangle(rectOkButton); //gui should appear ... wait, create screenshot, check patterns - sleep(7000); - if(!this.configuration.useDummyGfxTests()) - { - createScreenshot(robot, "guiWSFixedLogin"); - } - robot.saveScreenshot("guiWSFixedLogin"); + sleepIfRealScreen(7000); + robot.prepareScreenshot("guiWSFixedLogin"); //check that the gui appeared (at least most of it...) checkForPattern(robot, Patterns.MainWindow.MAIN_MENU, "main menu"); @@ -714,19 +648,15 @@ */ public void testStartGUIWithoutWebStorage() throws IOException, AWTException { - GuiRobot robot = new GuiRobot(); + GuiRobot robot = new GuiRobot(this.configuration); - if (this.configuration.useDummyGfxTests()) - { - robot.loadScreenshot("FailureToConnectToWebStorageDialog1"); - } - else + if (this.configuration.useRealScreenshots()) { runThermostatGuiInANewThread(); sleep(FIVE_SEC); - robot.createScreenCapture(); - robot.saveScreenshot("FailureToConnectToWebStorageDialog1"); } + + robot.prepareScreenshot("FailureToConnectToWebStorageDialog1"); checkForErrorIconAndClickQuit(robot); robot.saveScreenshot("FailureToConnectToWebStorageDialog2"); @@ -754,12 +684,9 @@ @TillVersion("0.14.0") public void testStartGUIWithWebStorageBasicTest() throws IOException, AWTException { - GuiRobot robot = startThermostatAndWebStorage("testStartGUIWithWebStorageBasicTest1"); - if (!this.configuration.useDummyGfxTests()) - { - sleep(3000); - createScreenshot(robot, "testStartGUIWithWebStorageBasicTest1"); - } + GuiRobot robot = startThermostatAndWebStorage(); + sleepIfRealScreen(3000); + prepareScreenshot(robot, "testStartGUIWithWebStorageBasicTest1"); checkForPattern(robot, Patterns.MainWindow.MAGNIFY_ICON, "magnify icon"); checkForPattern(robot, Patterns.MainWindow.ISSUES_LABEL, "issues label"); @@ -792,12 +719,9 @@ */ public void testStartGUIWithWebStorageMenuTest() throws IOException, AWTException { - GuiRobot robot = startThermostatAndWebStorage("testStartGUIWithWebStorageMenuTest1"); - if (!this.configuration.useDummyGfxTests()) - { - sleep(FIVE_SEC); - createScreenshot(robot, "testStartGUIWithWebStorageMenuTest1"); - } + GuiRobot robot = startThermostatAndWebStorage(); + sleepIfRealScreen(FIVE_SEC); + prepareScreenshot(robot, "testStartGUIWithWebStorageMenuTest1"); checkForPattern(robot, Patterns.MainWindowMenuBar.FILE_MENU, "file menu"); checkForPattern(robot, Patterns.MainWindowMenuBar.EDIT_MENU, "edit menu"); @@ -833,12 +757,9 @@ @TillVersion("0.14.0") public void testSummaryTab() throws IOException, AWTException { - GuiRobot robot = startThermostatAndWebStorage("testSummaryTabWSTest1"); - if (!this.configuration.useDummyGfxTests()) - { - sleep(3000); - createScreenshot(robot, "testSummaryTabWSTest1"); - } + GuiRobot robot = startThermostatAndWebStorage(); + sleepIfRealScreen(3000); + prepareScreenshot(robot, "testSummaryTabWSTest1"); checkForPattern(robot, Patterns.SummaryTab.SUMMARY_LABEL, "summary label on summary tab"); checkForPattern(robot, Patterns.SummaryTab.TOTAL_MACHINES_LABEL, "total machines label on summary tab"); @@ -877,21 +798,18 @@ */ public void testEditClientPreferences() throws IOException, AWTException { - GuiRobot robot = startThermostatAndWebStorage("testEditClientPreferencesWSTest1"); + GuiRobot robot = startThermostatAndWebStorage(); - sleep(FIVE_SEC); + sleepIfRealScreen(FIVE_SEC); enterMainMenu(robot); - robot.pressKey(KeyEvent.VK_RIGHT); - robot.pressKey(KeyEvent.VK_DOWN); - robot.pressKey(KeyEvent.VK_ENTER); + robot.pressRightKey(); + robot.pressDownKey(); + robot.pressEnterKey(); - if (!this.configuration.useDummyGfxTests()) - { - createScreenshot(robot, "testEditClientPreferencesWSTest1"); - } + prepareScreenshot(robot, "testEditClientPreferencesWSTest1"); - robot.pressKey(KeyEvent.VK_ENTER); + robot.pressEnterKey(); stopThermostatAndWebStorage(robot); checkForPattern(robot, Patterns.ClientPreferencesDialog.OK_BUTTON, "ok button"); @@ -901,10 +819,7 @@ checkForPattern(robot, Patterns.ClientPreferencesDialog.PASSWORD_LABEL, "password label"); checkForPattern(robot, Patterns.ClientPreferencesDialog.STORAGE_URL_LABEL, "storage url label"); checkForPattern(robot, Patterns.ClientPreferencesDialog.SAVE_ENTITLEMENTS_CHECKED, "save entitlements checkbox"); - if (!this.configuration.useDummyGfxTests()) - { - robot.saveScreenshot("testEditClientPreferencesWSTest2"); - } + robot.saveScreenshot("testEditClientPreferencesWSTest2"); } public static void main(String[] args) { diff -r 44af5584ec59 -r 3d06e2d323cb src/org/thermostat/qa/testsuites/GuiHostViewSmokeTest.java --- a/src/org/thermostat/qa/testsuites/GuiHostViewSmokeTest.java Tue Apr 01 14:50:03 2014 +0200 +++ b/src/org/thermostat/qa/testsuites/GuiHostViewSmokeTest.java Tue Apr 01 15:09:08 2014 +0200 @@ -86,32 +86,17 @@ new AgentThread().start(); logInfo("runAgentThread", "Thermostat Agent started"); - if (this.configuration.useDummyGfxTests()) - { - robot.loadScreenshot("GuiStarted1"); - } - else - { - //start gui - runThermostatGuiInANewThread(); - sleep(15000); - robot.createScreenCapture(); - robot.saveScreenshot("GuiStarted1"); - } - + //start gui + runThermostatGuiInANewThread(); + sleepIfRealScreen(15000); + robot.prepareScreenshot("ThermostatStartForHostView1"); + Rectangle r = checkForPattern(robot, Patterns.MainWindow.HOST_VIEW_ICON, "host view icon"); robot.clickToRectangle(r); - if (this.configuration.useDummyGfxTests()) - { - robot.loadScreenshot("HostViewActive1"); - } - else - { - sleep(2000); - robot.createScreenCapture(); - robot.saveScreenshot("HostViewActive1"); - } + sleepIfRealScreen(2000); + robot.prepareScreenshot("HostViewActive1"); + checkForPattern(robot, Patterns.MainWindow.HOST_VIEW_ICON_ACTIVE, "host view active icon"); robot.saveScreenshot("HostViewActive2"); @@ -125,15 +110,7 @@ { GuiRobot robot = clickOnHostView(); - if (this.configuration.useDummyGfxTests()) - { - robot.loadScreenshot("HostViewOverviewTab1"); - } - else - { - robot.createScreenCapture(); - robot.saveScreenshot("HostViewOverviewTab1"); - } + robot.prepareScreenshot("HostViewOverviewTab1"); //the overview tab should be active checkForPattern(robot, Patterns.HostView.OVERVIEW_TAB_CHOSEN, "overview tab active"); @@ -173,17 +150,8 @@ { GuiRobot robot = clickOnHostView(); - //click on the window somewhere + robot.prepareScreenshot("HostViewOverviewTab1"); - if (this.configuration.useDummyGfxTests()) - { - robot.loadScreenshot("HostViewOverviewTab1"); - } - else - { - robot.createScreenCapture(); - robot.saveScreenshot("HostViewOverviewTab1"); - } //the overview tab should be active checkForPattern(robot, Patterns.HostView.OVERVIEW_TAB_CHOSEN, "overview tab active"); @@ -199,18 +167,10 @@ Rectangle from = checkForPattern(robot, Patterns.MainWindow.RESIZABLE, "resizable r l corner"); robot.resize(from, 400, 300); - sleep(2000); + sleepIfRealScreen(2000); - if (this.configuration.useDummyGfxTests()) - { - robot.loadScreenshot("HostViewProcessorTab2"); - } - else - { - robot.createScreenCapture(); - robot.saveScreenshot("HostViewProcessorTab2"); - } - + robot.prepareScreenshot("HostViewOverviewTabResized1"); + //the small texts should be visible checkForPattern(robot, Patterns.HostView.TINY_HOST_LABEL, "tiny host label"); checkForPattern(robot, Patterns.HostView.TINY_ID_LABEL, "tiny id label"); @@ -230,7 +190,7 @@ checkForPattern(robot, Patterns.HostViewOverviewTab.SW_LABEL, "sw label"); checkForPattern(robot, Patterns.HostViewOverviewTab.TOTAL_MEMORY_LABEL, "total memory label"); - robot.saveScreenshot("HostViewOverviewTab2"); + robot.saveScreenshot("HostViewOverviewTabResized2"); //stop the gui, agent, storage stopThermostatParts(robot); @@ -248,17 +208,9 @@ Rectangle r = checkForPattern(robot, Patterns.HostView.PROCESSOR_TAB, "processor tab"); robot.clickToRectangle(r); - sleep(1000); + sleepIfRealScreen(1000); - if (this.configuration.useDummyGfxTests()) - { - robot.loadScreenshot("HostViewProcessorTab1"); - } - else - { - robot.createScreenCapture(); - robot.saveScreenshot("HostViewProcessorTab1"); - } + robot.prepareScreenshot("HostViewProcessorTab1"); //the processor tab should be active checkForPattern(robot, Patterns.HostView.PROCESSOR_TAB_CHOSEN, "processor tab active"); @@ -299,17 +251,10 @@ Rectangle r = checkForPattern(robot, Patterns.HostView.MEMORY_TAB, "memory tab"); robot.clickToRectangle(r); - sleep(1000); + sleepIfRealScreen(1000); - if (this.configuration.useDummyGfxTests()) - { - robot.loadScreenshot("HostViewMemoryTab1"); - } - else - { - robot.createScreenCapture(); - robot.saveScreenshot("HostViewMemoryTab1"); - } + robot.prepareScreenshot("HostViewMemoryTab1"); + //the overview tab should be active checkForPattern(robot, Patterns.HostView.MEMORY_TAB_CHOSEN, "memory tab active"); @@ -352,17 +297,10 @@ Rectangle r = checkForPattern(robot, Patterns.HostView.NUMA_TAB, "numa tab"); robot.clickToRectangle(r); - sleep(1000); + sleepIfRealScreen(1000); - if (this.configuration.useDummyGfxTests()) - { - robot.loadScreenshot("HostViewNumaTab1"); - } - else - { - robot.createScreenCapture(); - robot.saveScreenshot("HostViewNumaTab1"); - } + robot.prepareScreenshot("HostViewNumaTab1"); + //the overview tab should be active checkForPattern(robot, Patterns.HostView.NUMA_TAB_CHOSEN, "numa tab active"); diff -r 44af5584ec59 -r 3d06e2d323cb test.properties --- a/test.properties Tue Apr 01 14:50:03 2014 +0200 +++ b/test.properties Tue Apr 01 15:09:08 2014 +0200 @@ -5,3 +5,5 @@ thermostat_user_home=/home/jfabriko/.thermostat/ apache_tomcat_home=/home/jfabriko/thermostaty/apache-tomcat-7.0.42/ clean_after_gui_test=true +screenshot_source=normal +