Method: Browser#init_args

Defined in:
lib/actir/webdriver/browser.rb

#init_args(args = {}) ⇒ Object

初始化入参



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/actir/webdriver/browser.rb', line 84

def init_args(args = {})
  # config_exist = File.exist?(config_file)
  config_exist = ($config != nil)
  unless args.has_key?(:mode) && args[:mode] != nil
    #若通过actir执行测试用例,则会配置ENV的模式
    if ENV["mode"]
      args[:mode] = ENV["mode"].to_sym
    else
      #若ENV为空,则读取配置文件,判断有无配置文件
      if config_exist
        mode = $config["config"]["test_mode"]["mode"]
        args[:mode] = (mode == nil) ? :local : mode
      else
        args[:mode] = :local
      end
    end
  end
  unless args.has_key?(:browser) && args[:browser] != nil
    if config_exist 
      browser_type = $config["config"]["test_mode"]["browser"]
      args[:browser] = (browser_type == nil) ? :chrome : browser_type
    else
      args[:browser] = :chrome
    end
  end
  unless args.has_key?(:window_size) && args[:window_size] != nil
    if config_exist
      window_size = $config["config"]["window_size"]
      if window_size != nil
        width = window_size["width"]
        height = window_size["height"]
      end
      args[:window_size] = (width == nil || height == nil) ? nil : window_size
    else
      args[:window_size] = nil
    end
  end
  args[:agent] = :iphone  unless args.has_key?(:agent) && args[:agent] != nil
  args[:url] = $address  unless args.has_key?(:url) && args[:url] != nil
  args
end