Module: Awetestlib::Regression::Mobile
- Defined in:
- lib/awetestlib/regression/mobile.rb
Instance Method Summary collapse
- #clean_up_android_temp ⇒ Object
- #end_android_processes ⇒ Object
- #get_process_list ⇒ Object
- #open_mobile_browser ⇒ Object
- #parse_environment_node_for_mobile ⇒ Object
- #set_mobile_capabilities(device_id, device_type, sdk, emulator, http_client, server_url = "http://127.0.0.1:4723/wd/hub") ⇒ Object
Instance Method Details
#clean_up_android_temp ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/awetestlib/regression/mobile.rb', line 178 def clean_up_android_temp debug_to_log 'Here we will clean up emulator TMP files...' user = Etc::getlogin # debug_to_log user android_temp_path = 'C:\\Users\\'+user+'\\AppData\\Local\\Temp\\AndroidEmulator' debug_to_log android_temp_path if Dir.exists?(android_temp_path) dir = Dir.new(android_temp_path) dir.each do |file| debug_to_log file if file =~ /^TMP.+\.tmp/ end tmp_ptrn = '\\TMP*.tmp' dir_cmd = "dir #{android_temp_path}#{tmp_ptrn} 2>&1" del_cmd = "del #{android_temp_path}#{tmp_ptrn} 2>&1" debug_to_log "#{__LINE__}: #{dir_cmd}" dir_out = `#{dir_cmd}` unless dir_out =~ /file not found/i debug_to_log "#{__LINE__}: #{del_cmd}" debug_to_log `#{del_cmd}`.chomp if `#{dir_cmd}` =~ /file not found/i debug_to_log 'Emulator TMP files deleted successfully' end end else debug_to_log("#{android_temp_path} not found") end rescue failed_to_log(unable_to) end |
#end_android_processes ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/awetestlib/regression/mobile.rb', line 210 def end_android_processes processes = ['node.exe', 'emulator-arm.exe', 'emulator-x86.exe', 'adb.exe', 'chromedriver.exe', 'cmd.exe'] tasks = get_process_list targets = [] if USING_OSX kill_cmd = 'kill -9 @@@@@' else kill_cmd = 'taskkill /f /pid @@@@@' end processes.each do |image_name| if image_name == 'cmd.exe' hit = tasks.detect { |t| t[:window_title] =~ /^appium server/i } else hit = tasks.detect { |t| t[:image_name] =~ /^#{image_name}/i } end if hit and hit.length > 0 targets << hit end end ['node.exe', 'emulator', 'cmd.exe', 'adb.exe', 'chromedriver'].each do |process| hit = targets.detect { |t| t[:image_name] =~ /^#{process}/i } if hit and hit.length > 0 pid = hit[:pid] name = hit[:image_name] title = hit[:window_title] cmd = kill_cmd.sub('@@@@@', pid) debug_to_log("[#{cmd}] #{name} #{title}") kill_io = IO.popen(cmd, :err => :out) debug_to_log(kill_io.read.chomp) kill_io.close end end rescue failed_to_log(unable_to) end |
#get_process_list ⇒ Object
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/awetestlib/regression/mobile.rb', line 252 def get_process_list if USING_OSX cmd = "ps axo comm,pid,sess,fname" else cmd = 'tasklist /v -fo csv 2>&1' end debug_to_log(cmd) raw = `#{cmd}` list = raw.force_encoding(Encoding::UTF_8) # debug_to_log(list) if list =~ /No tasks are running which match the specified criteria/i tasks = nil else begin csv = CSV.new(list, :headers => true, :header_converters => :symbol) # debug_to_log(with_caller(__LINE__, "\n", "#{csv}")) rescue => e raise e end begin arr = csv.to_a # debug_to_log(with_caller(__LINE__, "\n", "#{arr}")) rescue => e raise e end begin tasks = arr.map { |row| row.to_hash } # debug_to_log(tasks) rescue => e raise e end end tasks rescue failed_to_log(unable_to) end |
#open_mobile_browser ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/awetestlib/regression/mobile.rb', line 7 def open_mobile_browser mark_test_level(": #{self.device_type.titleize}") if Dir.pwd =~ /shamisen/i subdir = 'awetest_report' sleep1 = 30 sleep2 = 90 server_url = "http://127.0.0.1:4723/wd/hub" # server_url = 'http://0.0.0.0:4723/wd/hub' else subdir = 'log' sleep1 = 10 sleep2 = 10 server_url = "http://127.0.0.1:4723/wd/hub" end debug_to_log(with_caller("$debug => #{$debug}, $DEBUG => #{$DEBUG}")) log_level = $debug ? 'debug:debug' : 'debug:debug' #'warn:debug' debug_to_log(with_caller("#{Dir.pwd.chomp}")) log_file = File.join(Dir.pwd.chomp, subdir, "#{File.basename(__FILE__, '.rb')}_appium_lib_#{Time.now.strftime("%Y%m%d%H%M%S")}.log") command = "start \"appium server\" appium --log-timestamp --log-level #{log_level} -g #{log_file} &" debug_to_log(command) appium = IO.popen(command, :err => :out) @appium_pid = appium.pid debug_to_log(with_caller("Appium PID: #{@appium_pid}")) debug_to_log(with_caller("nodejs version: #{`node --version`.chomp}")) sleep_for(sleep1) client = Selenium::WebDriver::Remote::Http::Default.new client.timeout = 300 desired_caps = set_mobile_capabilities(self.device_id, self.device_type, self.sdk, self.emulator, client, server_url) debug_to_log(desired_caps.to_yaml) debug_to_log(with_caller('Instantiating Appium Driver')) Appium::Driver.new(desired_caps) debug_to_log(with_caller('Starting Appium Driver')) $driver.start_driver sleep_for(sleep2) debug_to_log(with_caller('Getting Watir Browser from driver...')) browser = Watir::Browser.new($driver.driver) debug_to_log(with_caller('Returning browser')) browser rescue failed_to_log(unable_to) end |
#parse_environment_node_for_mobile ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/awetestlib/regression/mobile.rb', line 139 def parse_environment_node_for_mobile if self.environment_nodename =~ /;/ entries = {} self.environment['input_nodename'] = self.environment_nodename unless self.environment_nodename =~ /^W:/ self.environment_nodename = "W:#{self.environment_nodename}" end parms = self.environment_nodename.split(';') parms.each do |p| key, vlu = p.split(':') entries[key] = vlu end entries.each do |key, vlu| case key when 'W' self.environment_nodename = vlu self.[:environment_nodename] = vlu self.environment['nodename'] = vlu when 'I' self.device_id = vlu self.[:device_id] = vlu when 'K' self.sdk = vlu self.[:sdk] = vlu when 'T' self.device_type = vlu self.[:device_type] = vlu when 'E' self.emulator = vlu self.[:emulator] = vlu end end end rescue failed_to_log(unable_to) end |
#set_mobile_capabilities(device_id, device_type, sdk, emulator, http_client, server_url = "http://127.0.0.1:4723/wd/hub") ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 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 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/awetestlib/regression/mobile.rb', line 62 def set_mobile_capabilities(device_id, device_type, sdk, emulator, http_client, server_url = "http://127.0.0.1:4723/wd/hub") mark_test_level case device_type when /android device/i desired_caps = { :caps => { :newCommandTimeout => 600, :androidDeviceReadyTimeout => 420, :avdLaunchTimeout => 240000, :avdReadyTimeout => 240000, :deviceName => "Android Device", :automationName => "Appium", :platformName => "Android", :browserName => "Chrome", :platformVersion => sdk, 'app' => "chrome", # 'appPackage' => "com.android.chrome", :udid => device_id, :http_client => http_client, :chromeOptions => { "args" => ['--ignore-certificate-errors', '--verbose'] } #ignore-certificate-errors=true homepage=about:blank test_type=true' } }, :appium_lib => { :server_url => server_url } } when /android emulator/i # NOTE: avd cannot start from snapshot?. desired_caps = { :caps => { :newCommandTimeout => 1200, :androidDeviceReadyTimeout => 420, :avdLaunchTimeout => 240000, :avdReadyTimeout => 240000, :debug => true, :deviceName => "Android Emulator", :platformName => "Android", :avd => emulator, :browserName => "Browser", :avdArgs => '-no-audio -http-proxy 151.151.15.250:8080 -dns-server 10.27.206.11:55,10.27.206.101:55,10.91.218.197:55', :http_client => http_client, :chromeOptions => { 'args' => ['--ignore-certificate-errors', '--verbose'] } }, :appium_lib => { :server_url => server_url } } when /ios device/i desired_caps = { 'platformVersion' => sdk, 'deviceName' => "My_device", 'platformName' => "iOS", 'browserName' => 'Safari', 'udid' => device_id } when /ios simulator/i desired_caps = { 'deviceName' => device_type, 'platformVersion' => sdk, 'browserName' => 'Safari', 'platformName' => "iOS" } else raise "Unrecognized mobile device type: '#{device_type}'" end debug_to_log(with_caller("\n#{desired_caps.to_yaml}")) desired_caps rescue failed_to_log(unable_to) end |