List of usage examples for org.openqa.selenium Capabilities getPlatform
default Platform getPlatform()
From source file:com.chtr.tmoauto.webui.CommonFunctions.java
License:Open Source License
@Override public String getPlatform() { Capabilities capabilities = ((RemoteWebDriver) webDriver).getCapabilities(); return capabilities.getPlatform().toString(); }
From source file:com.vaadin.testbench.parallel.BrowserUtil.java
/** * Returns a human readable identifier of the platform described by the * given capabilities. Used mainly for screenshots * * @param capabilities//from w w w. j a v a 2 s .c o m * @return a human readable string describing the platform */ public static String getPlatform(Capabilities capabilities) { if (capabilities == null) { return "Unknown"; } try { Platform p = capabilities.getPlatform(); if (p == Platform.WIN8 || p == Platform.WINDOWS || p == Platform.VISTA || p == Platform.XP) { return "Windows"; } else if (p == Platform.MAC) { return "Mac"; } } catch (Exception e) { } Object rawPlatform = capabilities.getCapability(CapabilityType.PLATFORM); if (rawPlatform == null) { return "Unknown"; } return rawPlatform.toString(); }
From source file:com.vaadin.testbench.screenshot.ReferenceNameGenerator.java
/** * Generates the actual name of a reference screen shot from a reference ID * and browser information./* w w w . ja va 2 s . c o m*/ * * @param referenceId * the reference ID * @param browserCapabilities * a {@link Capabilities} instance containing information on the * browser. * @return The actual name. */ public String generateName(String referenceId, Capabilities browserCapabilities) { String platformString; Platform platform = browserCapabilities.getPlatform(); if (platform != null) { platformString = platform.toString().toLowerCase(); } else { platformString = "unknown"; } return String.format("%s_%s_%s_%s", referenceId, platformString, browserCapabilities.getBrowserName(), getMajorVersion(browserCapabilities)); }
From source file:com.vaadin.testbench.screenshot.ReferenceNameGeneratorTest.java
@Test public void testGenerateName_shotFirefox11inCapabilities_returnsGeneratedName() { Capabilities ffcaps = createNiceMock(Capabilities.class); expect(ffcaps.getPlatform()).andReturn(Platform.XP); expect(ffcaps.getBrowserName()).andReturn("Firefox"); expect(ffcaps.getVersion()).andReturn("13.0.1"); replay(ffcaps);/*from w w w .jav a2s . co m*/ String name = rng.generateName("shot", ffcaps); assertEquals("shot_xp_Firefox_13", name); verify(ffcaps); }
From source file:com.vaadin.testbench.screenshot.ReferenceNameGeneratorTest.java
@Test public void testGenerateName_fooSafari5inCapabilities_returnsGeneratedName() { Capabilities safari = createNiceMock(Capabilities.class); expect(safari.getPlatform()).andReturn(Platform.MAC); expect(safari.getBrowserName()).andReturn("Safari"); expect(safari.getVersion()).andReturn("5"); replay(safari);/* ww w .ja va 2 s. c om*/ String name = rng.generateName("foo", safari); assertEquals("foo_mac_Safari_5", name); verify(safari); }
From source file:com.vaadin.testbench.screenshot.ReferenceNameGeneratorTest.java
@Test public void testGenerateName_barPhantomJSinCapabilities_returnsGeneratedName() { Capabilities phantom = createNiceMock(Capabilities.class); expect(phantom.getPlatform()).andReturn(Platform.MAC); expect(phantom.getBrowserName()).andReturn("phantomjs"); expect(phantom.getVersion()).andReturn("phantomjs-1.8.1+ghostdriver-1.0.2"); replay(phantom);/* w w w .j a v a 2 s . c o m*/ String name = rng.generateName("bar", phantom); assertEquals("bar_mac_phantomjs_1", name); verify(phantom); }
From source file:com.vaadin.testbench.screenshot.ReferenceNameGeneratorTest.java
@Test public void testGenerateName_shotEdgeinCapabilities_returnsGeneratedName() { Capabilities chrome = createNiceMock(Capabilities.class); expect(chrome.getPlatform()).andReturn(Platform.XP); expect(chrome.getBrowserName()).andReturn("MicrosoftEdge"); expect(chrome.getVersion()).andReturn(""); expect(chrome.getCapability("browserVersion")).andReturn("25"); replay(chrome);/*from w ww .ja v a 2s . c o m*/ String name = rng.generateName("shot", chrome); assertEquals("shot_xp_MicrosoftEdge_25", name); verify(chrome); }
From source file:cuenen.raymond.svgplot.TestSuiteClass.java
License:CDDL license
@AfterSuite(alwaysRun = true) public static void stopSelenium() { for (WebDriver driver : DRIVERS) { StringBuilder sb = new StringBuilder("Tested "); if (driver instanceof HasCapabilities) { Capabilities caps = ((HasCapabilities) driver).getCapabilities(); if (caps.getBrowserName().equals("opera")) { /* The OperaDriver has no support for JavaScript alert/popup dialogues. */ sb.append("partly "); }/*from w w w . j av a2 s . com*/ sb.append("with ").append(caps.getBrowserName()); sb.append(" ").append(caps.getVersion()); sb.append(" on ").append(caps.getPlatform()); } else { sb.append("with ").append(driver); } Reporter.log(sb.toString(), true); driver.quit(); } }
From source file:org.cerberus.engine.execution.impl.ExecutionRunService.java
License:Open Source License
@Override public TestCaseExecution executeTestCase(TestCaseExecution tCExecution) throws CerberusException { long runID = tCExecution.getId(); String logPrefix = runID + " - "; /**//w w w .j a v a2s. com * Feeding Build Rev of main Application system to * testcaseexecutionsysver table. Only if execution is not manual. */ try { if (!(tCExecution.isManualURL())) { /** * Insert SystemVersion in Database */ TestCaseExecutionSysVer myExeSysVer = null; try { LOG.debug(logPrefix + "Registering Main System Version."); myExeSysVer = factoryTestCaseExecutionSysVer.create(runID, tCExecution.getApplicationObj().getSystem(), tCExecution.getBuild(), tCExecution.getRevision()); testCaseExecutionSysVerService.insertTestCaseExecutionSysVer(myExeSysVer); } catch (CerberusException ex) { LOG.error(logPrefix + ex.getMessage()); } LOG.debug(logPrefix + "Main System Version Registered."); /** * For all Linked environment, we also keep track on the * build/rev information inside testcaseexecutionsysver table. */ LOG.debug(logPrefix + "Registering Linked System Version."); try { List<CountryEnvLink> ceLink = null; ceLink = countryEnvLinkService.convert( countryEnvLinkService.readByVarious(tCExecution.getApplicationObj().getSystem(), tCExecution.getCountry(), tCExecution.getEnvironment())); for (CountryEnvLink myCeLink : ceLink) { LOG.debug(logPrefix + "Linked environment found : " + myCeLink.getSystemLink() + myCeLink.getCountryLink() + myCeLink.getEnvironmentLink()); CountryEnvParam mycountEnvParam; try { mycountEnvParam = this.countryEnvParamService .convert(this.countryEnvParamService.readByKey(myCeLink.getSystemLink(), myCeLink.getCountryLink(), myCeLink.getEnvironmentLink())); myExeSysVer = factoryTestCaseExecutionSysVer.create(runID, myCeLink.getSystemLink(), mycountEnvParam.getBuild(), mycountEnvParam.getRevision()); testCaseExecutionSysVerService.insertTestCaseExecutionSysVer(myExeSysVer); } catch (CerberusException ex) { // Referencial Integrity link between countryEnvLink and CountryEnvParam table should secure that exception to never happen. LOG.error(logPrefix + ex.getMessage()); throw new CerberusException(ex.getMessageError()); } } } catch (CerberusException ex) { LOG.debug(logPrefix + "No Linked environment found."); } LOG.debug(logPrefix + "Linked System Version Registered."); } /** * Get used SeleniumCapabilities (empty if application is not GUI) */ LOG.debug(logPrefix + "Getting Selenium capabitities for GUI applications."); if (tCExecution.getApplicationObj().getType().equalsIgnoreCase("GUI")) { try { Capabilities caps = this.serverService.getUsedCapabilities(tCExecution.getSession()); tCExecution.setBrowserFullVersion( caps.getBrowserName() + " " + caps.getVersion() + " " + caps.getPlatform().toString()); tCExecution.setVersion(caps.getVersion()); tCExecution.setPlatform(caps.getPlatform().toString()); } catch (Exception ex) { LOG.error(logPrefix + "Exception on selenium getting Used Capabilities :" + ex.toString()); } LOG.debug(logPrefix + "Selenium capabitities loaded."); } else { // If Selenium is not needed, the selenium and browser info is set to empty. tCExecution.setSeleniumIP(""); tCExecution.setSeleniumPort(""); tCExecution.setBrowser(""); tCExecution.setVersion(""); tCExecution.setPlatform(""); LOG.debug(logPrefix + "No Selenium capabitities loaded because application not GUI : " + tCExecution.getApplicationObj().getType()); } /** * Load PreTestCase information and set PreTCase to the * TestCaseExecution object */ tCExecution.setResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_LOADINGDETAILEDDATA)); LOG.debug(logPrefix + "Loading Pre-testcases."); List<TestCase> preTests = testCaseService.findTestCaseActiveByCriteria("Pre Testing", tCExecution.getTestCaseObj().getApplication(), tCExecution.getCountry()); tCExecution.setPreTestCaseList(preTests); if (!(preTests == null)) { LOG.debug( logPrefix + "Loaded PreTest List. " + tCExecution.getPreTestCaseList().size() + " found."); } LOG.debug(logPrefix + "Pre-testcases Loaded."); /** * Load Main TestCase with Step dependencies (Actions/Control) */ LOG.debug(logPrefix + "Loading all Steps information of Main testcase."); List<TestCaseStep> testCaseStepList; testCaseStepList = this.loadTestCaseService.loadTestCaseStep(tCExecution.getTestCaseObj()); tCExecution.getTestCaseObj().setTestCaseStep(testCaseStepList); LOG.debug(logPrefix + "Steps information of Main testcase Loaded : " + tCExecution.getTestCaseObj().getTestCaseStep().size() + " Step(s) found."); /** * Load Pre TestCase with Step dependencies (Actions/Control) */ LOG.debug(logPrefix + "Loading all Steps information (Actions & Controls) of all Pre-testcase."); List<TestCaseStep> preTestCaseStepList = new ArrayList<TestCaseStep>(); List<TestCase> preTestCase = new ArrayList<TestCase>(); for (TestCase myTCase : tCExecution.getPreTestCaseList()) { myTCase.setTestCaseStep(this.loadTestCaseService.loadTestCaseStep(myTCase)); preTestCaseStepList.addAll(myTCase.getTestCaseStep()); preTestCase.add(myTCase); LOG.debug(logPrefix + "Pre testcase : " + myTCase.getTest() + "-" + myTCase.getTestCase() + " Loaded With " + myTCase.getTestCaseStep().size() + " Step(s) found."); } tCExecution.setPreTestCaseList(preTestCase); LOG.debug(logPrefix + "All Steps information (Actions & Controls) of all Pre-testcase Loaded."); /** * Load All properties of the testcase */ LOG.debug(logPrefix + "Loading all Properties."); List<TestCaseCountryProperties> tcProperties = new ArrayList(); try { tcProperties = testCaseCountryPropertiesService.findAllWithDependencies(tCExecution.getTest(), tCExecution.getTestCase(), tCExecution.getCountry()); tCExecution.setTestCaseCountryPropertyList(tcProperties); } catch (CerberusException ex) { LOG.warn("Exception getting all the properties : " + ex); } if (LOG.isDebugEnabled()) { LOG.debug(logPrefix + "All Properties Loaded. " + tcProperties.size() + " property(ies) found : " + tcProperties); } /** * Start Execution of the steps/Actions/controls Iterate Steps. * mainExecutionTestCaseStepList will contain the list of steps to * execute for both pretest and test. This is where we schedule the * execution of the steps using mainExecutionTestCaseStepList * object. */ LOG.debug(logPrefix + "Starting the execution with step iteration."); List<TestCaseStep> mainExecutionTestCaseStepList; mainExecutionTestCaseStepList = new ArrayList<TestCaseStep>(); mainExecutionTestCaseStepList.addAll(preTestCaseStepList); mainExecutionTestCaseStepList.addAll(testCaseStepList); /** * Initialize the global TestCaseExecution Data List. */ // tCExecution.setResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_TESTEXECUTING)); try { testCaseExecutionService.updateTCExecution(tCExecution); } catch (CerberusException ex) { Logger.getLogger(ExecutionRunService.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } // Websocket --> we refresh the corresponding Detail Execution pages attached to this execution. if (tCExecution.isCerberus_featureflipping_activatewebsocketpush()) { TestCaseExecutionEndPoint.getInstance().send(tCExecution, true); } List<TestCaseExecutionData> myExecutionDataList = new ArrayList<TestCaseExecutionData>(); tCExecution.setTestCaseExecutionDataList(myExecutionDataList); // Evaluate the condition at the control level. AnswerItem<Boolean> conditionAnswerTc; try { tCExecution.setConditionVal1(variableService.decodeStringCompletly(tCExecution.getConditionVal1(), tCExecution, null, false)); } catch (CerberusEventException cex) { LOG.warn(cex); } try { tCExecution.setConditionVal2(variableService.decodeStringCompletly(tCExecution.getConditionVal2(), tCExecution, null, false)); } catch (CerberusEventException cex) { LOG.warn(cex); } conditionAnswerTc = this.conditionService.evaluateCondition(tCExecution.getConditionOper(), tCExecution.getConditionVal1(), tCExecution.getConditionVal2(), tCExecution); boolean execute_TestCase = (boolean) conditionAnswerTc.getItem(); if (execute_TestCase) { for (TestCaseStep testCaseStep : mainExecutionTestCaseStepList) { // init the index of the step in case we loop. int step_index = 1; boolean execute_Next_Step = false; TestCaseStepExecution testCaseStepExecution; int maxloop = parameterService.getParameterIntegerByKey("cerberus_loopstep_max", tCExecution.getApplicationObj().getSystem(), 20); do { /** * Start Execution of TestCaseStep */ long startStep = new Date().getTime(); /** * Create and Register TestCaseStepExecution */ MessageEvent stepMess = new MessageEvent(MessageEventEnum.STEP_PENDING) .resolveDescription("STEP", String.valueOf(testCaseStep.getSort())) .resolveDescription("STEPINDEX", String.valueOf(step_index)); testCaseStepExecution = factoryTestCaseStepExecution.create(runID, testCaseStep.getTest(), testCaseStep.getTestCase(), testCaseStep.getStep(), step_index, testCaseStep.getSort(), testCaseStep.getConditionOper(), testCaseStep.getConditionVal1(), testCaseStep.getConditionVal2(), testCaseStep.getConditionVal1(), testCaseStep.getConditionVal2(), null, startStep, 0, startStep, 0, new BigDecimal("0"), null, stepMess, testCaseStep, tCExecution, testCaseStep.getUseStep(), testCaseStep.getUseStepTest(), testCaseStep.getUseStepTestCase(), testCaseStep.getUseStepStep(), testCaseStep.getDescription()); testCaseStepExecution.setLoop(testCaseStep.getLoop()); testCaseStepExecutionService.insertTestCaseStepExecution(testCaseStepExecution); testCaseStepExecution.setExecutionResultMessage( new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_TESTSTARTED)); /** * We populate the TestCaseStep inside the execution * List */ tCExecution.addTestCaseStepExecutionList(testCaseStepExecution); // determine if step is executed (execute_Step) and if we trigger a new step execution after (execute_Next_Step) boolean execute_Step = true; AnswerItem<Boolean> conditionAnswer = new AnswerItem<>( new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_UNKNOWNCONDITION)); if (testCaseStepExecution.getLoop().equals(TestCaseStep.LOOP_ONCEIFCONDITIONFALSE) || testCaseStepExecution.getLoop().equals(TestCaseStep.LOOP_ONCEIFCONDITIONTRUE) || testCaseStepExecution.getLoop().equals(TestCaseStep.LOOP_WHILECONDITIONFALSEDO) || testCaseStepExecution.getLoop().equals(TestCaseStep.LOOP_WHILECONDITIONTRUEDO) || testCaseStepExecution.getLoop().equals("") || step_index > 1) { // Decode Conditionvalue1 and Conditionvalue2 and Evaluate the condition at the Step level. try { testCaseStepExecution.setConditionVal1(variableService.decodeStringCompletly( testCaseStepExecution.getConditionVal1(), tCExecution, null, false)); } catch (CerberusEventException cex) { LOG.warn(cex); } try { testCaseStepExecution.setConditionVal2(variableService.decodeStringCompletly( testCaseStepExecution.getConditionVal2(), tCExecution, null, false)); } catch (CerberusEventException cex) { LOG.warn(cex); } conditionAnswer = this.conditionService.evaluateCondition( testCaseStepExecution.getConditionOper(), testCaseStepExecution.getConditionVal1(), testCaseStepExecution.getConditionVal2(), tCExecution); execute_Step = (boolean) conditionAnswer.getItem(); switch (testCaseStepExecution.getLoop()) { case TestCaseStep.LOOP_ONCEIFCONDITIONFALSE: execute_Step = !execute_Step; execute_Next_Step = false; break; case TestCaseStep.LOOP_ONCEIFCONDITIONTRUE: case "": execute_Next_Step = false; break; case TestCaseStep.LOOP_WHILECONDITIONFALSEDO: case TestCaseStep.LOOP_DOWHILECONDITIONFALSE: execute_Step = !execute_Step; execute_Next_Step = execute_Step; break; case TestCaseStep.LOOP_WHILECONDITIONTRUEDO: case TestCaseStep.LOOP_DOWHILECONDITIONTRUE: execute_Next_Step = execute_Step; break; default: execute_Next_Step = false; } } else if (testCaseStepExecution.getLoop().equals(TestCaseStep.LOOP_DOWHILECONDITIONFALSE) || testCaseStepExecution.getLoop().equals(TestCaseStep.LOOP_DOWHILECONDITIONTRUE)) { // First Step execution for LOOP_DOWHILECONDITIONTRUE and LOOP_DOWHILECONDITIONFALSE --> We force the step execution and activate the next step execution. execute_Step = true; execute_Next_Step = true; } else { // First Step execution for Unknown Loop --> We force the step execution only once (default behaviour). execute_Step = true; execute_Next_Step = false; conditionAnswer.setResultMessage( new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_UNKNOWNCONDITION)); } /** * Execute Step */ LOG.debug(logPrefix + "Executing step : " + testCaseStepExecution.getTest() + " - " + testCaseStepExecution.getTestCase() + " - Step " + testCaseStepExecution.getStep() + " - Index " + testCaseStepExecution.getStep()); if (execute_Step) { /** * We execute the step */ testCaseStepExecution = this.executeStep(testCaseStepExecution, tCExecution); /** * Updating Execution Result Message only if * execution result message of the step is not PE or * OK. */ if ((!(testCaseStepExecution.getExecutionResultMessage() .equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_TESTSTARTED)))) && (!(testCaseStepExecution.getExecutionResultMessage() .equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_OK))))) { tCExecution.setResultMessage(testCaseStepExecution.getExecutionResultMessage()); } if (testCaseStepExecution.getStepResultMessage() .equals(new MessageEvent(MessageEventEnum.STEP_PENDING))) { testCaseStepExecution .setStepResultMessage(new MessageEvent(MessageEventEnum.STEP_SUCCESS)); } testCaseStepExecutionService.updateTestCaseStepExecution(testCaseStepExecution); if (testCaseStepExecution.isStopExecution()) { break; } } else { // We don't execute the step and record a generic execution. /** * Register Step in database */ MyLogger.log(ExecutionRunService.class.getName(), Level.DEBUG, "Registering Step : " + testCaseStepExecution.getStep()); // We change the Step message only if the Step is not executed due to condition. MessageEvent stepMes = new MessageEvent( MessageEventEnum.CONDITION_TESTCASESTEP_NOTEXECUTED); testCaseStepExecution.setStepResultMessage(stepMes); testCaseStepExecution.setReturnMessage(testCaseStepExecution.getReturnMessage() .replace("%COND%", testCaseStepExecution.getConditionOper()) .replace("%LOOP%", testCaseStepExecution.getLoop()) .replace("%MESSAGE%", conditionAnswer.getResultMessage().getDescription())); testCaseStepExecution.setEnd(new Date().getTime()); this.testCaseStepExecutionService.updateTestCaseStepExecution(testCaseStepExecution); MyLogger.log(ExecutionRunService.class.getName(), Level.DEBUG, "Registered Step"); } // Websocket --> we refresh the corresponding Detail Execution pages attached to this execution. if (tCExecution.isCerberus_featureflipping_activatewebsocketpush()) { TestCaseExecutionEndPoint.getInstance().send(tCExecution, false); } step_index++; } while (execute_Next_Step && step_index <= maxloop); if (testCaseStepExecution.isStopExecution()) { break; } } /** * If at that time the execution is still PE, we move it to OK. * It means that no issue were met. */ if ((tCExecution.getResultMessage() == null) || (tCExecution.getResultMessage() .equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_TESTSTARTED)))) { tCExecution.setResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_OK)); } /** * We record Selenium log at the end of the execution. */ try { tCExecution.addFileList(recorderService.recordSeleniumLog(tCExecution)); } catch (Exception ex) { LOG.error(logPrefix + "Exception Getting Selenium Logs " + tCExecution.getId() + " Exception :" + ex.toString()); } } else { // We don't execute the testcase. MessageGeneral mes; /** * Update Execution status from condition */ if (conditionAnswerTc.getResultMessage().getMessage().getCodeString().equals("PE")) { mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_NA_CONDITION); } else { mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_CONDITION); } mes.setDescription(mes.getDescription().replace("%COND%", tCExecution.getConditionOper()) .replace("%MES%", conditionAnswerTc.getResultMessage().getDescription())); tCExecution.setResultMessage(mes); } // tCExecution.setControlMessage("toto"); // tCExecution.setControlStatus(conditionAnswerTc.getResultMessage().getCodeString()); /** * We stop the server session here (selenium for ex.). */ try { tCExecution = this.stopTestCase(tCExecution); } catch (Exception ex) { LOG.error(logPrefix + "Exception Stopping Test " + tCExecution.getId() + " Exception :" + ex.toString()); } } finally { try { executionUUID.removeExecutionUUID(tCExecution.getExecutionUUID()); MyLogger.log(ExecutionRunService.class.getName(), Level.DEBUG, "Clean ExecutionUUID"); } catch (Exception ex) { MyLogger.log(ExecutionRunService.class.getName(), Level.FATAL, "Exception cleaning Memory: " + ex.toString()); //TODO:FN debug messages to be removed org.apache.log4j.Logger.getLogger(ExecutionRunService.class.getName()) .log(org.apache.log4j.Level.DEBUG, "[DEBUG] Exception cleaning Memory:" + ex.getMessage()); } MyLogger.log(ExecutionRunService.class.getName(), Level.INFO, "Execution Finished : UUID=" + tCExecution.getExecutionUUID() + "__ID=" + tCExecution.getId() + "__RC=" + tCExecution.getControlStatus() + "__" + "TestName=" + tCExecution.getEnvironment() + "." + tCExecution.getCountry() + "." + tCExecution.getBuild() + "." + tCExecution.getRevision() + "." + tCExecution.getTest() + "_" + tCExecution.getTestCase() + "_" + tCExecution.getTestCaseObj().getDescription().replace(".", "")); } //TODO:FN debug messages to be removed if (tCExecution.getControlStatus().equals("PE")) { org.apache.log4j.Logger.getLogger(ExecutionRunService.class.getName()).log(org.apache.log4j.Level.DEBUG, "[DEBUG] EXECUTION FINISHED WITH PE ? " + "Execution Finished : UUID=" + tCExecution.getExecutionUUID() + "__ID=" + tCExecution.getId() + "__RC=" + tCExecution.getControlStatus() + "__" + "TestName=" + tCExecution.getEnvironment() + "." + tCExecution.getCountry() + "." + tCExecution.getBuild() + "." + tCExecution.getRevision() + "." + tCExecution.getTest() + "_" + tCExecution.getTestCase() + "_" + tCExecution.getTestCaseObj().getDescription().replace(".", "")); } return tCExecution; }
From source file:org.cerberus.service.engine.impl.ExecutionRunService.java
License:Open Source License
@Override public TestCaseExecution executeTestCase(TestCaseExecution tCExecution) throws CerberusException { long runID = tCExecution.getId(); /**//from ww w . ja v a2s . co m * Feeding Build Rev of main Application system to * testcaseexecutionsysver table. Only if execution is not manual. */ try { if (!(tCExecution.isManualURL())) { /** * Insert SystemVersion in Database */ TestCaseExecutionSysVer myExeSysVer = null; try { myExeSysVer = factoryTestCaseExecutionSysVer.create(runID, tCExecution.getApplication().getSystem(), tCExecution.getBuild(), tCExecution.getRevision()); testCaseExecutionSysVerService.insertTestCaseExecutionSysVer(myExeSysVer); } catch (CerberusException ex) { MyLogger.log(ExecutionRunService.class.getName(), Level.INFO, ex.getMessage()); } /** * For all Linked environment, we also keep track on the * build/rev information inside testcaseexecutionsysver table. */ try { List<CountryEnvLink> ceLink = null; ceLink = countryEnvLinkService.findCountryEnvLinkByCriteria( tCExecution.getApplication().getSystem(), tCExecution.getCountry(), tCExecution.getEnvironment()); MyLogger.log(ExecutionRunService.class.getName(), Level.DEBUG, tCExecution.getId() + " - Linked environment found."); for (CountryEnvLink myCeLink : ceLink) { MyLogger.log(ExecutionRunService.class.getName(), Level.DEBUG, tCExecution.getId() + " - Linked environment found : " + myCeLink.getSystemLink() + myCeLink.getCountryLink() + myCeLink.getEnvironmentLink()); CountryEnvParam mycountEnvParam; try { mycountEnvParam = this.countryEnvParamService.findCountryEnvParamByKey( myCeLink.getSystemLink(), myCeLink.getCountryLink(), myCeLink.getEnvironmentLink()); myExeSysVer = factoryTestCaseExecutionSysVer.create(runID, myCeLink.getSystemLink(), mycountEnvParam.getBuild(), mycountEnvParam.getRevision()); testCaseExecutionSysVerService.insertTestCaseExecutionSysVer(myExeSysVer); } catch (CerberusException ex) { // Referencial Integrity link between countryEnvLink and CountryEnvParam table should secure that exception to never happen. MyLogger.log(ExecutionRunService.class.getName(), Level.FATAL, ex.getMessage()); throw new CerberusException(ex.getMessageError()); } } } catch (CerberusException ex) { MyLogger.log(ExecutionRunService.class.getName(), Level.DEBUG, tCExecution.getId() + " - No Linked environment found."); } } /** * Get used SeleniumCapabilities (empty if application is not GUI) */ if (tCExecution.getApplication().getType().equalsIgnoreCase("GUI")) { try { Capabilities caps = this.serverService.getUsedCapabilities(tCExecution.getSession()); tCExecution.setBrowserFullVersion( caps.getBrowserName() + " " + caps.getVersion() + " " + caps.getPlatform().toString()); tCExecution.setVersion(caps.getVersion()); tCExecution.setPlatform(caps.getPlatform().toString()); } catch (Exception ex) { MyLogger.log(ExecutionRunService.class.getName(), Level.ERROR, "exception on selenium getting Used Capabilities :" + ex.toString()); } } else { // If Selenium is not needed, the selenium and browser info is set to empty. tCExecution.setSeleniumIP(""); tCExecution.setSeleniumPort(""); tCExecution.setBrowser(""); tCExecution.setVersion(""); tCExecution.setPlatform(""); } /** * Load PreTestCase information and set PreTCase to the * TestCaseExecution object */ tCExecution.setResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_LOADINGDETAILEDDATA)); MyLogger.log(ExecutionRunService.class.getName(), Level.DEBUG, runID + " - Loading Pre testcases."); List<TCase> preTests = testCaseService.findTestCaseActiveByCriteria("Pre Testing", tCExecution.gettCase().getApplication(), tCExecution.getCountry()); tCExecution.setPreTCase(preTests); if (!(preTests == null)) { MyLogger.log(ExecutionRunService.class.getName(), Level.DEBUG, runID + " - Loaded PreTest List. " + tCExecution.getPreTCase().size() + " found."); } /** * Load Main TestCase with Step dependencies (Actions/Control) */ MyLogger.log(ExecutionRunService.class.getName(), Level.DEBUG, runID + " - Loading all Steps information of main testcase."); List<TestCaseStep> testCaseStepList; testCaseStepList = this.loadTestCaseService.loadTestCaseStep(tCExecution.gettCase()); tCExecution.gettCase().setTestCaseStep(testCaseStepList); MyLogger.log(ExecutionRunService.class.getName(), Level.DEBUG, runID + " - Loaded all Steps information of main testcase. " + tCExecution.gettCase().getTestCaseStep().size() + " Step(s) found."); /** * Load Pre TestCase with Step dependencies (Actions/Control) */ MyLogger.log(ExecutionRunService.class.getName(), Level.DEBUG, runID + " - Loading all Steps information of all pre testcase."); //TODO Pretest this.loadTestCaseService.loadTestCaseStep(tCExecution.getPreTCase()); List<TestCaseStep> preTestCaseStepList = new ArrayList<TestCaseStep>(); List<TCase> preTestCase = new ArrayList<TCase>(); for (TCase myTCase : tCExecution.getPreTCase()) { myTCase.setTestCaseStep(this.loadTestCaseService.loadTestCaseStep(myTCase)); preTestCaseStepList.addAll(myTCase.getTestCaseStep()); preTestCase.add(myTCase); MyLogger.log(ExecutionRunService.class.getName(), Level.DEBUG, runID + " - Pre testcase : " + myTCase.getTest() + "-" + myTCase.getTestCase() + " With " + myTCase.getTestCaseStep().size() + " Step(s) found."); } tCExecution.setPreTCase(preTestCase); /** * Load All properties of the testcase */ List<TestCaseCountryProperties> tcProperties = new ArrayList(); try { tcProperties = testCaseCountryPropertiesService.findAllWithDependencies(tCExecution.getTest(), tCExecution.getTestCase(), tCExecution.getCountry()); tCExecution.setTestCaseCountryPropertyList(tcProperties); if (LOG.isDebugEnabled()) { LOG.debug(tcProperties.size() + " property(ies) : " + tcProperties); } } catch (CerberusException ex) { LOG.warn("Exception getting all the properties : " + ex); } /** * Start Execution of the steps/Actions/controls Iterate Steps. * mainExecutionTestCaseStepList will contain the list of steps to * execute for both pretest and test. This is where we schedule the * execution of the steps using mainExecutionTestCaseStepList * object. */ MyLogger.log(ExecutionRunService.class.getName(), Level.DEBUG, runID + " - Starting the execution with step iteration."); List<TestCaseStep> mainExecutionTestCaseStepList; mainExecutionTestCaseStepList = new ArrayList<TestCaseStep>(); mainExecutionTestCaseStepList.addAll(preTestCaseStepList); mainExecutionTestCaseStepList.addAll(testCaseStepList); /** * Initialize the global TestCaseExecution Data List. */ // tCExecution.setResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_TESTEXECUTING)); try { testCaseExecutionService.updateTCExecution(tCExecution); } catch (CerberusException ex) { Logger.getLogger(ExecutionRunService.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } List<TestCaseExecutionData> myExecutionDataList = new ArrayList<TestCaseExecutionData>(); tCExecution.setTestCaseExecutionDataList(myExecutionDataList); for (TestCaseStep testCaseStep : mainExecutionTestCaseStepList) { /** * Start Execution of TestCaseStep */ long startStep = new Date().getTime(); /** * Create and Register TestCaseStepExecution */ TestCaseStepExecution testCaseStepExecution = factoryTestCaseStepExecution.create(runID, testCaseStep.getTest(), testCaseStep.getTestCase(), testCaseStep.getStep(), null, startStep, 0, startStep, 0, new BigDecimal("0"), null, new MessageEvent(MessageEventEnum.STEP_PENDING), testCaseStep, tCExecution, testCaseStep.getUseStep(), testCaseStep.getUseStepTest(), testCaseStep.getUseStepTestCase(), testCaseStep.getUseStepStep()); testCaseStepExecutionService.insertTestCaseStepExecution(testCaseStepExecution); testCaseStepExecution .setExecutionResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_TESTSTARTED)); /** * Execute Step */ MyLogger.log(ExecutionRunService.class.getName(), Level.DEBUG, runID + " - Executing step : " + testCaseStepExecution.getTest() + "-" + testCaseStepExecution.getTestCase() + "-" + testCaseStepExecution.getStep()); testCaseStepExecution = this.executeStep(testCaseStepExecution); /** * Updating Execution Result Message only if execution result * message of the step is not PE or OK. */ if ((!(testCaseStepExecution.getExecutionResultMessage() .equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_TESTSTARTED)))) && (!(testCaseStepExecution.getExecutionResultMessage() .equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_OK))))) { tCExecution.setResultMessage(testCaseStepExecution.getExecutionResultMessage()); } if (testCaseStepExecution.getStepResultMessage() .equals(new MessageEvent(MessageEventEnum.STEP_PENDING))) { testCaseStepExecution.setStepResultMessage(new MessageEvent(MessageEventEnum.STEP_SUCCESS)); } testCaseStepExecutionService.updateTestCaseStepExecution(testCaseStepExecution); if (testCaseStepExecution.isStopExecution()) { break; } } /** * If at that time the execution is still PE, we move it to OK. It * means that no issue were met. */ if ((tCExecution.getResultMessage() == null) || (tCExecution.getResultMessage() .equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_TESTSTARTED)))) { tCExecution.setResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_OK)); } try { recorderService.recordSeleniumLogAndGetName(tCExecution); } catch (Exception ex) { MyLogger.log(ExecutionRunService.class.getName(), Level.FATAL, "Exception Getting Selenium Logs " + tCExecution.getId() + " Exception :" + ex.toString()); org.apache.log4j.Logger.getLogger(ExecutionStartService.class.getName()).log( org.apache.log4j.Level.DEBUG, "[DEBUG] Failed to record selenium log and get name" + ex.getMessage()); } try { tCExecution = this.stopTestCase(tCExecution); } catch (Exception ex) { MyLogger.log(ExecutionRunService.class.getName(), Level.FATAL, "Exception Stopping Test " + tCExecution.getId() + " Exception :" + ex.toString()); org.apache.log4j.Logger.getLogger(ExecutionStartService.class.getName()) .log(org.apache.log4j.Level.DEBUG, "[DEBUG] Stop test case" + ex.getMessage()); } } finally { try { executionUUID.removeExecutionUUID(tCExecution.getExecutionUUID()); MyLogger.log(ExecutionRunService.class.getName(), Level.DEBUG, "Clean ExecutionUUID"); if (eSResponse.getExecutionSOAPResponse(tCExecution.getExecutionUUID()) != null) { eSResponse.removeExecutionSOAPResponse(tCExecution.getExecutionUUID()); MyLogger.log(ExecutionRunService.class.getName(), Level.DEBUG, "Clean ExecutionSOAPResponse"); } } catch (Exception ex) { MyLogger.log(ExecutionRunService.class.getName(), Level.FATAL, "Exception cleaning Memory: " + ex.toString()); //TODO:FN debug messages to be removed org.apache.log4j.Logger.getLogger(ExecutionStartService.class.getName()) .log(org.apache.log4j.Level.DEBUG, "[DEBUG] Exception cleaning Memory:" + ex.getMessage()); } MyLogger.log(ExecutionRunService.class.getName(), Level.INFO, "Execution Finished : UUID=" + tCExecution.getExecutionUUID() + "__ID=" + tCExecution.getId() + "__RC=" + tCExecution.getControlStatus() + "__" + "TestName=" + tCExecution.getEnvironment() + "." + tCExecution.getCountry() + "." + tCExecution.getBuild() + "." + tCExecution.getRevision() + "." + tCExecution.getTest() + "_" + tCExecution.getTestCase() + "_" + tCExecution.gettCase().getShortDescription().replace(".", "")); } //TODO:FN debug messages to be removed if (tCExecution.getControlStatus().equals("PE")) { org.apache.log4j.Logger.getLogger(ExecutionStartService.class.getName()).log( org.apache.log4j.Level.DEBUG, "[DEBUG] EXECUTION FINISHED WITH PE ? " + "Execution Finished : UUID=" + tCExecution.getExecutionUUID() + "__ID=" + tCExecution.getId() + "__RC=" + tCExecution.getControlStatus() + "__" + "TestName=" + tCExecution.getEnvironment() + "." + tCExecution.getCountry() + "." + tCExecution.getBuild() + "." + tCExecution.getRevision() + "." + tCExecution.getTest() + "_" + tCExecution.getTestCase() + "_" + tCExecution.gettCase().getShortDescription().replace(".", "")); } //Notify it's finnished // WebsocketTest wst = new WebsocketTest(); // try { // wst.handleMessage(tCExecution.getTag()); // } catch (IOException ex) { // Logger.getLogger(ExecutionRunService.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); // } // return tCExecution; }