view src/org/thermostat/qa2/framework/services/ThermostatGui.java @ 187:877b403e8344

Extended support for packaged thermostat changes: Makefile: src/org/thermostat/qa2/framework/ThermostatQAConfig.java: src/org/thermostat/qa2/framework/services/ThermostatStorage.java: src/org/thermostat/qa2/framework/services/ThermostatAgent.java: src/org/thermostat/qa2/framework/services/ThermostatGui.java: src/org/thermostat/qa2/framework/services/ThermostatService.java: src/org/thermostat/qa2/tests/AgentWebStorageTest.java: src/org/thermostat/qa2/tests/CliClientDBModificationsSmokeTest.java: - Added more (changed) configuration options src/org/thermostat/qa2/framework/services/BackupService.java: src/org/thermostat/qa2/framework/utils/ThermostatUtilities.java: - Using sudo to backup and overwrite root-owned thermostat configuration files. src/org/thermostat/qa2/framework/services/Tomcat.java - Added support for running native tomcat. src/org/thermostat/qa2/framework/TestRunner.java: src/org/thermostat/qa2/reporter/Generator.java: - Fixed bug in reporter (when test ends with error).
author Zdenek Zambersky <zzambers@redhat.com>
date Fri, 10 Jul 2015 14:21:09 +0200
parents 0d34a379de82
children a74aa91ab44c
line wrap: on
line source

/*
 ThermostatQA - test framework for Thermostat Monitoring Tool

 Copyright 2015 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.qa2.framework.services;

import org.thermostat.qa2.framework.NativeProcess;
import org.thermostat.qa2.framework.ThermostatQAConfig;
import org.thermostat.qa2.framework.utils.CommonUtilities;

/**
 *
 * @author Zdeněk Žamberský
 */
public class ThermostatGui extends ShellService {

    public ThermostatGui() {
        this("tested");
    }

    public ThermostatGui(String targetThermostat) {
        this(ThermostatQAConfig.getThermostatExecutablePath(targetThermostat), ThermostatQAConfig.getThermostatUserHome(targetThermostat));
    }

    public ThermostatGui(String thermostatExecutable, String thermostatUserHome) {
        super(thermostatExecutable, "gui", "-J-Dawt.useSystemAAFontSettings=false", "-J-Dswing.aatext=false");
        addEnvVariable("USER_THERMOSTAT_HOME", thermostatUserHome);
    }

    @Override
    public String getServiceName() throws Exception {
        return "Thermostat gui";
    }

    int timeout = 30;

    @Override
    public void startServiceImpl() throws Exception {
        super.startServiceImpl();
        for (int i = 0; i < timeout; ++i) {
            NativeProcess process = new NativeProcess("xdotool", "search", "--onlyvisible", "-class", "Thermostat");
            process.setLabel("Window checker");
            process.start();
            int ret = process.waitForRaw();
            if (ret == 0) {
                CommonUtilities.sleep(2000);
                return;
            }
            Thread.sleep(1000);
            if (!isRunning()) {
                throw new Exception(getServiceName() + ": stopped while waiting for window ");
            }
        }
        throw new Exception(getServiceName() + ": expired timeout " + timeout + " s waitng for window");
    }
}