How to use handleTestResults method of com.consol.citrus.remote.plugin.RunTestMojo class

Best Citrus code snippet using com.consol.citrus.remote.plugin.RunTestMojo.handleTestResults

Source:RunTestMojo.java Github

copy

Full Screen

...130 throw new MojoExecutionException("Failed to run tests on remote server: " + EntityUtils.toString(response.getEntity()));131 }132 if (run.isAsync()) {133 HttpClientUtils.closeQuietly(response);134 handleTestResults(pollTestResults());135 } else {136 handleTestResults(objectMapper.readValue(response.getEntity().getContent(), RemoteResult[].class));137 }138 } catch (IOException e) {139 throw new MojoExecutionException("Failed to run tests on remote server", e);140 } finally {141 HttpClientUtils.closeQuietly(response);142 }143 }144 /**145 * When using async test execution mode the client does not synchronously wait for test results as it might lead to read timeouts. Instead146 * this method polls for test results and waits for the test execution to completely finish.147 *148 * @return149 * @throws MojoExecutionException150 */151 private RemoteResult[] pollTestResults() throws MojoExecutionException {152 HttpResponse response = null;153 try {154 do {155 HttpClientUtils.closeQuietly(response);156 response = getHttpClient().execute(RequestBuilder.get(getServer().getUrl() + "/results")157 .addHeader(new BasicHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType()))158 .addParameter("timeout", String.valueOf(run.getPollingInterval()))159 .build());160 if (HttpStatus.SC_PARTIAL_CONTENT == response.getStatusLine().getStatusCode()) {161 getLog().info("Waiting for remote tests to finish ...");162 getLog().info(Stream.of(objectMapper.readValue(response.getEntity().getContent(), RemoteResult[].class))163 .map(RemoteResult::toTestResult).map(result -> result.isSkipped() ? "x" : (result.isSuccess() ? "+" : "-")).collect(Collectors.joining()));164 }165 } while (HttpStatus.SC_PARTIAL_CONTENT == response.getStatusLine().getStatusCode());166 if (HttpStatus.SC_OK != response.getStatusLine().getStatusCode()) {167 throw new MojoExecutionException("Failed to get test results from remote server: " + EntityUtils.toString(response.getEntity()));168 }169 return objectMapper.readValue(response.getEntity().getContent(), RemoteResult[].class);170 } catch (IOException e) {171 throw new MojoExecutionException("Failed to get test results from remote server", e);172 } finally {173 HttpClientUtils.closeQuietly(response);174 }175 }176 /**177 * Check test results for failures.178 * @param results179 * @throws IOException180 */181 private void handleTestResults(RemoteResult[] results) {182 StringWriter resultWriter = new StringWriter();183 resultWriter.append(String.format("%n"));184 OutputStreamReporter reporter = new OutputStreamReporter(resultWriter);185 Stream.of(results).forEach(result -> reporter.getTestResults().addResult(RemoteResult.toTestResult(result)));186 reporter.generateTestResults();187 getLog().info(resultWriter.toString());188 if (getReport().isHtmlReport()) {189 HtmlReporter htmlReporter = new HtmlReporter();190 htmlReporter.setReportDirectory(getOutputDirectory().getPath() + File.separator + getReport().getDirectory());191 Stream.of(results).forEach(result -> htmlReporter.getTestResults().addResult(RemoteResult.toTestResult(result)));192 htmlReporter.generateTestResults();193 }194 SummaryReporter summaryReporter = new SummaryReporter();195 Stream.of(results).forEach(result -> summaryReporter.getTestResults().addResult(RemoteResult.toTestResult(result)));...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Citrus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful