2222import org .junit .jupiter .api .Test ;
2323import org .openqa .selenium .By ;
2424import org .openqa .selenium .devtools .events .ConsoleEvent ;
25+ import org .openqa .selenium .devtools .idealized .runtime .model .RemoteObject ;
2526import org .openqa .selenium .environment .webserver .Page ;
2627import org .openqa .selenium .testing .Ignore ;
2728
29+ import java .util .List ;
2830import java .util .concurrent .CompletableFuture ;
2931import java .util .concurrent .ExecutionException ;
3032import java .util .concurrent .TimeUnit ;
3335class ConsoleEventsTest extends DevToolsTestBase {
3436
3537 @ Test
36- @ Ignore (gitHubActions = true )
3738 public void canWatchConsoleEvents () throws InterruptedException , ExecutionException , TimeoutException {
3839 String page = appServer .create (
3940 new Page ()
@@ -50,4 +51,23 @@ public void canWatchConsoleEvents() throws InterruptedException, ExecutionExcept
5051 assertThat (event .getMessages ()).containsExactly ("Hello, world!" );
5152 }
5253
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+
5373}
0 commit comments