Skip to content

Commit d43d4fc

Browse files
add custom report generator extension point. report doc updates. (#64)
1 parent 10c5da1 commit d43d4fc

File tree

23 files changed

+358
-71
lines changed

23 files changed

+358
-71
lines changed

webtau-docs/webtau/REST/headers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Standard headers like `Content-Type` and `Accept` are set on your behalf.
44
When payload content is present then values are based on the content type you are sending.
5-
When no palyload is present, it defaults to `application/json`.
5+
When no payload is present, it defaults to `application/json`.
66

77
# Common Header
88

webtau-docs/webtau/REST/report.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Location
2+
3+
By default report is generated at `<workingdir>/webtau.report.html`. To change the location use `--reportPath` option.
4+
5+
# Summary
6+
7+
Out of the box report provides high level information like number of failed tests and HTTP Operations coverage.
8+
9+
:include-image: img/rest-report-summary.png {fit: true}
10+
11+
# Navigation
12+
13+
Report is a self contained single page application.
14+
Url tracks your navigation through screens, so you can share url with your teammates to narrow down a problem.
15+
16+
# Additional Reports
17+
18+
To generate custom reports, or upload report data to your server, specify `reportGenerator` config property.
19+
20+
:include-file: examples/rest/report/webtau.cfg {title: "webtau.cfg"}
21+
22+
Where `Report.&generateReport` is implemented as following
23+
24+
:include-file: examples/rest/report/Report.groovy {title: "rest/report/Report.groovy"}
25+
148 KB
Loading

webtau-docs/webtau/toc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ REST
88
documentation
99
complex-types
1010
openAPI-spec
11+
report
1112
matchers
1213
UI
1314
configuration
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package rest.report
2+
3+
import com.twosigma.webtau.console.ConsoleOutputs
4+
import com.twosigma.webtau.console.ansi.Color
5+
import com.twosigma.webtau.report.ReportTestEntries
6+
7+
import static com.twosigma.webtau.WebTauDsl.cfg
8+
9+
class Report {
10+
static void generateReport(ReportTestEntries entries) {
11+
def reportPath = cfg.workingDir.resolve('report.txt')
12+
13+
ConsoleOutputs.out('generating report: ', Color.PURPLE, reportPath)
14+
reportPath.toFile().text = entries.size()
15+
}
16+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2018 TWO SIGMA OPEN SOURCE, LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package rest.report
18+
19+
import static com.twosigma.webtau.WebTauGroovyDsl.scenario
20+
21+
scenario("no op") {
22+
23+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import rest.report.Report
2+
3+
url = "http://localhost:8080"
4+
5+
reportGenerator = Report.&generateReport

webtau-groovy/src/main/groovy/com/twosigma/webtau/cfg/WebTauGroovyFileConfigHandler.groovy

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package com.twosigma.webtau.cfg
1818

1919
import com.twosigma.webtau.console.ConsoleOutputs
2020
import com.twosigma.webtau.console.ansi.Color
21+
import com.twosigma.webtau.report.ReportGenerator
22+
import com.twosigma.webtau.report.ReportGenerators
2123

2224
import java.nio.file.Files
2325
import java.nio.file.Path
@@ -45,24 +47,34 @@ class WebTauGroovyFileConfigHandler implements WebTauConfigHandler {
4547
def parsedConfig = configSlurper.parse(configScript)
4648
cfg.acceptConfigValues("config file", parsedConfig.flatten())
4749

50+
if (!parsedConfig) {
51+
return
52+
}
53+
4854
def headerProvider = httpHeaderProvider(parsedConfig)
4955
if (headerProvider) {
50-
// we cannot add configuration here since most likely config setup will be triggered
56+
// we cannot add configuration here using HttpConfigurations.add since most likely config setup will be triggered
5157
// as part of the first cfg value access (e.g. baseUrl lookup).
5258
// to lookup base url webtau loops through registered handlers, adding new handlers will cause
5359
// loop exception.
5460
// so we register GroovyConfigBasedHttpConfiguration via service loaded,
5561
// and adding actual header provider now
5662
GroovyConfigBasedHttpConfiguration.setHeaderProvider(headerProvider)
5763
}
58-
}
5964

60-
private static Closure httpHeaderProvider(parsedConfig) {
61-
if (!parsedConfig) {
62-
return null
65+
def reportGenerator = reportGenerator(parsedConfig)
66+
if (reportGenerator) {
67+
ReportGenerators.add(reportGenerator)
6368
}
69+
}
6470

71+
private static Closure httpHeaderProvider(parsedConfig) {
6572
def provider = parsedConfig.get("httpHeaderProvider")
6673
return provider ? provider as Closure : null
6774
}
75+
76+
private static ReportGenerator reportGenerator(parsedConfig) {
77+
def generator = parsedConfig.get("reportGenerator")
78+
return generator ? generator as ReportGenerator : null
79+
}
6880
}

webtau-groovy/src/main/groovy/com/twosigma/webtau/cli/WebTauCliApp.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import com.twosigma.webtau.console.ConsoleOutput
2525
import com.twosigma.webtau.console.ConsoleOutputs
2626
import com.twosigma.webtau.console.ansi.AnsiConsoleOutput
2727
import com.twosigma.webtau.driver.WebDriverCreator
28-
import com.twosigma.webtau.report.HtmlReportGenerator
28+
import com.twosigma.webtau.report.ReportGenerators
29+
import com.twosigma.webtau.report.ReportTestEntries
2930
import com.twosigma.webtau.reporter.ConsoleStepReporter
3031
import com.twosigma.webtau.reporter.IntegrationTestsMessageBuilder
3132
import com.twosigma.webtau.reporter.ScreenshotStepReporter
@@ -130,7 +131,7 @@ class WebTauCliApp implements StandaloneTestListener {
130131

131132
@Override
132133
void afterAllTests() {
133-
HtmlReportGenerator.generateAndCreateFile(tests.reportTestEntry)
134+
ReportGenerators.generate(new ReportTestEntries(tests.reportTestEntry))
134135
problemCount = consoleTestReporter.failed + consoleTestReporter.errored + consoleTestReporter.skipped
135136
}
136137
}

webtau-groovy/src/test/groovy/com/twosigma/webtau/cfg/WebTauGroovyFileConfigHandlerTest.groovy

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,55 @@
1616

1717
package com.twosigma.webtau.cfg
1818

19+
import com.twosigma.webtau.report.ReportGenerators
20+
import com.twosigma.webtau.report.ReportTestEntries
1921
import org.junit.Test
2022

23+
import static com.twosigma.webtau.Ddjt.code
24+
import static com.twosigma.webtau.Ddjt.throwException
25+
2126
class WebTauGroovyFileConfigHandlerTest {
2227
@Test
2328
void "should use default environment values when env is not specified"() {
2429
def cfg = createConfig()
30+
handle(cfg)
2531

26-
def handler = new WebTauGroovyFileConfigHandler()
27-
handler.onAfterCreate(cfg)
28-
29-
cfg.baseUrl.should == "http://localhost:8180"
32+
cfg.baseUrl.should == 'http://localhost:8180'
3033
}
3134

3235
@Test
3336
void "should use environment specific values when env is specified"() {
3437
def cfg = createConfig()
35-
cfg.envConfigValue.set("test", "dev")
38+
cfg.envConfigValue.set('test', 'dev')
3639

40+
handle(cfg)
41+
42+
cfg.baseUrl.should == 'http://dev.host:8080'
43+
}
44+
45+
@Test
46+
void "should let specify custom reporter"() {
47+
def cfg = createConfig()
48+
cfg.envConfigValue.set('test', 'prod')
49+
50+
handle(cfg)
51+
52+
cfg.reportPath.toFile().deleteOnExit()
53+
54+
// prod report throws exception on purpose
55+
code {
56+
ReportGenerators.generate(new ReportTestEntries())
57+
} should throwException('report issue 0')
58+
}
59+
60+
private static void handle(WebTauConfig cfg) {
3761
def handler = new WebTauGroovyFileConfigHandler()
3862
handler.onAfterCreate(cfg)
39-
40-
cfg.baseUrl.should == "http://dev.host:8080"
4163
}
4264

4365
private static WebTauConfig createConfig() {
4466
def cfg = new WebTauConfig()
45-
cfg.configFileName.set("test", "src/test/resources/webtau.cfg")
67+
cfg.configFileName.set('test', 'src/test/resources/webtau.cfg')
4668

4769
return cfg
4870
}

0 commit comments

Comments
 (0)