22
22
import org .junit .jupiter .api .Test ;
23
23
import org .openqa .selenium .By ;
24
24
import org .openqa .selenium .devtools .events .ConsoleEvent ;
25
+ import org .openqa .selenium .devtools .idealized .runtime .model .RemoteObject ;
25
26
import org .openqa .selenium .environment .webserver .Page ;
26
27
import org .openqa .selenium .testing .Ignore ;
27
28
29
+ import java .util .List ;
28
30
import java .util .concurrent .CompletableFuture ;
29
31
import java .util .concurrent .ExecutionException ;
30
32
import java .util .concurrent .TimeUnit ;
33
35
class ConsoleEventsTest extends DevToolsTestBase {
34
36
35
37
@ Test
36
- @ Ignore (gitHubActions = true )
37
38
public void canWatchConsoleEvents () throws InterruptedException , ExecutionException , TimeoutException {
38
39
String page = appServer .create (
39
40
new Page ()
@@ -50,4 +51,23 @@ public void canWatchConsoleEvents() throws InterruptedException, ExecutionExcept
50
51
assertThat (event .getMessages ()).containsExactly ("Hello, world!" );
51
52
}
52
53
54
+ @ Test
55
+ public void canWatchConsoleEventsWithArgs () throws InterruptedException , ExecutionException , TimeoutException {
56
+ String page = appServer .create (
57
+ new Page ()
58
+ .withBody ("<div id='button' onclick='helloWorld()'>click me</div>" )
59
+ .withScripts ("function helloWorld() { console.log(\" array\" , [1, 2, 3]) }" ));
60
+ driver .get (page );
61
+
62
+ CompletableFuture <ConsoleEvent > future = new CompletableFuture <>();
63
+ devTools .getDomains ().events ().addConsoleListener (future ::complete );
64
+ driver .findElement (By .id ("button" )).click ();
65
+ ConsoleEvent event = future .get (5 , TimeUnit .SECONDS );
66
+
67
+ assertThat (event .getType ()).isEqualTo ("log" );
68
+ List <Object > args = event .getArgs ();
69
+ // Ensure args returned by CDP protocol are maintained
70
+ assertThat (args ).isNotInstanceOf ((RemoteObject .class ));
71
+ }
72
+
53
73
}
0 commit comments