view src/org/thermostat/qa/testsuites/GuiClientSmokeTest.java @ 167:7baba5d67a16

Fixes of gui tests and web storage tests, making tests more independent * Makefile: added possibility to change backend for making screenshots * Makefile: fixed problem with web storage (content of thermostat webapp direcory is copied in /webaps/thermostat instead of *.war) * Makefile: add coping configuration files to thermostat user directory, which fixed problem of some tests relying on leftower configuration and make it possible run them independently * README.md: new informations about screenshot backends included * src/org/thermostat/qa/framework/Patterns.java: new possible patterns for some tabs added (versions of tabs highlighted under cursor) * src/org/thermostat/qa/framework/ThermostatUtilities.java: thermostats jaas configruation file is now passed to tomcat * src/org/thermostat/qa/testsuites/GuiClientSmokeTest.java: adding 1 second delay fixed problem, when test sometimes failed * src/org/thermostat/qa/testsuites/GuiHostViewSmokeTest.java: window is now not resized more than necessary (caused problem where part of the window did not fit in lower resolution (1024x768) displays/vncs and test failed) * patterns/1.1.0/noAA/ClientPreferencesDialog/connection_info_label.png: added/updated pattern * patterns/1.1.0/noAA/HostView/memory_tab_chsen.png: same as previous * patterns/1.1.0/noAA/HostView/notes_tab.png: same as previous * patterns/1.1.0/noAA/HostView/notes_tab_chosen.png: same as previous * patterns/1.1.0/noAA/HostView/memory_tab_chosen2.png: same as previous * patterns/1.1.0/noAA/HostView/numa_tab_chosen2.png: same as previous * patterns/1.1.0/noAA/HostView/processor_tab_chosen2.png: same as previous
author Zdenek Zambersky <zzambers@redhat.com>
date Fri, 21 Nov 2014 10:50:09 +0100
parents 419257a68b27
children af42c142855f
line wrap: on
line source

/*

    ThermostatQA - test framework for Thermostat Monitoring Tool

    Copyright 2013 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.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;
import org.thermostat.qa.framework.GuiRobot;
import org.thermostat.qa.framework.Patterns;
import org.thermostat.qa.framework.ThermostatGuiTest;
import org.thermostat.qa.annotations.TillVersion;
import org.thermostat.qa.annotations.SinceVersion;
import org.thermostat.qa.common.ScreenshotSourceType;



/**
 * Set o tests for checking if Thermostat GUI client is working correctly.
 * Tests are perfomed by running Thermostat client and checking if various part
 * of its graphical user interface is displayed correctly on the desktop.
 *
 * @author: Pavel Tisnovsky
 */
@TestType(TestTypes.GUI_TEST)
public class GuiClientSmokeTest extends ThermostatGuiTest
{

    @Override
    protected void setUp()
    {
        //setupForGuiTests();
    }
    
    @Override
    protected void tearDown()
    {
        //tearDownGuiTests();
    }

    /**
     * Test if "Failure dialog" is displayed when Thermostat GUI client is started
     * w/o storage.
     *
     * Following patterns are checked for its presence:<br /><br />
     * Text antialiasing enabled:<br />
     * <img src="patterns/AA/FailureToConnectToStorageDialog/error_icon.png"><br /><br />
     * <img src="patterns/AA/FailureToConnectToStorageDialog/configure_button.png"><br /><br />
     * <img src="patterns/AA/FailureToConnectToStorageDialog/quit_button.png"><br /><br />
     * Text antialiasing disabled:<br />
     * <img src="patterns/noAA/FailureToConnectToStorageDialog/error_icon.png"><br /><br />
     * <img src="patterns/noAA/FailureToConnectToStorageDialog/configure_button.png"><br /><br />
     * <img src="patterns/noAA/FailureToConnectToStorageDialog/quit_button.png"><br /><br />
     */
    public void testStartGUIWithoutStorage() throws IOException, AWTException
    {
        GuiRobot robot = new GuiRobot(this.configuration);

        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");

        robot.clickToRectangle(rectQuitButton);
    }

