view src/org/thermostat/qa/testsuites/GuiHostViewSmokeTest.java @ 150:3d06e2d323cb

refactoring of the framework+testsuites for gui tests so Xvfb+fluxbox may be used
author Jana Fabrikova <jfabriko@redhat.com>
date Tue, 01 Apr 2014 15:09:08 +0200
parents ddc240382616
children 7baba5d67a16
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 java.util.List;



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.framework.ThermostatUtilities.AgentThread;
import org.thermostat.qa.annotations.TillVersion;
import org.thermostat.qa.annotations.SinceVersion;



/**
 * Set o tests for checking if the host view tab in 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.
 */
@TestType(TestTypes.GUI_TEST)
public class GuiHostViewSmokeTest extends ThermostatGuiTest
{

    @Override
    protected void setUp()
    {
        // Auto-generated method stub
    }
    
    @Override
    protected void tearDown()
    {
        // Auto-generated method stub
    }
    
    private GuiRobot clickOnHostView() 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("ThermostatStartForHostView1");
        
        Rectangle r = checkForPattern(robot, Patterns.MainWindow.HOST_VIEW_ICON, "host view icon");
        robot.clickToRectangle(r);
        
        sleepIfRealScreen(2000);
        robot.prepareScreenshot("HostViewActive1");
        
        
        checkForPattern(robot, Patterns.MainWindow.HOST_VIEW_ICON_ACTIVE, "host view active icon");
        robot.saveScreenshot("HostViewActive2");
        
