module Bucky::TestEquipment::SeleniumHandler::WebdriverHandler
Public Class Methods
create_webdriver(device_type)
click to toggle source
Create and return webdriver object @param [String] device_type e.g.) sp, pc, tablet @return [Selenium::WebDriver]
# File lib/bucky/test_equipment/selenium_handler/webdriver_handler.rb, line 14 def create_webdriver(device_type) @@config = Bucky::Utils::Config.instance driver_args = create_driver_args(device_type) driver = Selenium::WebDriver.for(:remote, **driver_args) driver.manage.window.resize_to(1280, 1000) driver.manage.timeouts.implicit_wait = @@config[:find_element_timeout] driver rescue StandardError => e Bucky::Core::Exception::BuckyException.handle(e) end
Private Instance Methods
create_driver_args(device_type)
click to toggle source
@param [String] device_type e.g.) sp, pc, tablet @return [Hash] driver_args
# File lib/bucky/test_equipment/selenium_handler/webdriver_handler.rb, line 30 def create_driver_args(device_type) driver_args = { url: format('http://%<ip>s:%<port>s/wd/hub', ip: @@config[:selenium_ip], port: @@config[:selenium_port]) } driver_args[:desired_capabilities] = generate_desire_caps(device_type) client = Selenium::WebDriver::Remote::Http::Default.new client.open_timeout = @@config[:driver_open_timeout] client.read_timeout = @@config[:driver_read_timeout] driver_args[:http_client] = client driver_args end
create_webdriver(device_type)
click to toggle source
Create and return webdriver object @param [String] device_type e.g.) sp, pc, tablet @return [Selenium::WebDriver]
# File lib/bucky/test_equipment/selenium_handler/webdriver_handler.rb, line 14 def create_webdriver(device_type) @@config = Bucky::Utils::Config.instance driver_args = create_driver_args(device_type) driver = Selenium::WebDriver.for(:remote, **driver_args) driver.manage.window.resize_to(1280, 1000) driver.manage.timeouts.implicit_wait = @@config[:find_element_timeout] driver rescue StandardError => e Bucky::Core::Exception::BuckyException.handle(e) end
generate_desire_caps(device_type)
click to toggle source
@param [String] device_type e.g.) sp, pc, tablet @return [Hash] desire_capabilities
# File lib/bucky/test_equipment/selenium_handler/webdriver_handler.rb, line 42 def generate_desire_caps(device_type) case @@config[:browser] when :chrome then set_chrome_option(device_type) else raise 'Currently only supports chrome. Sorry.' end end
set_chrome_option(device_type)
click to toggle source
# File lib/bucky/test_equipment/selenium_handler/webdriver_handler.rb, line 51 def set_chrome_option(device_type) chrome_options = { 'goog:chromeOptions' => { args: [] } } unless device_type == 'pc' device_type = "#{device_type}_device_name".to_sym mobile_emulation = { 'deviceName' => @@config[:device_name_on_chrome][@@config[device_type]] } chrome_options['goog:chromeOptions']['mobileEmulation'] = mobile_emulation end chrome_options['goog:chromeOptions'][:args] << "--user-agent=#{@@config[:user_agent]}" if @@config[:user_agent] chrome_options['goog:chromeOptions'][:args] << '--headless' if @@config[:headless] chrome_options['goog:chromeOptions'][:args].concat(@@config[:chromedriver_flags]) unless @@config[:chromedriver_flags].nil? Selenium::WebDriver::Remote::Capabilities.chrome(chrome_options) end