    /**
     * Test if all base GUI parts are displayed on the screen when Thermostat GUI client
     * is started.
     *
     * Following patterns are checked for its presence:<br /><br />
     * Text antialiasing enabled:<br />
     * <img src="patterns/AA/MainWindow/magnify_icon.png"><br /><br />
     * <img src="patterns/AA/MainWindow/issues_label.png"><br /><br />
     * <img src="patterns/AA/MainWindow/summary_label.png"><br /><br />
     * <img src="patterns/AA/MainWindow/main_menu.png"><br /><br />
     * Text antialiasing disabled:<br />
     * <img src="patterns/noAA/MainWindow/magnify_icon.png"><br /><br />
     * <img src="patterns/noAA/MainWindow/issues_label.png"><br /><br />
     * <img src="patterns/noAA/MainWindow/summary_label.png"><br /><br />
     * <img src="patterns/noAA/MainWindow/main_menu.png"><br /><br />
     */
    @TillVersion("0.14.0")
    public void testStartGUIWithStorageBasicTest() throws IOException, AWTException
    {
        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");
        checkForPattern(robot, Patterns.MainWindow.MAIN_MENU, "main menu");

        robot.saveScreenshot("testStartGUIWithStorageBasicTest2");

        stopThermostatAndStorage(robot);
    }

    /**
     * Test if all base GUI parts are displayed on the screen when Thermostat GUI client
     * is started.
     *
     * Following patterns are checked for its presence:<br /><br />
     * Text antialiasing enabled:<br />
     * <img src="patterns/AA/MainWindow/magnify_icon.png"><br /><br />
     * <img src="patterns/AA/MainWindow/main_menu.png"><br /><br />
     * Text antialiasing disabled:<br />
     * <img src="patterns/noAA/MainWindow/magnify_icon.png"><br /><br />
     * <img src="patterns/noAA/MainWindow/main_menu.png"><br /><br />
     */
    //@SinceVersion("0.16.0")
    public void testStartGUIWithStorageBasicTest2() throws IOException, AWTException
    {
        GuiRobot robot = startThermostatAndStorage();
        prepareScreenshot(robot, "testStartGUIWithStorageBasicTest1");
        
        checkForPattern(robot, Patterns.MainWindow.MAGNIFY_ICON, "magnify icon");
        checkForPattern(robot, Patterns.MainWindow.MAIN_MENU, "main menu");

        robot.saveScreenshot("testStartGUIWithStorageBasicTest2");

        stopThermostatAndStorage(robot);
    }
    
    /**
     * Test for presence of all four main menu items: File menu, Edit menu, View menu and Help menu.
     *
     * Following patterns are checked for its presence:<br /><br />
     * Text antialiasing enabled:<br />
     * <img src="patterns/AA/MainMenu/menu_bar_file.png"><br /><br />
     * <img src="patterns/AA/MainMenu/menu_bar_edit.png"><br /><br />
     * <img src="patterns/AA/MainMenu/menu_bar_view.png"><br /><br />
     * <img src="patterns/AA/MainMenu/menu_bar_help.png"><br /><br />
     * Text antialiasing disabled:<br />
     * <img src="patterns/noAA/MainMenu/menu_bar_file.png"><br /><br />
     * <img src="patterns/noAA/MainMenu/menu_bar_edit.png"><br /><br />
     * <img src="patterns/noAA/MainMenu/menu_bar_view.png"><br /><br />
     * <img src="patterns/noAA/MainMenu/menu_bar_help.png"><br /><br />
     */
    public void testStartGUIWithStorageMenuTest() throws IOException, AWTException
    {
        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");
        checkForPattern(robot, Patterns.MainWindowMenuBar.HELP_MENU, "help menu");

        robot.saveScreenshot("testStartGUIWithStorageMenuTest2");

        stopThermostatAndStorage(robot);
    }