        return robot;
    }


    @TillVersion("0.18.0")
    public void testOverviewTab() throws IOException, AWTException
    {
        GuiRobot robot = clickOnHostView();
        
        robot.prepareScreenshot("HostViewOverviewTab1");
        
        //the overview tab should be active
        checkForPattern(robot, Patterns.HostView.OVERVIEW_TAB_CHOSEN, "overview tab active");
                        
        //all other tabs are not active
        checkForPattern(robot, Patterns.HostView.PROCESSOR_TAB, "processor tab");
        checkForPattern(robot, Patterns.HostView.MEMORY_TAB, "memory tab");
        checkForPattern(robot, Patterns.HostView.NUMA_TAB, "numa tab");
        
        //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");
        
        //specific patterns inside the overview tab
        checkForPattern(robot, Patterns.HostViewOverviewTab.BASICS_LABEL, "basic label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.HOST_LABEL, "host label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.HW_LABEL, "hw label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.INTERFACE_LABEL, "interface label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.IPV4_ADDRESS_LABEL, "ipv4 address label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.IPV6_ADDRESS_LABEL, "ipv6 address label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.NETWORK_LABEL,"network label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.OS_KERNEL_LABEL, "os kernel label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.OS_NAME_LABEL, "os name label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.PROCESSOR_COUNT_LABEL, "processor count label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.PROCESSOR_MODEL_LABEL, "processor model label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.SW_LABEL, "sw label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.TOTAL_MEMORY_LABEL, "total memory label");
                
        robot.saveScreenshot("HostViewOverviewTab2");

        //stop the gui, agent, storage
        stopThermostatParts(robot);
    }
    
    @SinceVersion("0.18.1")
    public void testOverviewTab2() throws IOException, AWTException
    {
        GuiRobot robot = clickOnHostView();
        
        robot.prepareScreenshot("HostViewOverviewTab1");
        
        
        //the overview tab should be active
        checkForPattern(robot, Patterns.HostView.OVERVIEW_TAB_CHOSEN, "overview tab active");
                        
        //all other tabs are not active
        checkForPattern(robot, Patterns.HostView.PROCESSOR_TAB, "processor tab");
        checkForPattern(robot, Patterns.HostView.MEMORY_TAB, "memory tab");
        checkForPattern(robot, Patterns.HostView.NUMA_TAB, "numa tab");
        
        //maximize the window so all components of the Overview tab are visible
        /* robot.press2Keys(KeyEvent.VK_WINDOWS, KeyEvent.VK_UP);
           does not work, makes only gnome help visible */
        Rectangle from = checkForPattern(robot, Patterns.MainWindow.RESIZABLE, "resizable r l corner");
        robot.resize(from, 400, 300);
        
        sleepIfRealScreen(2000);
        
        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");
        
        //specific patterns inside the overview tab
        checkForPattern(robot, Patterns.HostViewOverviewTab.BASICS_LABEL, "basic label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.HOST_LABEL, "host label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.HW_LABEL, "hw label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.INTERFACE_LABEL, "interface label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.IPV4_ADDRESS_LABEL, "ipv4 address label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.IPV6_ADDRESS_LABEL, "ipv6 address label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.NETWORK_LABEL,"network label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.OS_KERNEL_LABEL, "os kernel label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.OS_NAME_LABEL, "os name label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.PROCESSOR_COUNT_LABEL, "processor count label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.PROCESSOR_MODEL_LABEL, "processor model label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.SW_LABEL, "sw label");
        checkForPattern(robot, Patterns.HostViewOverviewTab.TOTAL_MEMORY_LABEL, "total memory label");
                
        robot.saveScreenshot("HostViewOverviewTabResized2");

        //stop the gui, agent, storage
        stopThermostatParts(robot);
    }
    
    private void stopThermostatParts(GuiRobot robot) throws IOException {
        stopGUI(robot);
        stopStorage();
        runHelperBashScript("stop_all_therm_agents.sh");
    }

    public void testProcessorTab() throws IOException, AWTException
    {
        GuiRobot robot = clickOnHostView();
        
        Rectangle r = checkForPattern(robot, Patterns.HostView.PROCESSOR_TAB, "processor tab");
        robot.clickToRectangle(r);
        sleepIfRealScreen(1000);
       
        robot.prepareScreenshot("HostViewProcessorTab1");
            
        //the processor tab should be active
        checkForPattern(robot, Patterns.HostView.PROCESSOR_TAB_CHOSEN, "processor tab active");
                        
        //all other tabs are not active
        checkForPattern(robot, Patterns.HostView.OVERVIEW_TAB, "overview tab");
        checkForPattern(robot, Patterns.HostView.MEMORY_TAB, "memory tab");
        checkForPattern(robot, Patterns.HostView.NUMA_TAB, "numa tab");
        
        //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");
        
        //specific patterns inside the overview tab
        checkForPattern(robot, Patterns.HostViewProcessorTab.CPU0_LABEL, "cpu0 label");
        checkForPattern(robot, Patterns.HostViewProcessorTab.CPU_USAGE_LEGEND, "cpu usage legend");
        checkForPattern(robot, Patterns.HostViewProcessorTab.DISPLAY_RECENT_LABEL, "display recent label");
        checkForPattern(robot, Patterns.HostViewProcessorTab.DISPLAY_RECENT_EDIT, "display recent edit");
        checkForPattern(robot, Patterns.HostViewProcessorTab.DISPLAY_RECENT_DROP, "display recent dropbox");
        checkForPattern(robot, Patterns.HostViewProcessorTab.PROCESSOR_COUNT_LABEL, "processor count label");
        checkForPattern(robot, Patterns.HostViewProcessorTab.PROCESSOR_LABEL, "processor label");
        checkForPattern(robot, Patterns.HostViewProcessorTab.PROCESSOR_MODEL_LABEL, "processor model label");
        checkForPattern(robot, Patterns.HostViewProcessorTab.TIME_LEGEND, "time legend");
        
        //TODO add here checking for the presence of graph
        
        
        robot.saveScreenshot("HostViewProcessorTab2");


        //stop the gui, agent, storage
        stopThermostatParts(robot);
    }
    
    public void testMemoryTab() throws IOException, AWTException
    {
        GuiRobot robot = clickOnHostView();
        
        Rectangle r = checkForPattern(robot, Patterns.HostView.MEMORY_TAB, "memory tab");
        robot.clickToRectangle(r);
        sleepIfRealScreen(1000);
    
        robot.prepareScreenshot("HostViewMemoryTab1");
        
            
        //the overview tab should be active
        checkForPattern(robot, Patterns.HostView.MEMORY_TAB_CHOSEN, "memory tab active");
                        
        //all other tabs are not active
        checkForPattern(robot, Patterns.HostView.OVERVIEW_TAB, "overview tab");
        checkForPattern(robot, Patterns.HostView.PROCESSOR_TAB, "processor tab");
        checkForPattern(robot, Patterns.HostView.NUMA_TAB, "numa tab");
        
        //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");
        
        //specific patterns inside the overview tab
        checkForPattern(robot, Patterns.HostViewMemoryTab.MEMORY_LABEL, "memory label");
        checkForPattern(robot, Patterns.HostViewMemoryTab.DISPLAY_RECENT_LABEL, "display recent label");
        checkForPattern(robot, Patterns.HostViewMemoryTab.DISPLAY_RECENT_EDIT, "display recent edit");
        checkForPattern(robot, Patterns.HostViewMemoryTab.DISPLAY_RECENT_DROP, "display recent dropbox");
        checkForPattern(robot, Patterns.HostViewMemoryTab.SIZE_LEGEND, "size legend");
        checkForPattern(robot, Patterns.HostViewMemoryTab.TIME_LEGEND, "time legend");
        checkForPattern(robot, Patterns.HostViewMemoryTab.TOTAL_MEMORY_LABEL, "total memory label");
        checkForPattern(robot, Patterns.HostViewMemoryTab.FREE_MEMORY_CHECKED, "free memory checked");
        checkForPattern(robot, Patterns.HostViewMemoryTab.TOTAL_MEMORY_CHECKED, "total memory checked");
        checkForPattern(robot, Patterns.HostViewMemoryTab.TOTAL_SWAP_CHECKED, "total swap checked");
        checkForPattern(robot, Patterns.HostViewMemoryTab.USED_MEMORY_CHECKED, "used memory checked");

        //TODO try experimenting with checking/unchecking the graphs visibility
        //and finding given graphs in area between size/time legend
        
        robot.saveScreenshot("HostViewMemoryTab2");


        //stop the gui, agent, storage
        stopThermostatParts(robot);
    }
    
    public void testNumaTab() throws IOException, AWTException
    {
        GuiRobot robot = clickOnHostView();
        
        Rectangle r = checkForPattern(robot, Patterns.HostView.NUMA_TAB, "numa tab");
        robot.clickToRectangle(r);
        sleepIfRealScreen(1000);
        
        robot.prepareScreenshot("HostViewNumaTab1");
        
                
        //the overview tab should be active
        checkForPattern(robot, Patterns.HostView.NUMA_TAB_CHOSEN, "numa tab active");
                        
        //all other tabs are not active
        checkForPattern(robot, Patterns.HostView.OVERVIEW_TAB, "overview tab");
        checkForPattern(robot, Patterns.HostView.PROCESSOR_TAB, "processor tab");
        checkForPattern(robot, Patterns.HostView.MEMORY_TAB, "memory tab");
        
        //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");
        
        //specific patterns inside the overview tab
        checkForPattern(robot, Patterns.HostViewNumaTab.NUMA_LABEL, "numa label");
        checkForPattern(robot, Patterns.HostViewNumaTab.NODE0_CHECKED, "node0 checked");
        checkForPattern(robot, Patterns.HostViewNumaTab.NUMBER_HITS_LEGEND, "number of hits legend");
        checkForPattern(robot, Patterns.HostViewNumaTab.TIME_LEGEND, "time legend");
        checkForPattern(robot, Patterns.HostViewNumaTab.DISPLAY_RECENT_LABEL, "display recent label");
        checkForPattern(robot, Patterns.HostViewNumaTab.DISPLAY_RECENT_EDIT, "display recent edit");
        checkForPattern(robot, Patterns.HostViewNumaTab.DISPLAY_RECENT_DROP, "display recent dropbox");
        
        robot.saveScreenshot("HostViewNumaTab2");

        //stop the gui, agent, storage
        stopThermostatParts(robot);
    }
    
    /**
     * Start this test suite by performing host view GUI-related tests.
     */
    public static void main(String[] args)
    {
        new GuiHostViewSmokeTest().doTests(args);
    }

}