Class: Watir::Device
- Inherits:
-
Object
- Object
- Watir::Device
- Defined in:
- lib/watir-device/device.rb
Overview
Automate Chrome in mobile emulation mode. Devices availabe for emulation are available in the Dev Tool preferences, including “Apple iPhone 6 Plus”, “Samsung Galaxy Note 3”, “Google Nexus 10”, etc.
Instance Attribute Summary collapse
-
#browser ⇒ Object
readonly
Returns the value of attribute browser.
-
#device_name ⇒ Object
readonly
Returns the value of attribute device_name.
-
#driver ⇒ Object
readonly
Returns the value of attribute driver.
Class Method Summary collapse
-
.start(url, device_name, *args) ⇒ Watir::Device
Spin up an instance and navigate to a URL.
Instance Method Summary collapse
-
#device ⇒ String
Get the emulated device’s name.
-
#device_driver(name) ⇒ Object
private
Build a WebDriver to emulate the device.
-
#initialize(device_name, *args) ⇒ Watir::Device
constructor
Emulate a device browser with Chrome’s mobile emulation tool.
-
#inspect ⇒ String
Closed instances will return string ending in CLOSED.
-
#method_missing(mthd, *args) ⇒ Object
private
Undefined methods are passed to Watir::Browser.
Constructor Details
#initialize(device_name, *args) ⇒ Watir::Device
Emulate a device browser with Chrome’s mobile emulation tool.
37 38 39 40 41 42 43 44 45 |
# File 'lib/watir-device/device.rb', line 37 def initialize device_name, *args begin @driver = device_driver(device_name) rescue Selenium::WebDriver::Error::UnknownError => e raise DeviceError, "Invalid device name: '#{device_name}'" end @device_name = device_name @browser = Watir::Browser.new driver end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mthd, *args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Undefined methods are passed to Watir::Browser.
81 82 83 |
# File 'lib/watir-device/device.rb', line 81 def method_missing mthd, *args browser.send(mthd, *args) end |
Instance Attribute Details
#browser ⇒ Object (readonly)
Returns the value of attribute browser.
12 13 14 |
# File 'lib/watir-device/device.rb', line 12 def browser @browser end |
#device_name ⇒ Object (readonly)
Returns the value of attribute device_name.
12 13 14 |
# File 'lib/watir-device/device.rb', line 12 def device_name @device_name end |
#driver ⇒ Object (readonly)
Returns the value of attribute driver.
12 13 14 |
# File 'lib/watir-device/device.rb', line 12 def driver @driver end |
Class Method Details
.start(url, device_name, *args) ⇒ Watir::Device
Spin up an instance and navigate to a URL.
26 27 28 |
# File 'lib/watir-device/device.rb', line 26 def start url, device_name, *args new(device_name, *args).tap { |dev| dev.goto url } end |
Instance Method Details
#device ⇒ String
Get the emulated device’s name.
52 53 54 |
# File 'lib/watir-device/device.rb', line 52 def device device_name end |
#device_driver(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Build a WebDriver to emulate the device.
68 69 70 71 72 73 74 75 76 |
# File 'lib/watir-device/device.rb', line 68 def device_driver name opts = { "mobileEmulation" => { "deviceName" => name } } capabilities = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => opts) Selenium::WebDriver.for(:chrome, desired_capabilities: capabilities) end |
#inspect ⇒ String
Closed instances will return string ending in CLOSED.
62 63 64 |
# File 'lib/watir-device/device.rb', line 62 def inspect '<#%s:0x%x device=%s url=%s>' % [self.class, hash*2, device, browser.url] rescue '<#%s:0x%x device=%s CLOSED>' % [self.class, hash*2, device] end |