    /**
     * Test for presence of items located in File menu.
     *
     * Following patterns are checked for its presence:<br />
     * Text antialiasing enabled:<br />
     * <img src="patterns/AA/MainMenu/menu_file_exit.png"><br /><br />
     * Text antialiasing disabled:<br />
     * <img src="patterns/noAA/MainMenu/menu_file_exit.png"><br /><br />
     */
    public void testStartGUIWithStorageMenuFileTest() throws IOException, AWTException
    {
        GuiRobot robot = startThermostatAndStorage();
        
        enterMainMenu(robot);
        prepareScreenshot(robot, "testStartGUIWithStorageMenuFileTest1");

        checkForPattern(robot, Patterns.MainWindowMenuFile.EXIT, "file/exit menu item");

        robot.saveScreenshot("testStartGUIWithStorageMenuFileTest2");
        stopThermostatAndStorage(robot);
    }

    /**
     * Test for presence of items located in Edit menu.
     *
     * Following patterns are checked for its presence:<br /><br />
     * Text antialiasing enabled:<br />
     * <img src="patterns/AA/MainMenu/menu_edit_client_preferences.png"><br /><br />
     * <img src="patterns/AA/MainMenu/menu_edit_enable_history_mode.png"><br /><br />
     * <img src="patterns/AA/MainMenu/menu_edit_show_non_living_vm.png"><br /><br />
     * Text antialiasing disabled:<br />
     * <img src="patterns/noAA/MainMenu/menu_edit_client_preferences.png"><br /><br />
     * <img src="patterns/noAA/MainMenu/menu_edit_enable_history_mode.png"><br /><br />
     * <img src="patterns/noAA/MainMenu/menu_edit_show_non_living_vm.png"><br /><br />
     */
    @TillVersion("0.15.0")
    public void testStartGUIWithStorageMenuEditTest() throws IOException, AWTException
    {
        GuiRobot robot = startThermostatAndStorage();
        
        enterMainMenu(robot);
        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");
        checkForPattern(robot, Patterns.MainWindowMenuEdit.SHOW_NON_LIVING_VM, "edit/show non living VM");

        robot.saveScreenshot("testStartGUIWithStorageMenuEditTest2");
        stopThermostatAndStorage(robot);
    }
    
    @SinceVersion("0.16.0")
    public void testStartGUIWithStorageMenuEditTest2() throws IOException, AWTException
    {
        GuiRobot robot = startThermostatAndStorage();

        enterMainMenu(robot);
        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");
        checkForPattern(robot, Patterns.MainWindowMenuEdit.SHOW_NON_LIVING_VM, "edit/show non living VM");

        robot.saveScreenshot("testStartGUIWithStorageMenuEditTest2");
        stopThermostatAndStorage(robot);
    }

    /**
     * Test for presence of items located in View menu.
     *
     * Following patterns are checked for its presence:<br /><br />
     * Text antialiasing enabled:<br />
     * <img src="patterns/AA/MainMenu/menu_view_all_agents.png"><br /><br />
     * Text antialiasing disabled:<br />
     * <img src="patterns/noAA/MainMenu/menu_view_all_agents.png"><br /><br />
     */
    public void testStartGUIWithStorageMenuViewTest() throws IOException, AWTException
    {
        GuiRobot robot = startThermostatAndStorage();

        enterMainMenu(robot);
        robot.pressRightKey();
        robot.pressRightKey();
        prepareScreenshot(robot, "testStartGUIWithStorageMenuViewTest1");

        checkForPattern(robot, Patterns.MainWindowMenuView.VIEW_ALL_AGENTS, "view/all agents");

        robot.saveScreenshot("testStartGUIWithStorageMenuViewTest2");
        stopThermostatAndStorage(robot);
    }

