Skip to content

Commit

Permalink
move tests produced doc-artifacts to target (#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
MykolaGolubyev committed Aug 23, 2019
1 parent 5457c95 commit 4ad3019
Show file tree
Hide file tree
Showing 31 changed files with 108 additions and 154 deletions.
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,3 @@ webtau-report-*.html
*-webtau-report.html
.webtau.cache.json
.vertx
webtau-http-groovy/doc-artifacts/*
webtau-feature-testing/doc-artifacts/*
webtau-feature-testing/examples/doc-artifacts/*
webtau-groovy/doc-artifacts/*
webtau-http/doc-artifacts/*
webtau-cli/doc-artifacts/*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ scenario("search by specific query") {

## Precise Reporting

![report-image](webtau-report-testing/src/test/groovy/doc-artifacts/reports/report-http-calls.png)
![report-image](report-crud-separated-http-calls.png)

[Full Documentation](https://opensource.twosigma.com/webtau/guide/)
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@
<module>webtau-testapp</module>
<module>webtau-config</module>
<module>webtau-feature-testing</module>
<module>webtau-report-testing</module>
<module>webtau-cli-testing</module>
<module>webtau-docs</module>
<module>webtau-maven-plugin</module>
<module>webtau-maven-plugin-test</module>
<module>webtau-maven-plugin-test-skip</module>
<module>webtau-report-testing</module>
<module>webtau-shaded</module>
<module>webtau-dist</module>
<module>webtau</module>
Expand Down
Binary file added report-crud-separated-http-calls.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions webtau-cli/src/test/java/com/twosigma/webtau/cli/CliJavaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import com.twosigma.webtau.documentation.DocumentationArtifactsLocation;
import com.twosigma.webtau.utils.FileUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import java.nio.file.Files;
Expand All @@ -29,6 +31,20 @@
import static com.twosigma.webtau.cli.CliTestUtils.nixOnly;

public class CliJavaTest {
private static Path existingDocRoot;

@BeforeClass
public static void init() {
existingDocRoot = DocumentationArtifactsLocation.getRoot();
DocumentationArtifactsLocation.setRoot(
DocumentationArtifactsLocation.classBasedLocation(CliJavaTest.class).resolve("doc-artifacts"));
}

@AfterClass
public static void clean() {
DocumentationArtifactsLocation.setRoot(existingDocRoot);
}

@Test
public void outputOnlyValidation() {
cli.run("ls -l", (output, error) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,11 @@

import com.twosigma.webtau.utils.FileUtils;

import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;

public class DocumentationArtifacts {
public static void create(Class testClass, String artifactName, String textContent) {
try {
Path path = Paths.get(testClass.getProtectionDomain().getCodeSource().getLocation().toURI())
.resolve(artifactName);
FileUtils.writeTextContent(path, textContent);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
Path path = DocumentationArtifactsLocation.classBasedLocation(testClass).resolve(artifactName);
FileUtils.writeTextContent(path, textContent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.twosigma.webtau.documentation;

import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.atomic.AtomicReference;
Expand All @@ -27,10 +28,22 @@ public static void setRoot(Path newRoot) {
root.set(newRoot);
}

public static Path getRoot() {
return root.get();
}

public static Path resolve(String artifactName) {
return root.get().resolve(artifactName);
}

public static Path classBasedLocation(Class<?> testClass) {
try {
return Paths.get(testClass.getProtectionDomain().getCodeSource().getLocation().toURI());
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}

private static Path getInitialRoot() {
String property = System.getProperty("documentation.artifacts.root");
return property == null ? Paths.get("doc-artifacts") : Paths.get(property);
Expand Down
10 changes: 5 additions & 5 deletions webtau-docs/webtau/UI/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ To capture screenshots use `browser.doc[.withAnnotations].capture`:

The result of the `capture` command is two files: actual screenshot and `annotations.json`.

:include-file: doc-artifacts/ui/search.json {title: "search.json"}
:include-file: doc-artifacts/search.json {title: "search.json"}

[Webtau](https://github.com/twosigma/webtau) documentation site is generated using [Znai](https://github.com/twosigma/znai).
[Znai](https://github.com/twosigma/znai) has `include-image` plugin that supports annotations format generated by `capture` command.

:include-image: doc-artifacts/ui/search.png {fit: true, annotationsPath: "doc-artifacts/ui/search.json"}
:include-image: doc-artifacts/search.png {fit: true, annotationsPath: "doc-artifacts/search.json"}

:include-image: doc-artifacts/ui/search.png {annotationsPath: "doc-artifacts/ui/search.json"}
:include-image: doc-artifacts/search.png {annotationsPath: "doc-artifacts/search.json"}

# Annotation Types

:include-file: doc-artifacts/snippets/doc-capture/captureBadges.groovy {title: "badges"}
:include-image: doc-artifacts/ui/search.png {annotationsPath: "doc-artifacts/ui/search.json"}
:include-image: doc-artifacts/search.png {annotationsPath: "doc-artifacts/search.json"}

:include-file: doc-artifacts/snippets/doc-capture/captureHighlightCover.groovy {title: "cover and highlight"}
:include-image: doc-artifacts/ui/search-highlight-cover.png {annotationsPath: "doc-artifacts/ui/search-highlight-cover.json"}
:include-image: doc-artifacts/search-highlight-cover.png {annotationsPath: "doc-artifacts/search-highlight-cover.json"}
5 changes: 5 additions & 0 deletions webtau-docs/webtau/lookup-paths
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
../../webtau-groovy/
../../webtau-groovy/src/main/groovy
../../webtau-groovy/src/main/resources
../../webtau-groovy/target/test-classes
../../webtau-feature-testing
../../webtau-feature-testing/examples
../../webtau-feature-testing/target/classes
../../webtau-http/
../../webtau-http/target/test-classes
../../webtau-http-groovy/
../../webtau-http-groovy/target/test-classes
../../webtau-browser/src/main/java
../../webtau-browser/src/test/groovy
../../webtau-browser/src/test/resources
Expand All @@ -25,4 +29,5 @@
../../webtau-junit5-examples/src/test/groovy
../../webtau-junit5-examples/src/test/java
../../webtau-report-testing/src/test/groovy
../../webtau-report-testing/target
../target/classes
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
url = "http://localhost:8080"

docPath = "doc-artifacts"
url = "http://localhost:8080"
10 changes: 0 additions & 10 deletions webtau-feature-testing/examples/scenarios/ui/byNumber.groovy

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package com.twosigma.webtau.featuretesting

import com.twosigma.webtau.documentation.DocumentationArtifactsLocation
import com.twosigma.webtau.utils.FileUtils
import com.twosigma.webtau.utils.ResourceUtils
import com.twosigma.webtau.utils.StringUtils
Expand All @@ -58,8 +59,8 @@ class FeaturesDocArtifactsExtractor {
return StringUtils.stripIndentation(removeMarkedLines(script.substring(scopeStartIdx + 1, scopeEndIdx)))
}

static void extractCodeSnippets(String extractedPath, String inputName, Map<String, String> scenarioToOutputFile) {
def artifactsRoot = Paths.get(extractedPath)
static void extractCodeSnippets(String artifactName, String inputName, Map<String, String> scenarioToOutputFile) {
def artifactsRoot = artifactsRoot(artifactName)

def script = FileUtils.fileTextContent(Paths.get(inputName))

Expand All @@ -69,12 +70,26 @@ class FeaturesDocArtifactsExtractor {
}
}

static String extractHtml(String resourceName, String css) {
static void extractHtmlSnippets(String artifactName, String resourceName, Map<String, String> cssToOutputFile) {
def artifactsRoot = artifactsRoot(artifactName)

cssToOutputFile.each { outputFileName, css ->
extractAndSaveHtml(resourceName, css,
artifactsRoot.resolve(outputFileName))
}
}

private static Path artifactsRoot(String artifactName) {
DocumentationArtifactsLocation.classBasedLocation(FeaturesDocArtifactsExtractor).
resolve('doc-artifacts').resolve('snippets').resolve(artifactName)
}

private static String extractHtml(String resourceName, String css) {
def html = ResourceUtils.textContent(resourceName)
return Jsoup.parse(html).select(css).html().toString()
}

static void extractAndSaveHtml(String resourceName, String css, Path outputPath) {
private static void extractAndSaveHtml(String resourceName, String css, Path outputPath) {
def html = extractHtml(resourceName, css)
FileUtils.writeTextContent(outputPath, html)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,15 @@ package com.twosigma.webtau.featuretesting

import com.twosigma.webtau.cfg.WebTauConfig
import com.twosigma.webtau.cli.WebTauCliApp
import com.twosigma.webtau.console.ConsoleOutputs
import com.twosigma.webtau.console.ansi.Color
import com.twosigma.webtau.expectation.ActualPath
import com.twosigma.webtau.expectation.equality.CompareToComparator
import com.twosigma.webtau.documentation.DocumentationArtifactsLocation
import com.twosigma.webtau.http.testserver.TestServer
import com.twosigma.webtau.reporter.StepReporter
import com.twosigma.webtau.reporter.StepReporters
import com.twosigma.webtau.reporter.TestStep
import com.twosigma.webtau.runner.standalone.StandaloneTest
import com.twosigma.webtau.runner.standalone.StandaloneTestListener
import com.twosigma.webtau.runner.standalone.StandaloneTestListeners
import com.twosigma.webtau.utils.FileUtils
import com.twosigma.webtau.utils.JsonUtils

import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths

Expand Down Expand Up @@ -62,15 +56,15 @@ class WebTauEndToEndTestRunner implements StepReporter, StandaloneTestListener {
StepReporters.add(this)
StandaloneTestListeners.add(this)

def reportPath = 'examples/'
if (testFileName.endsWith('.groovy')) {
reportPath += testFileName.replace('.groovy', '-webtau-report.html')
} else {
reportPath += testFileName + '/webtau-report.html'
}
def targetClassesLocation = DocumentationArtifactsLocation.classBasedLocation(WebTauEndToEndTestRunner)
def reportPath = targetClassesLocation
.resolve(testFileName.endsWith('.groovy') ?
testFileName.replace('.groovy', '-webtau-report.html'):
testFileName + '/webtau-report.html')

try {
def args = ['--workingDir=examples', '--config=' + configFileName,
'--docPath=' + targetClassesLocation.resolve('doc-artifacts'),
'--reportPath=' + reportPath]
args.addAll(Arrays.asList(additionalArgs))
args.add(testPath.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ class WebTauRestFeaturesTest {

@Test
void "schema validation extract snippets"() {
def root = 'doc-artifacts/snippets/json-schema'

extractCodeSnippets(
root, 'examples/scenarios/rest/jsonSchema/validateSchema.groovy', [
'json-schema', 'examples/scenarios/rest/jsonSchema/validateSchema.groovy', [
'validateBody.groovy': 'valid schema',
'validateField.groovy': 'validate specific field',
])
Expand All @@ -86,10 +84,8 @@ class WebTauRestFeaturesTest {

@Test
void "open api extract snippets"() {
def root = 'doc-artifacts/snippets/openapi'

extractCodeSnippets(
root, 'examples/scenarios/rest/openapi/disableOpenApiValidation.groovy', [
'openapi', 'examples/scenarios/rest/openapi/disableOpenApiValidation.groovy', [
'disableAll.groovy': 'disable all validation',
'disableRequest.groovy': 'disable request validation',
'disableResponse.groovy': 'disable response validation',
Expand Down
Loading

0 comments on commit 4ad3019

Please sign in to comment.