17
17
18
18
package org .openqa .selenium .logging ;
19
19
20
- import static org .assertj .core .api .Assertions .assertThat ;
21
- import static org .openqa .selenium .remote .CapabilityType .ENABLE_PROFILING_CAPABILITY ;
22
- import static org .openqa .selenium .testing .drivers .Browser .CHROME ;
23
- import static org .openqa .selenium .testing .drivers .Browser .EDGE ;
24
- import static org .openqa .selenium .testing .drivers .Browser .HTMLUNIT ;
25
- import static org .openqa .selenium .testing .drivers .Browser .IE ;
26
- import static org .openqa .selenium .testing .drivers .Browser .FIREFOX ;
27
- import static org .openqa .selenium .testing .drivers .Browser .SAFARI ;
28
-
29
20
import org .junit .jupiter .api .AfterEach ;
30
21
import org .junit .jupiter .api .Test ;
31
- import org .openqa .selenium .By ;
32
- import org .openqa .selenium .ImmutableCapabilities ;
33
22
import org .openqa .selenium .WebDriver ;
34
- import org .openqa .selenium .logging .profiler .EventType ;
35
23
import org .openqa .selenium .testing .Ignore ;
36
24
import org .openqa .selenium .testing .JupiterTestBase ;
37
- import org .openqa .selenium .testing .drivers .WebDriverBuilder ;
38
25
39
- import java .util .List ;
40
- import java .util .stream .Collectors ;
41
- import java .util .stream .StreamSupport ;
26
+ import static org .assertj .core .api .Assertions .assertThat ;
27
+ import static org .openqa .selenium .testing .drivers .Browser .FIREFOX ;
28
+ import static org .openqa .selenium .testing .drivers .Browser .HTMLUNIT ;
29
+ import static org .openqa .selenium .testing .drivers .Browser .IE ;
30
+ import static org .openqa .selenium .testing .drivers .Browser .SAFARI ;
42
31
43
32
@ Ignore (HTMLUNIT )
44
33
@ Ignore (IE )
@@ -64,65 +53,7 @@ void testDisabledProfilingDoesNotLog() {
64
53
.isEmpty ();
65
54
}
66
55
67
- @ Test
68
- void testLogsSingleHttpCommand () {
69
- startLoggingDriver ();
70
- List <LogEntry > entries = getProfilerEntriesOfType (getProfilerEntries (loggingDriver ),
71
- EventType .HTTP_COMMAND );
72
- // Expect start of newSession, end of newSession, start of getLogs, end of getLogs
73
- String [] expected = {"\" command\" : \" newSession\" ,\" startorend\" : \" start\" " ,
74
- "\" command\" : \" newSession\" ,\" startorend\" : \" end\" " ,
75
- "\" command\" : \" getLog\" ,\" startorend\" : \" start\" " ,
76
- "\" command\" : \" getLog\" ,\" startorend\" : \" end\" " };
77
- assertThat (containsExpectedEntries (entries , expected )).isTrue ();
78
- }
79
-
80
- /**
81
- * Checks if the given list of strings occur in the given order among the
82
- * given log messages (one string per message).
83
- *
84
- * @param entries The list of log entries.
85
- * @param expected The array of expected strings.
86
- * @return true if a match was found for all expected strings, otherwise false.
87
- */
88
- private boolean containsExpectedEntries (List <LogEntry > entries , String [] expected ) {
89
- int index = 0 ;
90
- for (LogEntry entry : entries ) {
91
- if (index == expected .length ) {
92
- return true ;
93
- }
94
- if (!entry .getMessage ().contains (expected [index ])) {
95
- index ++;
96
- }
97
- }
98
- return (index == expected .length );
99
- }
100
-
101
- @ Test
102
- @ Ignore (CHROME )
103
- @ Ignore (EDGE )
104
- public void testGetsYieldToPageLoadLogEntries () {
105
- startLoggingDriver ();
106
- loggingDriver .get (pages .formPage );
107
- loggingDriver .findElement (By .id ("submitButton" )).click ();
108
- assertThat (
109
- getProfilerEntriesOfType (getProfilerEntries (loggingDriver ), EventType .YIELD_TO_PAGE_LOAD ).size ())
110
- .isPositive ();
111
- }
112
-
113
- private void startLoggingDriver () {
114
- if (loggingDriver == null ) {
115
- loggingDriver = new WebDriverBuilder ()
116
- .get (new ImmutableCapabilities (ENABLE_PROFILING_CAPABILITY , true ));
117
- }
118
- }
119
-
120
56
private LogEntries getProfilerEntries (WebDriver driver ) {
121
57
return driver .manage ().logs ().get (LogType .PROFILER );
122
58
}
123
-
124
- private List <LogEntry > getProfilerEntriesOfType (LogEntries entries , EventType eventType ) {
125
- return StreamSupport .stream (entries .spliterator (), false ).filter (
126
- entry -> entry .getMessage ().contains (eventType .toString ())).collect (Collectors .toList ());
127
- }
128
59
}
0 commit comments