/* +----------------------------------------------------------------------+ | Class: CLauncher | | | | Developper: Eric Gavaldo (eric.gavaldo@xqual.com) | | Version: 1.0 | +----------------------------------------------------------------------+ */ package com.xqual.xlauncher.ranorex; import java.io.File; import java.util.Vector; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import com.xqual.xagent.launcher.CExecutionStep; import com.xqual.xagent.launcher.CLauncher; import com.xqual.xagent.launcher.CParamParsingException; import com.xqual.xagent.launcher.CReturnStatus; import com.xqual.xagent.launcher.runner.CRunner; import com.xqual.xagent.launcher.runner.IRunner; import com.xqual.xcommon.CAttribute; import com.xqual.xcommon.CXmlDocumentFactory; import com.xqual.xcommon.IConstantsResults; import com.xqual.xcommon.utils.CFileUtils; /** * The CLauncherImpl implementation of ILauncher for Ranorex native tests. * @author egavaldo */ public class CLauncherImpl extends CLauncher implements IConstantsResults { // +==============================================================+ // | Attributes | // +==============================================================+ static final String TRACE_HEADER = "{ranorex } "; // parameters impacting executing at run time set by the test operator private String testRootPath; //private String ranorexInstallPath; //private String testLanguage; //private String testConfiguration; private String testParentFolderPath; // +==============================================================+ // | Constructors // +==============================================================+ public CLauncherImpl() { super(TRACE_HEADER); } // +==============================================================+ // | Methods | // +==============================================================+ @Override public CReturnStatus initialize(int sutId, String sutName, String sutVersion) { setSutDetails(sutId, sutName, sutVersion); // check the configuration sent by the manager printConfiguration(); Vector executionSteps = new Vector(); try { // retrieve the parameters we need testRootPath = getStringParamValue("General", "Test root path"); // i.e. C:/Documents and Settings/keynux/Mes documents/RanorexStudio Projects/Samples //ranorexInstallPath = getStringParamValue("Ranorex", "Ranorex install path"); // i.e. C:/Program files/Ranorex 2.3 //testLanguage = getStringParamValue("Ranorex", "Language"); // i.e. Python //testConfiguration = getStringParamValue("Ranorex", "Configuration"); // i.e. Debug } catch (CParamParsingException e) { traceln(LOG_PRIORITY_SEVERE, "parsing error during initialization"); executionSteps.add(new CExecutionStep(RESULT_FAILURE, "Exception during initialize: " + e.getMessage())); return new CReturnStatus(RESULT_FAILURE, executionSteps); } return new CReturnStatus(RESULT_SUCCESS, executionSteps); } @Override public CReturnStatus preRun(int testId, String testPath, String testName, Vector attributes, String additionalInfo) { traceln(LOG_PRIORITY_INFO, "preRun testId=" + testId + " testPath=" + testPath + " [" + testName + "]..."); return new CReturnStatus(RESULT_SUCCESS); } @Override public CReturnStatus run(int testId, String testPath, String testName, int testcaseIndex, String testcaseName, String additionalInfo) { traceln(LOG_PRIORITY_INFO, "run testId=" + testId + " testPath=" + testRootPath + "/" + testPath + "/" + testName + " testcaseIndex=" + testcaseIndex + "..."); Vector executionSteps = new Vector(); // i.e. C:/Documents and Settings/keynux/Mes documents/RanorexStudio Projects/Samples/WordPad Test Sample /bin/debug/Word Pad Test .exe // i.e. C:/Documents and Settings/keynux/Mes documents/RanorexStudio Projects/Samples/WordPad Test SampleVBNET/bin/debug/Word Pad Test .exe // i.e. C:/Documents and Settings/keynux/Mes documents/RanorexStudio Projects/Samples/WordpadTestSamplePy /bin/debug/WordpadTestSamplePy.exe // \______________________________ testRootPath _______________________________/\________ canonical path__________/ \____ testName ___/ // \______________________________________________ testParentFolderPath __________________________________________/ // +------------------------------------+ // | Run the Ranorex executable // +------------------------------------+ /* if (testLanguage.equals("C#")) { testExecutionPath = CFileUtils.quoteFilePath(testRootPath + "/" + testName + "/bin/" + testConfiguration.toLowerCase()); executableName = testName + ".exe"; } else if (testLanguage.equals("VBNET")) { testExecutionPath = CFileUtils.quoteFilePath(testRootPath + "/" + testName + "VBNET/bin/" + testConfiguration.toLowerCase()); executableName = testName + ".exe"; } else if (testLanguage.equals("Python")) { testExecutionPath = CFileUtils.quoteFilePath(testRootPath + "/" + testName.trim() + "Py/bin/" + testConfiguration.toLowerCase()); executableName = testName + ".exe"; } */ testParentFolderPath = testRootPath + "/" + testPath; File workingDir = new File(testParentFolderPath); CRunner exeRunner = new CRunner("[" + testId + "] "+ testPath + ":" + testName + "." + testcaseIndex, CFileUtils.quoteFilePath(testParentFolderPath + "/" + testName + ".exe"), workingDir); short result = exeRunner.requestAction(IRunner.START_PROCESS, IRunner.WAIT_END_OF_EXECUTION); if (result == RESULT_FAILURE) { executionSteps.add(new CExecutionStep(RESULT_FAILURE, "execution failed")); } else { executionSteps.add(new CExecutionStep(RESULT_SUCCESS, "execution succeeded")); } File rxlogFile = retrieveRxlogFile(testName); if (rxlogFile == null) { executionSteps.add(new CExecutionStep(RESULT_FAILURE, "rxlog file for test " + testName + " not found!")); return new CReturnStatus(RESULT_FAILURE, executionSteps); } addAttachment(rxlogFile); Vector screenshotFiles = retrieveScreenshots(testName); addAttachments(screenshotFiles); return parseResultFile(rxlogFile, executionSteps); } @Override public CReturnStatus postRun(int testId, String testPath, String testName) { traceln(LOG_PRIORITY_INFO, "postRun testId=" + testId + " testPath=" + testPath + ":" + testName + "..."); return new CReturnStatus(RESULT_SUCCESS); } @Override public CReturnStatus terminate() { traceln(LOG_PRIORITY_INFO, "terminate..."); return new CReturnStatus(RESULT_SUCCESS); } // +--------------------------+ // ¦ Utilities ¦ // +--------------------------+ private File retrieveRxlogFile(String testName) { File output = new File(testParentFolderPath + "/" + testName.replaceAll(" ", "") + ".rxlog"); if (output.exists()) { return output; } else { traceln(LOG_PRIORITY_SEVERE, "log file " + output + " does not exist !"); return null; } } private Vector retrieveScreenshots(String testName) { Vector output = new Vector(); File parentFolder = new File(testParentFolderPath); File[] childFiles = parentFolder.listFiles(); for (int i=0; i executionSteps) { executionSteps.add(new CExecutionStep(RESULT_NOT_EXECUTED, "Parsing the reports...")); boolean atLeastOneFailure = false; String xmlContent = CFileUtils.FileToString(rxlogFile, "UTF-8"); Document xmlDocument = CXmlDocumentFactory.createXMLDoc(xmlContent); NodeList nodeList = CXmlDocumentFactory.getNodeObjListFromXPath(xmlDocument, "//message"); for (int i=0; i0) { executionSteps.add(new CExecutionStep(time, result, "[" + category + "] " + traceNode.getNodeValue())); //System.out.println("- - -> " + time + "\t" + result + "\t" + "[" + category + "] " + traceNode.getNodeValue().trim()); } } } return new CReturnStatus(atLeastOneFailure ? RESULT_FAILURE : RESULT_SUCCESS, executionSteps); } // +----------------------------- // | MAIN // +----------------------------- public static void main(String[] args) { CLauncherImpl toto = new CLauncherImpl(); toto.parseResultFile(new File("C:/toto.xml"), new Vector()); } }