Skip to content

Commit 0f87cc7

Browse files
fs: add docs
1 parent 1141a7b commit 0f87cc7

14 files changed

Lines changed: 197 additions & 13 deletions

File tree

webtau-docs/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<plugin>
6060
<groupId>org.testingisdocumenting.znai</groupId>
6161
<artifactId>znai-maven-plugin</artifactId>
62-
<version>1.47</version>
62+
<version>1.48</version>
6363
<executions>
6464
<execution>
6565
<id>guide</id>

webtau-docs/znai/getting-started/why.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ Writing end-to-end tests is hard and there are a lot of excuses not write one.
2929
End to end test feedback loop is usually long and slow. Webtau provides [REPL](REPL/experiments) mode to help you
3030
experiment with API and write a test in incremental fashion.
3131

32+
# Utilities
33+
34+
Webtau provides many utility functions to simplify data organization and setup. [Data](utilities/data) module provides
35+
shortcuts to deal with `CSV` and `JSON` based data. [File System](utilities/file-system) module provides shortcuts to
36+
deal with file system related things.
37+
3238
# Documentation Artifacts
3339

3440
I believe that big chunks of a documentation of your product should be automatically generated:

webtau-docs/znai/toc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ cli
5252
utilities
5353
introduction
5454
data
55+
file-system
5556
groovy-standalone-runner
5657
introduction
5758
data-driven-scenarios
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# File Content
2+
3+
:include-file: doc-artifacts/snippets/fsFileContent/createFile.groovy {
4+
title: "write content to a file",
5+
includeRegexp: ["fs\\.writeText"]
6+
}
7+
8+
:include-file: doc-artifacts/snippets/fsFileContent/readFile.groovy {
9+
title: "validate file content",
10+
startLine: "assert-file",
11+
endLine: "assert-file",
12+
excludeStartEnd: true
13+
}
14+
15+
`fs.textContent` declares file content, but doesn't access it right away.
16+
Webtau reads file content when validation happens. Here is an example of waiting on file content:
17+
18+
:include-file: doc-artifacts/snippets/fsFileContent/readFile.groovy {
19+
title: "wait for file content",
20+
startLine: "wait-for-id",
21+
endLine: "wait-for-id",
22+
excludeStartEnd: true
23+
}
24+
25+
Use `.data` to access actual file content for further processing
26+
27+
:include-file: doc-artifacts/snippets/fsFileContent/readFile.groovy {
28+
title: "access file content",
29+
startLine: "actual-file-content",
30+
endLine: "actual-file-content",
31+
excludeStartEnd: true
32+
}
33+
34+
Use `extractByRegexp` to extract content from a file by regular expression
35+
36+
:include-file: doc-artifacts/snippets/fsFileContent/readFile.groovy {
37+
title: "extract file content",
38+
startLine: "extract-id",
39+
endLine: "extract-id",
40+
excludeStartEnd: true,
41+
excludeRegexp: "statusCode"
42+
}
43+
44+
# Copy
45+
46+
:include-file: doc-artifacts/snippets/fsCopy/copyFileToDir.groovy {
47+
title: "copy single file to a directory",
48+
includeRegexp: ["fs\\.copy", "createDir"]
49+
}
50+
51+
:include-file: doc-artifacts/snippets/fsCopy/copyFileToTempDir.groovy {
52+
title: "copy single file to a temp directory",
53+
includeRegexp: ["fs\\.copy", "tempDir"]
54+
}
55+
56+
:include-file: doc-artifacts/snippets/fsCopy/copyFileToFile.groovy {
57+
title: "copy single file to a file",
58+
includeRegexp: ["fs\\.copy"]
59+
}
60+
61+
# Unzip
62+
63+
:include-file: doc-artifacts/snippets/fsArchive/unzip.groovy {
64+
title: "unzip a file"
65+
}
66+
67+
68+
69+
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Webtau has several modules to help you simplify automation processes. All operations in the modules provide
22
detailed information on steps executed and details are included in web report as well as console output.
33

4-
* [data](utilities/data) - module to read structured data like CSV and JSON into data structures like `TableData`, lists and maps
4+
* [data](utilities/data) - module to read structured data like CSV and JSON into data structures like `TableData`, lists and maps
5+
* [file system](utilities/file-system) - module to create files, directories, reading data, unzipping, etc
1.21 KB
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package scenarios.fs
2+
3+
import static org.testingisdocumenting.webtau.WebTauGroovyDsl.*
4+
5+
scenario('unzip') {
6+
def dir = fs.tempDir('for-unzip')
7+
fs.unzip('data/data.zip', dir)
8+
}

webtau-feature-testing/examples/scenarios/fs/copy.groovy

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,21 @@ package scenarios.fs
22

33
import static org.testingisdocumenting.webtau.WebTauGroovyDsl.*
44

