All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.internal.HtmlBuilder Maven / Gradle / Ivy

There is a newer version: 1.6
Show newest version
package com.github.internal;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.testng.ISuiteResult;
import org.testng.ITestResult;

import com.github.internal.Utils.ExecutionResults;

public class HtmlBuilder {

  public static StringBuilder buildScriptContent() {
    // SCRIPT CONTENT
    StringBuilder builder = new StringBuilder();
    builder
        .append(
            "\r\n")
        .append(
            "\r\n \r\n \r\n \r\n \r\n ")
        .append("\r\n 
"); builder.append("\r\n\n"); return builder; } public static StringBuilder buildEmailTab(ExecutionResults results) { StringBuilder builder = new StringBuilder(); builder .append( "
\r\n

Email Statistics


\r\n") .append( "\r\n") .append( "\r\n") .append( " Click Here To Download Email\r\n \r\n") .append( "\r\n
"); return builder; } public static StringBuilder buildLogsTab() { StringBuilder builder = new StringBuilder(); builder .append( "

**index.html need to be in current folder in order to display here

\r\n") .append( "
"); return builder; } public static StringBuilder appendMethodMetricsHeader(){ StringBuilder builder = new StringBuilder(); System.out.println("4 of 4: Capturing method metrics..."); builder .append( "
\r\n

Method Metrics


\r\n") .append( "\r\n \r\n \r\n") .append( "\r\n \r\n \r\n\t \r\n \r\n") .append("\r\n "); return builder; } public static StringBuilder appendMethodMetricsFooter(){ StringBuilder builder = new StringBuilder(); builder.append( "\r\n " + "
Class NameMethod NameStatusTime(s)Error Message
\r\n
" + "
"); return builder; } // "4 of 4: Capturing method metrics..." public static StringBuilder buildMethodMetricsTab(ISuiteResult suiteResult) { // METHOD METRICS TAB StringBuilder builder = new StringBuilder(); // Method Metrics gatherTestInformation(suiteResult, builder,false); return builder; } public static StringBuilder appendTestMetricsHeader(String executionTime){ StringBuilder builder = new StringBuilder(); System.out.println("3 of 4: Capturing test metrics..."); builder .append( "
\r\n

Test Metrics

" + "
Total Execution Time: " + executionTime + "

\r\n") .append( "\r\n \r\n \r\n") .append( "\r\n \r\n \r\n\t \r\n \r\n") .append("\r\n "); return builder; } public static StringBuilder appendTestMetricsFooter(){ StringBuilder builder = new StringBuilder(); builder .append("\r\n ") .append( "
Class NameTest NameStatusTime(s)Error Message
\r\n
") .append("
"); return builder; } // "3 of 4: Capturing test metrics..." public static StringBuilder buildTestMetricsTab(ISuiteResult suiteResult) { StringBuilder builder = new StringBuilder(); // Test Metrics gatherTestInformation(suiteResult, builder,true); return builder; } public static StringBuilder appendClassMetricsHeader() { System.out.println("2 of 4: Capturing class metrics..."); StringBuilder builder = new StringBuilder(); builder .append( "
\r\n

Class Metrics


\r\n") .append( "\r\n\r\n\r\n\r\n") .append( "\r\n\r\n\t\r\n" + "\r\n\r\n\r\n"); return builder; } public static StringBuilder appendClassMetricsFooter() { StringBuilder builder = new StringBuilder(); builder .append("\r\n ") .append( "
Class NameTotalPassedFailedSkippedPass (%)
\r\n
") .append("
"); return builder; } // "2 of 4: Capturing class metrics..." public static StringBuilder buildClassMetrics(ISuiteResult suiteResult) { // CLASS METRICS TAB StringBuilder builder = new StringBuilder(); Set allResults = Utils.extractResults(suiteResult); Map> classMap = Utils.asMap(allResults); for (Entry> each : classMap.entrySet()) { int cTotalSteps = 0; int cPassSteps = 0; int cFailSteps = 0; int cSkipSetps = 0; String fullClassName = each.getKey(); String className = fullClassName.substring(fullClassName.lastIndexOf('.') + 1); builder .append("\r\n") .append( String.format( "%s\r\n", className)); for (ITestResult eachResult : each.getValue()) { if (!eachResult.getMethod().isTest()) { continue; } switch (eachResult.getStatus()) { case ITestResult.SUCCESS: cPassSteps++; break; case ITestResult.FAILURE: cFailSteps++; break; case ITestResult.SKIP: cSkipSetps++; } } cTotalSteps = cPassSteps + cFailSteps + cSkipSetps; float cPassPercentage = (cPassSteps*100)/cTotalSteps; builder .append(String.format("%s\r\n", cTotalSteps)) .append(String.format("%s\r\n", cPassSteps)) .append(String.format("%s\r\n", cFailSteps)) .append(String.format("%s\r\n", cSkipSetps)) .append(String.format("%s\r\n", cPassPercentage)) .append("\r\n "); } return builder; } // "1 of 4: Capturing dashboard statistics..." public static StringBuilder buildDashBoard(ExecutionResults results, String logo) { StringBuilder builder = new StringBuilder(); System.out.println("1 of 4: Capturing dashboard statistics..."); builder .append( "
\r\n
\r\n
\r\n") .append( "\r\n
\r\n
"); // DASHBOARD CONTENT builder .append( "
\r\n
\r\n") .append( "
\r\n") .append( "
Dashboard
\r\n") .append("\r\n
\r\n
\r\n
%s

Total Tests

", results.getTotal())) .append( String.format( "
\r\n \r\n\t", results.getPassed())) .append( String.format( "\r\n\t", results.getFailed())) .append( String.format( "\r\n ", results.getSkipped())) .append( "

\r\n
\r\n
\r\n") .append("Test Status:\r\n
\r\n") .append( "
\r\n
\r\n") .append( "Top 5 Class Failures:\r\n
\r\n") .append( "
\r\n
\r\n
\r\n
\r\n") .append( "Top 10 Test Performance(sec):\r\n
\r\n") .append( "
\r\n\t
\r\n") .append( "Top 10 Config Methods Performance(sec):\r\n
\r\n") .append( "
\r\n
\r\n
\r\n") .append( "

testng-metrics

\r\n
\r\n ") .append(" \r\n
"); return builder; } public static StringBuilder buildViewInfo() { StringBuilder builder = new StringBuilder(); // append html header and title builder .append("\r\n") .append("\r\n
\r\n
\r\n") .append("
\r\n \r\n \r\n
\r\n") .append("

Execution Info

\r\n \r\n") .append("
\r\n \r\n \r\n") .append("
\r\n\t\t\t\r\n\t\t\t\t\r\n\t\t\t\t") .append( String.format( "\r\n\t\t\t\t \r\n\t\t\t\t\t\r\n\t\t\t\t\t\r\n\t\t\t\t",System.getProperty("user.name"))) .append( String.format( "\r\n\t\t\t\t \r\n\t\t\t\t\t\r\n\t\t\t\t\t\r\n\t\t\t\t",System.getProperty("os.name"))) .append( String.format( "\r\n\t\t\t\t \r\n\t\t\t\t\t\r\n\t\t\t\t\t\r\n\t\t\t\t",System.getProperty("java.version"))) .append( String.format( "\r\n\t\t\t\t \r\n\t\t\t\t\t\r\n\t\t\t\t\t\r\n\t\t\t\t",new java.util.Date())) .append("\r\n\t\t\t\t\r\n\t\t\t
Executed By:%s
OS Name:%s
Java Version:%s
Generated Time:%s
\r\n
\r\n") .append("\r\n \r\n
\r\n") .append("\r\n") .append("
\r\n \r\n
\r\n
\r\n
"); return builder; } public static StringBuilder buildHeaderAndTitle() { StringBuilder builder = new StringBuilder(); // append html header and title builder .append("\r\n\r\n \r\n") .append( "\r\n") .append( " TestNG Metrics Report\r\n \r\n \r\n") .append("\r\n") .append( "\r\n") .append( "\r\n") .append( "\r\n") .append( "\r\n") .append( "\r\n \r\n") .append( "\r\n \r\n \r\n") .append( "\r\n") .append( "\r\n") .append( "\r\n") .append( "\r\n") .append( "\r\n") .append( "\r\n") .append( "\r\n") .append( "\r\n") .append( "" + "\r\n\r\n"); builder.append(""); return builder; } private static void gatherTestInformation(ISuiteResult suiteResult, StringBuilder builder, boolean isTest) { Set results = Utils.extractResults(suiteResult); for (ITestResult result : results) { if (isTest) { if (!result.getMethod().isTest()) { continue; } } else { if (result.getMethod().isTest()) { continue; } } String fullClassName = result.getTestClass().getName(); String className = fullClassName.substring(fullClassName.lastIndexOf('.') + 1); String methodName = result.getMethod().getMethodName(); String errorMessage = ""; Object[] testParameters = result.getParameters(); if (testParameters.length > 0 && testParameters != null) { methodName = methodName + " (" + Arrays.toString(testParameters) + ")"; } if (result.getThrowable() != null) { //errorMessage = org.testng.internal.Utils.longStackTrace(result.getThrowable(), false); errorMessage = result.getThrowable().getMessage(); } long duration = result.getEndMillis() - result.getStartMillis(); builder .append("\r\n ") .append( String.format( "%s\r\n", className)) .append( String.format( "%s\r\n", methodName)) .append(String.format("%s\r\n", Utils.getStatusString(result))) .append(String.format("%s\r\n", duration / 1000)) .append( String.format( "%s\r\n", errorMessage)) .append(" \r\n"); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy