17
17
18
18
package org .openqa .selenium .server .htmlrunner ;
19
19
20
+ import com .google .common .base .Function ;
21
+ import com .google .common .collect .FluentIterable ;
22
+
20
23
import org .openqa .selenium .internal .BuildInfo ;
21
24
22
25
import java .io .IOException ;
@@ -35,6 +38,7 @@ public class Results {
35
38
36
39
private final String suiteSource ;
37
40
private final List <String > allTables = new LinkedList <>();
41
+ private final List <Boolean > allResults = new LinkedList <>();
38
42
private final StringBuilder log = new StringBuilder ();
39
43
private final long start = System .currentTimeMillis ();
40
44
@@ -72,12 +76,16 @@ public void addTest(String rawSource, List<CoreTestCase.StepResult> stepResults)
72
76
}
73
77
succeeded &= passed ;
74
78
75
- allTables .add (massage (rawSource , stepResults ));
79
+ allTables .add (
80
+ massage (rawSource , "insert-core-result" , stepResults , input -> input .getRenderableClass ()));
81
+ allResults .add (passed );
76
82
}
77
83
78
- private String massage (
84
+ private < X > String massage (
79
85
String rawSource ,
80
- List <CoreTestCase .StepResult > stepResults ) {
86
+ String toSubstitute ,
87
+ List <X > toConvert ,
88
+ Function <X , String > transform ) {
81
89
82
90
Reader stringReader = new StringReader (rawSource );
83
91
HTMLEditorKit htmlKit = new HTMLEditorKit ();
@@ -86,8 +94,9 @@ private String massage(
86
94
doc .setAsynchronousLoadPriority (-1 );
87
95
ElementCallback callback ;
88
96
try {
89
- final Iterator <CoreTestCase .StepResult > allResults = stepResults .iterator ();
90
- callback = new ElementCallback (allResults );
97
+ callback = new ElementCallback (
98
+ toSubstitute ,
99
+ FluentIterable .from (toConvert ).transform (transform ).iterator ());
91
100
parser .parse (stringReader , callback , true );
92
101
} catch (IOException e ) {
93
102
throw new RuntimeException ("Unable to parse test table" );
@@ -124,18 +133,24 @@ public HTMLTestResults toSuiteResult() {
124
133
String .valueOf (commandPasses ),
125
134
String .valueOf (commandFailures ),
126
135
String .valueOf (commandErrors ),
127
- suiteSource ,
136
+ massage (
137
+ suiteSource ,
138
+ "insert-test-result" ,
139
+ allResults ,
140
+ input -> input ? "status_passed" : "status_failed" ),
128
141
allTables ,
129
142
log .toString ());
130
143
}
131
144
132
145
private static class ElementCallback extends HTMLEditorKit .ParserCallback {
146
+ private final String toSubstitute ;
133
147
private final List <Integer > tagPositions = new LinkedList <>();
134
148
private final List <String > originals = new LinkedList <>();
135
149
private final List <String > substitutions = new LinkedList <>();
136
- private final Iterator <CoreTestCase . StepResult > allResults ;
150
+ private final Iterator <String > allResults ;
137
151
138
- public ElementCallback (Iterator <CoreTestCase .StepResult > allResults ) {
152
+ public ElementCallback (String toSubstitute , Iterator <String > allResults ) {
153
+ this .toSubstitute = toSubstitute ;
139
154
this .allResults = allResults ;
140
155
}
141
156
@@ -145,12 +160,10 @@ public void handleStartTag(HTML.Tag tag, MutableAttributeSet attrs, int pos) {
145
160
Object rawAttr = attrs .getAttribute (HTML .Attribute .CLASS );
146
161
if (rawAttr != null ) {
147
162
String classes = String .valueOf (rawAttr );
148
- if (classes .contains ("insert-core-result" )) {
149
- CoreTestCase . StepResult result = allResults .next ();
163
+ if (classes .contains (toSubstitute )) {
164
+ String result = allResults .next ();
150
165
originals .add (classes );
151
- substitutions .add (classes .replace (
152
- "insert-core-result" ,
153
- result .getRenderableClass ()));
166
+ substitutions .add (classes .replace (toSubstitute , result ));
154
167
tagPositions .add (pos );
155
168
}
156
169
}
0 commit comments