@@ -25,6 +25,20 @@ module WebDriver
25
25
only : { browser : %i[ chrome edge firefox ] } do
26
26
after { |example | reset_driver! ( example : example ) }
27
27
28
+ # Helper to match the expected pattern of `script.StackFrame` objects.
29
+ # https://w3c.github.io/webdriver-bidi/#type-script-StackFrame
30
+ #
31
+ # Pass in any fields you want to check more specific values for, e.g:
32
+ # a_stack_frame('functionName' => 'someFunction')
33
+ def a_stack_frame ( **options )
34
+ include ( {
35
+ 'columnNumber' => an_instance_of ( Integer ) ,
36
+ 'functionName' => an_instance_of ( String ) ,
37
+ 'lineNumber' => an_instance_of ( Integer ) ,
38
+ 'url' => an_instance_of ( String )
39
+ } . merge ( options ) )
40
+ end
41
+
28
42
it 'errors when bidi not enabled' do
29
43
reset_driver! ( web_socket_url : false ) do |driver |
30
44
msg = /BiDi must be enabled by setting #web_socket_url to true in options class/
@@ -45,10 +59,27 @@ module WebDriver
45
59
expect ( log_entries . size ) . to eq ( 1 )
46
60
log_entry = log_entries . first
47
61
expect ( log_entry ) . to be_a BiDi ::LogHandler ::ConsoleLogEntry
62
+ expect ( log_entry . type ) . to eq 'console'
48
63
expect ( log_entry . level ) . to eq 'info'
49
64
expect ( log_entry . method ) . to eq 'log'
50
65
expect ( log_entry . text ) . to eq 'Hello, world!'
51
- expect ( log_entry . type ) . to eq 'console'
66
+ expect ( log_entry . args ) . to eq [
67
+ { 'type' => 'string' , 'value' => 'Hello, world!' }
68
+ ]
69
+ expect ( log_entry . timestamp ) . to be_an_integer
70
+ expect ( log_entry . source ) . to match (
71
+ 'context' => an_instance_of ( String ) ,
72
+ 'realm' => an_instance_of ( String )
73
+ )
74
+ # Stack traces on console messages are optional.
75
+ expect ( log_entry . stack_trace ) . to be_nil . or match (
76
+ # Some browsers include stack traces from parts of the runtime, so we
77
+ # just check the first frames that come from user code.
78
+ 'callFrames' => start_with (
79
+ a_stack_frame ( 'functionName' => 'helloWorld' ) ,
80
+ a_stack_frame ( 'functionName' => 'onclick' )
81
+ )
82
+ )
52
83
end
53
84
54
85
it 'logs multiple console messages' do
@@ -97,10 +128,22 @@ module WebDriver
97
128
expect ( log_entries . size ) . to eq ( 1 )
98
129
log_entry = log_entries . first
99
130
expect ( log_entry ) . to be_a BiDi ::LogHandler ::JavaScriptLogEntry
100
- expect ( log_entry . level ) . to eq 'error'
101
131
expect ( log_entry . type ) . to eq 'javascript'
132
+ expect ( log_entry . level ) . to eq 'error'
102
133
expect ( log_entry . text ) . to eq 'Error: Not working'
103
- expect ( log_entry . stack_trace ) . not_to be_empty
134
+ expect ( log_entry . timestamp ) . to be_an_integer
135
+ expect ( log_entry . source ) . to match (
136
+ 'context' => an_instance_of ( String ) ,
137
+ 'realm' => an_instance_of ( String )
138
+ )
139
+ expect ( log_entry . stack_trace ) . to match (
140
+ # Some browsers include stack traces from parts of the runtime, so we
141
+ # just check the first frames that come from user code.
142
+ 'callFrames' => start_with (
143
+ a_stack_frame ( 'functionName' => 'createError' ) ,
144
+ a_stack_frame ( 'functionName' => 'onclick' )
145
+ )
146
+ )
104
147
end
105
148
106
149
it 'errors removing non-existent handler' do
0 commit comments