Class: OmniAI::Tools::Browser::WatirDriver
- Inherits:
-
BaseDriver
- Object
- BaseDriver
- OmniAI::Tools::Browser::WatirDriver
- Defined in:
- lib/omniai/tools/browser/watir_driver.rb
Overview
Constant Summary
Constants inherited from BaseDriver
Instance Method Summary collapse
- #click(selector:) ⇒ Hash
- #close ⇒ Object
- #fill_in(selector:, text:) ⇒ Hash
- #goto(url:) ⇒ Object
- #html ⇒ String
-
#initialize(logger: Logger.new(IO::NULL), browser: Watir::Browser.new(:chrome)) ⇒ WatirDriver
constructor
A new instance of WatirDriver.
- #screenshot {|file| ... } ⇒ Object
- #title ⇒ String
- #url ⇒ String
Constructor Details
#initialize(logger: Logger.new(IO::NULL), browser: Watir::Browser.new(:chrome)) ⇒ WatirDriver
Returns a new instance of WatirDriver.
11 12 13 14 |
# File 'lib/omniai/tools/browser/watir_driver.rb', line 11 def initialize(logger: Logger.new(IO::NULL), browser: Watir::Browser.new(:chrome)) super(logger:) @browser = browser end |
Instance Method Details
#click(selector:) ⇒ Hash
71 72 73 74 75 76 77 78 79 |
# File 'lib/omniai/tools/browser/watir_driver.rb', line 71 def click(selector:) element = find_element(selector) return { status: :error, message: "unknown selector=#{selector.inspect}" } if element.nil? element.click { status: :ok } end |
#close ⇒ Object
16 17 18 |
# File 'lib/omniai/tools/browser/watir_driver.rb', line 16 def close @browser.close end |
#fill_in(selector:, text:) ⇒ Hash
58 59 60 61 62 63 64 65 66 |
# File 'lib/omniai/tools/browser/watir_driver.rb', line 58 def fill_in(selector:, text:) element = find_field(selector) return { status: :error, message: "unknown selector=#{selector.inspect}" } if element.nil? element.set(text) { status: :ok } end |
#goto(url:) ⇒ Object
36 37 38 39 40 |
# File 'lib/omniai/tools/browser/watir_driver.rb', line 36 def goto(url:) @browser.goto(url) { status: :ok } end |
#html ⇒ String
31 32 33 |
# File 'lib/omniai/tools/browser/watir_driver.rb', line 31 def html @browser.html end |
#screenshot {|file| ... } ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/omniai/tools/browser/watir_driver.rb', line 44 def screenshot tempfile = Tempfile.new(["screenshot", ".png"]) @browser.screenshot.save(tempfile.path) yield File.open(tempfile.path, "rb") ensure tempfile&.close tempfile&.unlink end |
#title ⇒ String
26 27 28 |
# File 'lib/omniai/tools/browser/watir_driver.rb', line 26 def title @browser.title end |
#url ⇒ String
21 22 23 |
# File 'lib/omniai/tools/browser/watir_driver.rb', line 21 def url @browser.url end |