1717
1818package org .openqa .selenium .logging ;
1919
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-
2920import org .junit .jupiter .api .AfterEach ;
3021import org .junit .jupiter .api .Test ;
31- import org .openqa .selenium .By ;
32- import org .openqa .selenium .ImmutableCapabilities ;
3322import org .openqa .selenium .WebDriver ;
34- import org .openqa .selenium .logging .profiler .EventType ;
3523import org .openqa .selenium .testing .Ignore ;
3624import org .openqa .selenium .testing .JupiterTestBase ;
37- import org .openqa .selenium .testing .drivers .WebDriverBuilder ;
3825
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 ;
4231
4332@ Ignore (HTMLUNIT )
4433@ Ignore (IE )
@@ -64,65 +53,7 @@ void testDisabledProfilingDoesNotLog() {
6453 .isEmpty ();
6554 }
6655
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-
12056 private LogEntries getProfilerEntries (WebDriver driver ) {
12157 return driver .manage ().logs ().get (LogType .PROFILER );
12258 }
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- }
12859}
0 commit comments