-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deploying to gh-pages from @ 4079a16 🚀
- Loading branch information
1 parent
1a6472e
commit 1ddbe61
Showing
47 changed files
with
253 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta name="generator" content="Asciidoctor 2.0.18"> | ||
<title>Visualising Executions</title> | ||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700"> | ||
<link rel="stylesheet" href="./asciidoctor.css"> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.css"> | ||
</head> | ||
<body class="article toc2 toc-left"> | ||
<div id="header"> | ||
<div id="toc" class="toc2"> | ||
<div id="toctitle">Table of Contents</div> | ||
<ul class="sectlevel2"> | ||
<li><a href="#_visualising_executions">Visualising Executions</a></li> | ||
</ul> | ||
</div> | ||
</div> | ||
<div id="content"> | ||
<div class="sect2"> | ||
<h3 id="_visualising_executions">Visualising Executions</h3> | ||
<div class="paragraph"> | ||
<p>TestNG allows you to visualise the test method executions via the interface <a href="https://javadoc.io/static/org.testng/testng/7.9.0/org/testng/IExecutionVisualiser.html">IExecutionVisualiser</a>.</p> | ||
</div> | ||
<div class="paragraph"> | ||
<p>TestNG passes metadata about the current execution state in <a href="https://graphviz.org/doc/info/lang.html">dot</a> representation.</p> | ||
</div> | ||
<div class="paragraph"> | ||
<p>Color coding is done as below:</p> | ||
</div> | ||
<div class="ulist"> | ||
<ul> | ||
<li> | ||
<p>tests that are yet to run are colored in <strong>yellow</strong>.</p> | ||
</li> | ||
<li> | ||
<p>tests that are currently running are colored in <strong>green</strong>.</p> | ||
</li> | ||
<li> | ||
<p>tests that have completed execution are colored in <strong>grey</strong>.</p> | ||
</li> | ||
</ul> | ||
</div> | ||
<div class="paragraph"> | ||
<p>This listener should be declared, as explained in the section about <a href="testng_listeners.html">TestNG listeners</a>.</p> | ||
</div> | ||
<div class="paragraph"> | ||
<p>Let’s a sample.</p> | ||
</div> | ||
<div class="sect3"> | ||
<h4 id="_setup">Setup</h4> | ||
<div class="ulist"> | ||
<ul> | ||
<li> | ||
<p>Follow the instructions detailed in <a href="https://graphviz.org/download/">graphviz</a> website to install <code>graphviz</code>. This binary will help us convert the <code>dot</code> format into <code>png</code> files.</p> | ||
</li> | ||
<li> | ||
<p>Add a dependency to a library such as <a href="https://github.com/square/gifencoder/">gifencoder</a> so that we can convert a bunch of <code>png</code> files into a <code>gif</code> file.</p> | ||
</li> | ||
</ul> | ||
</div> | ||
<div class="listingblock"> | ||
<div class="content"> | ||
<pre class="prettyprint highlight"><code data-lang="xml"><dependency> | ||
<groupId>com.squareup</groupId> | ||
<artifactId>gifencoder</artifactId> | ||
<version>0.10.1</version> | ||
</dependency></code></pre> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="sect3"> | ||
<h4 id="_code_sample">Code sample</h4> | ||
<div class="paragraph"> | ||
<p>Here’s how a sample implementation could look like:</p> | ||
</div> | ||
<div class="listingblock"> | ||
<div class="content"> | ||
<pre class="prettyprint highlight"><code data-lang="java">import com.squareup.gifencoder.FloydSteinbergDitherer; | ||
import com.squareup.gifencoder.GifEncoder; | ||
import com.squareup.gifencoder.ImageOptions; | ||
import org.testng.IExecutionVisualiser; | ||
import org.testng.IReporter; | ||
import org.testng.ISuite; | ||
import org.testng.xml.XmlSuite; | ||
|
||
import javax.imageio.ImageIO; | ||
import java.awt.image.BufferedImage; | ||
import java.io.*; | ||
import java.nio.file.*; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class SampleVisualiser implements IExecutionVisualiser, IReporter { | ||
|
||
private final AtomicInteger counter = new AtomicInteger(1); | ||
private final Path tmpdir; | ||
|
||
private final List<String> pngFiles = new ArrayList<>(); | ||
|
||
public SampleVisualiser() throws IOException { | ||
tmpdir = Files.createTempDirectory(Paths.get("target"), "dot-"); | ||
} | ||
|
||
@Override | ||
public void consumeDotDefinition(String dotDefinition) { | ||
String filePrefix = counter.getAndIncrement() + "-" + UUID.randomUUID(); | ||
Path input = Path.of(tmpdir.toFile().getAbsolutePath(), filePrefix + "-input.dot"); | ||
try { | ||
Files.writeString(input, dotDefinition); | ||
Path output = Path.of(tmpdir.toFile().getAbsolutePath(), filePrefix + "-output.png"); | ||
if (generatePngFileFromDotContent(input, output)) { | ||
pngFiles.add(output.toFile().getAbsolutePath()); | ||
} | ||
} catch (IOException | InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) { | ||
//The GIF image will be created with file name "animation.gif" | ||
File writeTo = new File(tmpdir.toFile().getAbsolutePath(), "animation.gif"); | ||
try (FileOutputStream outputStream = new FileOutputStream(writeTo)) { | ||
ImageOptions options = new ImageOptions(); | ||
|
||
//Set 500ms between each frame | ||
options.setDelay(500, TimeUnit.MILLISECONDS); | ||
//Use Floyd Steinberg dithering as it yields the best quality | ||
options.setDitherer(FloydSteinbergDitherer.INSTANCE); | ||
GifEncoder encoder = new GifEncoder(outputStream, 1600, 1200, 0); | ||
for (String pngFile : pngFiles) { | ||
encoder.addImage(convertImageToArray(new File(pngFile)), options); | ||
} | ||
encoder.finishEncoding(); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
System.err.println("The gif has been generated in :" + writeTo.getAbsolutePath()); | ||
} | ||
|
||
private int[][] convertImageToArray(File file) throws IOException { | ||
BufferedImage bufferedImage = ImageIO.read(file); | ||
int[][] rgbArray = new int[bufferedImage.getHeight()][bufferedImage.getWidth()]; | ||
for (int i = 0; i < bufferedImage.getHeight(); i++) { | ||
for (int j = 0; j < bufferedImage.getWidth(); j++) { | ||
rgbArray[i][j] = bufferedImage.getRGB(j, i); | ||
} | ||
} | ||
return rgbArray; | ||
} | ||
|
||
private static boolean generatePngFileFromDotContent(Path input, Path output) throws IOException, InterruptedException { | ||
String[] cmds = { | ||
"dot", | ||
"-Tpng", | ||
input.toFile().getAbsolutePath(), | ||
"-o", | ||
output.toFile().getAbsolutePath() | ||
}; | ||
Process process = new ProcessBuilder().command(cmds).start(); | ||
handleInputErrorFrom(process); | ||
int exitCode = process.waitFor(); | ||
System.err.println("PNG file written to " + output.toFile().getAbsolutePath()); | ||
return exitCode == 0; | ||
} | ||
|
||
private static void handleInputErrorFrom(Process process) throws IOException { | ||
processStream(process.getInputStream()); | ||
processStream(process.getErrorStream()); | ||
} | ||
|
||
private static void processStream(InputStream stream) throws IOException { | ||
if (stream == null) { | ||
return; | ||
} | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); | ||
|
||
String line; | ||
while ((line = reader.readLine()) != null) { | ||
System.out.println(line); | ||
} | ||
} | ||
}</code></pre> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div id="footer"> | ||
<div id="footer-text"> | ||
Last updated 2024-01-23 05:18:21 UTC | ||
</div> | ||
</div> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/run_prettify.min.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.