File tree 5 files changed +62
-5
lines changed 5 files changed +62
-5
lines changed Original file line number Diff line number Diff line change @@ -210,6 +210,10 @@ def path(node)
210
210
evaluate_on ( node : node , expression : "_cuprite.path(this)" )
211
211
end
212
212
213
+ def obscured? ( node )
214
+ evaluate_on ( node : node , expression : "_cuprite.isObscured(this)" )
215
+ end
216
+
213
217
def all_text ( node )
214
218
node . text
215
219
end
Original file line number Diff line number Diff line change @@ -115,6 +115,35 @@ class Cuprite {
115
115
return `//${ selectors . join ( "/" ) } ` ;
116
116
}
117
117
118
+ /**
119
+ * Returns true if the node is obscured in the viewport.
120
+ *
121
+ * @param {Element } node
122
+ * @return {boolean } true if the node is obscured, false otherwise
123
+ */
124
+ isObscured ( node ) {
125
+ let win = window ;
126
+ let rect = node . getBoundingClientRect ( ) ;
127
+ let px = rect . left + rect . width / 2 ;
128
+ let py = rect . top + rect . height / 2 ;
129
+
130
+ while ( win ) {
131
+ let topNode = win . document . elementFromPoint ( px , py ) ;
132
+
133
+ if ( node !== topNode && ! node . contains ( topNode ) ) return true ;
134
+
135
+ node = win . frameElement ;
136
+ if ( ! node ) return false ;
137
+
138
+ rect = node . getBoundingClientRect ( ) ;
139
+ px = rect . left + px ;
140
+ py = rect . top + py ;
141
+ win = win . parent ;
142
+ }
143
+
144
+ return false ;
145
+ }
146
+
118
147
set ( node , value ) {
119
148
if ( node . readOnly ) return ;
120
149
Original file line number Diff line number Diff line change @@ -213,6 +213,10 @@ def path
213
213
command ( :path )
214
214
end
215
215
216
+ def obscured?
217
+ command ( :obscured? )
218
+ end
219
+
216
220
def inspect
217
221
%(#<#{ self . class } @node=#{ @node . inspect } >)
218
222
end
Original file line number Diff line number Diff line change 314
314
end
315
315
end
316
316
317
+ describe "Node#obscured?" do
318
+ context "when the element is not in the viewport of parent element" do
319
+ before do
320
+ @session . visit ( "/cuprite/scroll" )
321
+ end
322
+
323
+ it "is is a boolean" do
324
+ expect ( @session . find_link ( "Link outside viewport" ) ) . to be_obscured
325
+ expect ( @session . find_link ( "Below the fold" ) ) . to be_obscured
326
+ end
327
+ end
328
+
329
+ context "when the element is only overlapped by descendants" do
330
+ before do
331
+ @session . visit ( "/with_html" )
332
+ end
333
+
334
+ # copied from https://github.com/teamcapybara/capybara/blob/master/lib/capybara/spec/session/node_spec.rb#L328
335
+ # as this example is currently disabled on CI in the upstream suite
336
+ it "is not obscured" do
337
+ expect ( @session . first ( :css , "p:not(.para)" ) ) . not_to be_obscured
338
+ end
339
+ end
340
+ end
341
+
317
342
it "has no trouble clicking elements when the size of a document changes" do
318
343
@session . visit ( "/cuprite/long_page" )
319
344
@session . find ( :css , "#penultimate" ) . click
Original file line number Diff line number Diff line change @@ -37,7 +37,6 @@ module TestSessions
37
37
RSpec . configure do |config |
38
38
config . define_derived_metadata do |metadata |
39
39
regexes = <<~REGEXP . split ( "\n " ) . map { |s | Regexp . quote ( s . strip ) } . join ( "|" )
40
- node #obscured?
41
40
node #drag_to should work with jsTree
42
41
node #drag_to should drag and drop an object
43
42
node #drag_to should drag and drop if scrolling is needed
@@ -68,10 +67,6 @@ module TestSessions
68
67
node #path reports when element in shadow dom
69
68
node #shadow_root
70
69
node #set should submit single text input forms if ended with
71
- #all with obscured filter should only find nodes on top in the viewport when false
72
- #all with obscured filter should not find nodes on top outside the viewport when false
73
- #all with obscured filter should find top nodes outside the viewport when true
74
- #all with obscured filter should only find non-top nodes when true
75
70
#fill_in should fill in a color field
76
71
#fill_in should handle carriage returns with line feeds in a textarea correctly
77
72
#has_field with valid should be false if field is invalid
You can’t perform that action at this time.
0 commit comments