File tree 4 files changed +35
-0
lines changed
4 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
### Added
4
4
5
+ - Support for ` Driver#send_keys ` , the ` :focused ` filter, and ` Driver#active_element ` [ #261 ]
6
+
5
7
### Changed
6
8
- ` @window_size ` attribute is moved from Ferrum, viewport size is still inherited [ #253 ]
7
9
- Compatibility with latest Ferrum. Browser instance is not passed everywhere now [ #254 ]
Original file line number Diff line number Diff line change @@ -127,6 +127,10 @@ def close_window(target_id)
127
127
targets . delete ( target_id ) # page.close is async, delete target asap
128
128
end
129
129
130
+ def active_element
131
+ evaluate ( "document.activeElement" )
132
+ end
133
+
130
134
def browser_error
131
135
evaluate ( "_cuprite.browserError()" )
132
136
end
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ class Driver < Capybara::Driver::Base
15
15
delegate %i[ restart quit status_code timeout timeout= current_url title body
16
16
window_handles close_window switch_to_window within_window window_handle
17
17
back forward refresh wait_for_reload viewport_size device_pixel_ratio ] => :browser
18
+ delegate %i[ send_keys ] => :active_element
18
19
alias html body
19
20
alias current_window_handle window_handle
20
21
alias go_back back
@@ -70,6 +71,10 @@ def frame_title
70
71
evaluate_script ( "document.title" )
71
72
end
72
73
74
+ def active_element
75
+ Node . new ( self , browser . active_element )
76
+ end
77
+
73
78
def find_xpath ( selector )
74
79
find ( :xpath , selector )
75
80
end
Original file line number Diff line number Diff line change @@ -1303,6 +1303,30 @@ def create_screenshot(file, *args)
1303
1303
expect ( input . text ) . to eq ( "hello" )
1304
1304
end
1305
1305
1306
+ it "supports the :focused filter" do
1307
+ @session . find_field ( "empty_input" ) . execute_script ( "this.focus()" )
1308
+
1309
+ expect ( @session ) . to have_field ( "empty_input" , focused : true )
1310
+ end
1311
+
1312
+ it "accessed the document.activeElement" do
1313
+ input = @session . find_field ( "empty_input" )
1314
+ input . execute_script ( "this.focus()" )
1315
+
1316
+ expect ( @session . active_element ) . to eq ( input )
1317
+ end
1318
+
1319
+ it "sends keys to the active_element" do
1320
+ @session . find_field ( "empty_input" ) . execute_script ( "this.focus()" )
1321
+
1322
+ expect ( @session ) . to have_field ( "empty_input" , focused : true )
1323
+
1324
+ @session . send_keys ( :tab )
1325
+
1326
+ expect ( @session ) . to have_field ( "empty_input" , focused : false )
1327
+ . and ( have_field ( "filled_input" , focused : true ) )
1328
+ end
1329
+
1306
1330
it "sends keys to filled contenteditable div" do
1307
1331
input = @session . find ( :css , "#filled_div" )
1308
1332
You can’t perform that action at this time.
0 commit comments