    /**
     * Test for presence of items located in View menu.
     *
     * Following patterns are checked for its presence:<br /><br />
     * Text antialiasing enabled:<br />
     * <img src="patterns/AA/MainMenu/menu_help_about.png"><br /><br />
     * Text antialiasing disabled:<br />
     * <img src="patterns/noAA/MainMenu/menu_help_about.png"><br /><br />
     */
    public void testStartGUIWithStorageMenuHelpTest() throws IOException, AWTException
    {
        GuiRobot robot = startThermostatAndStorage();

        enterMainMenu(robot);
        for (int i = 0; i < 3; i++)
        {
            robot.pressRightKey();
        }
        prepareScreenshot(robot, "testStartGUIWithStorageMenuHelpTest1");

        checkForPattern(robot, Patterns.MainWindowMenuHelp.ABOUTS, "help/about");

        robot.saveScreenshot("testStartGUIWithStorageMenuHelpTest2");
        stopThermostatAndStorage(robot);
    }

    /**
     * Test if dialog Help/About is really shown on the screen and if all it's GUI items are presented.
     *
     * Following patterns are checked for its presence:<br /><br />
     * Text antialiasing enabled:<br />
     * <img src="patterns/AA/AboutDialog/close_button.png"><br /><br />
     * Text antialiasing disabled:<br />
     * <img src="patterns/noAA/AboutDialog/close_button.png"><br /><br />
     */
    public void testStartGUIWithStorageMenuHelpAboutTest() throws IOException, AWTException
    {
        GuiRobot robot = startThermostatAndStorage();

        enterMainMenu(robot);
        for (int i = 0; i < 3; i++)
        {
            robot.pressRightKey();
        }
        robot.pressDownKey();
        robot.pressEnterKey();

        prepareScreenshot(robot, "testStartGUIWithStorageMenuHelpAboutTest1");

        checkForPattern(robot, Patterns.AboutDialog.CLOSE_BUTTON, "about dialog/close button");
        checkForPattern(robot, Patterns.AboutDialog.THERMOSTAT_LOGO, "about dialog/Thermostat logo");
        checkForPattern(robot, Patterns.AboutDialog.THERMOSTAT_TITLE, "about dialog/Thermostat title");
        checkForPattern(robot, Patterns.AboutDialog.UPPER_TEXT, "about dialog/upper text");
        checkForPattern(robot, Patterns.AboutDialog.LOWER_TEXT, "about dialog/lower text");

        robot.saveScreenshot("testStartGUIWithStorageMenuHelpAboutTest2");

        // leave the About dialog
        robot.pressEnterKey();
        stopThermostatAndStorage(robot);
    }

    /**
     * Test if Summary tab is shown on the screen.
     *
     * Following patterns are checked for its presence:<br /><br />
     * Text antialiasing enabled:<br />
     * <img src="patterns/AA/TabSummary/summary_label.png"><br /><br />
     * <img src="patterns/AA/TabSummary/issues_label.png"><br /><br />
     * <img src="patterns/AA/TabSummary/total_machines_label.png"><br /><br />
     * <img src="patterns/AA/TabSummary/total_java_virtual_machines_label.png"><br /><br />
     * <img src="patterns/AA/TabSummary/no_issues_in_text_area.png"><br /><br />
     * Text antialiasing disabled:<br />
     * <img src="patterns/noAA/TabSummary/summary_label.png"><br /><br />
     * <img src="patterns/noAA/TabSummary/issues_label.png"><br /><br />
     * <img src="patterns/noAA/TabSummary/total_machines_label.png"><br /><br />
     * <img src="patterns/noAA/TabSummary/total_java_virtual_machines_label.png"><br /><br />
     * <img src="patterns/noAA/TabSummary/no_issues_in_text_area.png"><br /><br />
     */
    @TillVersion("0.14.0")
    public void testSummaryTab() throws IOException, AWTException
    {
        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");
        checkForPattern(robot, Patterns.SummaryTab.TOTAL_VIRTUAL_MACHINES_LABEL, "total virtual machines label on summary tab");
        checkForPattern(robot, Patterns.SummaryTab.ISSUES_LABEL, "issues label on summary tab");
        checkForPattern(robot, Patterns.SummaryTab.NO_ISSUES_IN_TEXT_AREA, "'no issues' text placed in text area");

        robot.saveScreenshot("testSummaryTabTest2");
        stopThermostatAndStorage(robot);
    }

