Skip to content

Commit 13ab43d

Browse files
committed
#52 Add set_content method
1 parent 0e96c1c commit 13ab43d

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,12 @@ browser.evaluate("window.__injected") # => 42
705705
#### frames
706706
#### main_frame
707707
#### frame_by
708+
#### set_content(html)
709+
710+
Sets a content of given frame
711+
712+
* html `String`
713+
708714

709715
Play around inside given frame
710716

lib/ferrum/browser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Browser
1717
delegate %i[default_context] => :contexts
1818
delegate %i[targets create_target create_page page pages windows] => :default_context
1919
delegate %i[goto back forward refresh reload stop
20-
at_css at_xpath css xpath current_url title body doctype
20+
at_css at_xpath css xpath current_url title body doctype set_content
2121
headers cookies network
2222
mouse keyboard
2323
screenshot pdf viewport_size

lib/ferrum/frame.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ def main?
3535
@parent_id.nil?
3636
end
3737

38+
def set_content(html)
39+
evaluate_async(%(
40+
document.open();
41+
document.write(arguments[0]);
42+
document.close();
43+
arguments[1](true);
44+
), @page.timeout, html)
45+
end
46+
3847
def execution_id?(execution_id)
3948
@execution_id == execution_id
4049
end

lib/ferrum/page.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def reset
3131

3232
extend Forwardable
3333
delegate %i[at_css at_xpath css xpath
34-
current_url current_title url title body doctype
34+
current_url current_title url title body doctype set_content
3535
execution_id evaluate evaluate_on evaluate_async execute
3636
add_script_tag add_style_tag] => :main_frame
3737

spec/frame_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,12 @@ module Ferrum
235235
expect(frame.url).to end_with("/ferrum/slow")
236236
expect(browser.current_url).to end_with("/ferrum/frames")
237237
end
238+
239+
it "can set page content" do
240+
browser.set_content(%(<html><head></head><body>Voila!</body></html>))
241+
242+
expect(browser.body).to include("Voila!")
243+
end
238244
end
239245
end
240246
end

0 commit comments

Comments
 (0)