Skip to content

Commit

Permalink
Merge pull request #5 from OndraM/feature/embedd-xsl
Browse files Browse the repository at this point in the history
Embed XSL into results XML file to overcome same origin policy problems
  • Loading branch information
OndraM committed May 13, 2015
2 parents 99c33f9 + 25d73a4 commit 28b62bd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<!-- There is always Unreleased section on the top. Subsections (Added, Changed, Fixed, Removed) should be added as needed. -->

## Unreleased
- Nothing yet.
### Changed
- The `logs/results.xml` could now be also accessed locally (the XSLT is now embedded right into the file, so we don't encounter same-origin policy problems).

## 1.0.0 - 2015-05-09
### Added
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ The log is printed to the console where you run the `run-tests` command. But thi

So for each testcase there is separate file in JUnit XML format, placed in `logs/` directory. Also screenshots and HTML snapsnots are saved into this directory (they are automatically generated on failed assertion or if some WebDriver command fails).

During the tests execution check file `logs/results.xml` (you must access it through webserver, as the XSLT won't work and you will see plain XML) to see current status of tests.

During the tests execution check file `logs/results.xml` to see current status of tests:
![Example output as displayed in logs/results.xml file](https://lmc-eu.github.io/steward/images/results-output-example.png)

## License
Expand Down
26 changes: 18 additions & 8 deletions src/Publisher/XmlPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,16 @@ protected function readAndLock()
throw new \RuntimeException(sprintf('Cannot obtain lock for file "%s"', $file));
}

if (fstat($this->fileHandle)['size'] == 0) { // new or empty file, create empty xml element
$xslPath = '../src/results.xsl';
if (is_readable($fileDir . '/../vendor/lmc/steward/src/results.xsl')) {
$xslPath = '../vendor/lmc/steward/src/results.xsl';
}

if (fstat($this->fileHandle)['size'] == 0) { // new or empty file => create empty xml element and add stylesheet
$xml = new \SimpleXMLElement(
'<?xml version="1.0" encoding="utf-8" ?>'
. '<?xml-stylesheet type="text/xsl" href="' . $xslPath . '"?>'
. '<testcases />'
. '<?xml-stylesheet type="text/xsl" href="#stylesheet"?>'
. '<!DOCTYPE testcases [<!ATTLIST xsl:stylesheet id ID #REQUIRED>]>'
. '<testcases>'
. $this->getStylesheet()
. '</testcases>'
);

} else { // file already exists, load current xml
$fileContents = fread($this->fileHandle, fstat($this->fileHandle)['size']);
$xml = simplexml_load_string($fileContents);
Expand Down Expand Up @@ -263,4 +262,15 @@ protected function writeAndUnlock(\SimpleXMLElement $xml)
fclose($this->fileHandle);
$this->fileHandle = null;
}

/**
* @return string
*/
private function getStylesheet()
{
$xslPath = __DIR__ . '/../results.xsl';
$xsl = file_get_contents($xslPath);

return $xsl;
}
}
15 changes: 9 additions & 6 deletions src/results.xsl
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="stylesheet">

<xsl:output method="xml" doctype-system="about:legacy-compat" indent="yes" encoding="UTF-8"/>

<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Steward results</title>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
</head>
<body>
<div class="container">
Expand Down Expand Up @@ -108,7 +107,7 @@
</tr>
</thead>
<tbody>
<xsl:for-each select="/testcases/testcase">
<xsl:for-each select="//testcases/testcase">
<tr class="testcase-row">
<td colspan="2">
<xsl:value-of select="@name"/>
Expand Down Expand Up @@ -198,8 +197,8 @@
</tbody>
</table>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.3/moment.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.3/moment.min.js"></script>
<script>
<![CDATA[
$(function () {
Expand Down Expand Up @@ -234,4 +233,8 @@
</html>
</xsl:template>

<xsl:template match="xsl:stylesheet">
<!-- ignore the stylesheet from being processed -->
</xsl:template>

</xsl:stylesheet>

0 comments on commit 28b62bd

Please sign in to comment.