5-
scenario('copy file') {
6-
def dir = fs.tempDir('fs-copy')
7-
fs.copy('data/message.txt', dir)
8-
fs.textContent(dir.resolve('message.txt')).should == 'message inside file'
5+
scenario("copy file to temp dir") {
6+
def dir = fs.tempDir("fs-copy")
7+
fs.copy("data/message.txt", dir)
8+
fs.textContent(dir.resolve("message.txt")).should == "message inside file"
9+
}
10+
11+
scenario("copy file to a dir") {
12+
def dir = fs.createDir("my-dir")
13+
fs.copy("data/message.txt", dir)
14+
fs.textContent(dir.resolve("message.txt")).should == "message inside file"
15+
fs.delete(dir)
16+
}
17+
18+
scenario("copy file to a different file") {
19+
fs.copy("data/message.txt", "data/new-message.txt")
20+
fs.textContent("data/new-message.txt").should == "message inside file"
21+
fs.delete("data/new-message.txt")
922
}

webtau-feature-testing/examples/scenarios/fs/files.groovy

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,35 @@ scenario('create and delete file') {
2020
}
2121

2222
scenario('create file using string path') {
23-
def path = fs.writeText('another-test-file.txt', 'hello world')
24-
cfg.workingDir.resolve('another-test-file.txt').toAbsolutePath().toString().should == path.toString()
23+
def path = fs.writeText('my-test-file.txt', 'hello world')
24+
cfg.workingDir.resolve('my-test-file.txt').toAbsolutePath().toString().should == path.toString()
25+
26+
fs.delete(path)
27+
}
28+
29+
scenario('read file using string path') {
30+
def path = fs.writeText('my-test-file.txt', 'hello world\nid=15')
31+
// assert-file
32+
fs.textContent('my-test-file.txt').should == 'hello world\nid=15'
33+
// assert-file
34+
35+
// wait-for-id
36+
def fileTextContent = fs.textContent('my-test-file.txt')
37+
fileTextContent.waitTo contain('id=15')
38+
// wait-for-id
39+
40+
// actual-file-content
41+
def actualFileContent = fileTextContent.data
42+
// actual-file-content
43+
actualFileContent.should == 'hello world\nid=15'
44+
45+
// extract-id
46+
def id = fileTextContent.extractByRegexp("id=(\\d+)")
47+
http.get("/customers/${id}") {
48+
// ...
49+
statusCode.should == 404
50+
}
51+
// extract-id
2552

2653
fs.delete(path)
2754
}

webtau-feature-testing/src/test/groovy/org/testingisdocumenting/webtau/featuretesting/WebTauFileSystemFeaturesTest.groovy

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package org.testingisdocumenting.webtau.featuretesting
1919
import org.junit.BeforeClass
2020
import org.junit.Test
2121

22+
import static org.testingisdocumenting.webtau.featuretesting.FeaturesDocArtifactsExtractor.extractCodeSnippets
23+
2224
class WebTauFileSystemFeaturesTest {
2325
private static WebTauEndToEndTestRunner testRunner
2426

@@ -29,7 +31,7 @@ class WebTauFileSystemFeaturesTest {
2931

3032
@Test
3133
void "files"() {
32-
runCli('files.groovy', 'webtau.cfg.groovy')
34+
runCli('files.groovy', 'webtau.cfg.groovy', "--url=${SpringBootDemoAppUrl.baseUrl}")
3335
}
3436

3537
@Test
@@ -42,6 +44,32 @@ class WebTauFileSystemFeaturesTest {
4244
runCli('dirs.groovy', 'webtau.cfg.groovy')
4345
}
4446

47+
@Test
48+
void "archive"() {
49+
runCli('archive.groovy', 'webtau.cfg.groovy')
50+
}
51+
52+
@Test
53+
void "extract snippets"() {
54+
extractCodeSnippets(
55+
'fsCopy', 'examples/scenarios/fs/copy.groovy', [
56+
'copyFileToTempDir.groovy': 'copy file to temp dir',
57+
'copyFileToDir.groovy': 'copy file to a dir',
58+
'copyFileToFile.groovy': 'copy file to a different file'
59+
])
60+
61+
extractCodeSnippets(
62+
'fsFileContent', 'examples/scenarios/fs/files.groovy', [
63+
'createFile.groovy': 'create file using string path',
64+
'readFile.groovy': 'read file using string path'
65+
])
66+
67+
extractCodeSnippets(
68+
'fsArchive', 'examples/scenarios/fs/archive.groovy', [
69+
'unzip.groovy': 'unzip'
70+
])
71+
}
72+
4573
private static void runCli(String testName, String configFileName, String... additionalArgs) {
4674
testRunner.runCli("scenarios/fs/$testName",
4775
configFileName.isEmpty() ? "" : "scenarios/fs/$configFileName", additionalArgs)

0 commit comments

Comments
 (0)