    /**
     * Test if dialog with client preferences is really shown on the screen.
     *
     * Following patterns are checked for its presence:<br /><br />
     * Text antialiasing enabled:<br />
     * <img src="patterns/AA/ClientPreferencesDialog/ok_button.png"><br /><br />
     * <img src="patterns/AA/ClientPreferencesDialog/cancel_button.png"><br /><br />
     * <img src="patterns/AA/ClientPreferencesDialog/user_name_label.png"><br /><br />
     * <img src="patterns/AA/ClientPreferencesDialog/password_label.png"><br /><br />
     * <img src="patterns/AA/ClientPreferencesDialog/storage_url_label.png"><br /><br />
     * <img src="patterns/AA/ClientPreferencesDialog/connection_info_label.png"><br /><br />
     * <img src="patterns/AA/ClientPreferencesDialog/save_entitlements_checkbox.png"><br /><br />
     * Text antialiasing disabled:<br />
     * <img src="patterns/noAA/ClientPreferencesDialog/ok_button.png"><br /><br />
     * <img src="patterns/noAA/ClientPreferencesDialog/cancel_button.png"><br /><br />
     * <img src="patterns/noAA/ClientPreferencesDialog/user_name_label.png"><br /><br />
     * <img src="patterns/noAA/ClientPreferencesDialog/password_label.png"><br /><br />
     * <img src="patterns/noAA/ClientPreferencesDialog/storage_url_label.png"><br /><br />
     * <img src="patterns/noAA/ClientPreferencesDialog/connection_info_label.png"><br /><br />
     * <img src="patterns/noAA/ClientPreferencesDialog/save_entitlements_checkbox.png"><br /><br />
     */
    public void testEditClientPreferences() throws IOException, AWTException
    {
        GuiRobot robot = startThermostatAndStorage();

        enterMainMenu(robot);
        robot.pressRightKey();
        robot.pressDownKey();
        robot.pressEnterKey();
        sleepIfRealScreen(2000);

        prepareScreenshot(robot, "testEditClientPreferencesTest1");

        robot.pressEnterKey();
        stopThermostatAndStorage(robot);

        checkForPattern(robot, Patterns.ClientPreferencesDialog.OK_BUTTON, "ok button");
        checkForPattern(robot, Patterns.ClientPreferencesDialog.CANCEL_BUTTON, "cancel button");
        checkForPattern(robot, Patterns.ClientPreferencesDialog.CONNECTION_INFO_LABEL, "connection info text on dialog");
        checkForPattern(robot, Patterns.ClientPreferencesDialog.USER_NAME_LABEL, "user name label");
        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");

        robot.saveScreenshot("testEditClientPreferencesTest2");
    }

    /**
     * Test if dialog with all agents information is really shown on the screen.
     *
     * Following patterns are checked for its presence:<br /><br />
     * Text antialiasing enabled:<br />
     * <img src="patterns/AA/AllAgentsDialog/close_button.png"><br /><br />
     * <img src="patterns/AA/AllAgentsDialog/close_button2.png"><br /><br />
     * Text antialiasing disabled:<br />
     * <img src="patterns/noAA/AllAgentsDialog/close_button.png"><br /><br />
     * <img src="patterns/noAA/AllAgentsDialog/close_button2.png"><br /><br />
     */
    public void testAllAgentsDialog() throws IOException, AWTException
    {
        GuiRobot robot = startThermostatAndStorage();

        enterMainMenu(robot);
        robot.pressRightKey();
        robot.pressRightKey();
        robot.pressDownKey();
        robot.pressEnterKey();

        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);
        stopThermostatAndStorage(robot);

        Assert.assertNotNull(rect, "Close button can't be found!");

        robot.saveScreenshot("testAllAgentsDialogTest2");
    }

    /**
     * Start this test suite by performing basic GUI-related tests.
     */
    public static void main(String[] args)
    {
        new GuiClientSmokeTest().doTests(args);
    }

}