Class: Testin::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/testin.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Task

Returns a new instance of Task.



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/testin.rb', line 210

def initialize(options)
  # 1:安卓 2:IOS
  @path = options[:path]

  @devices = options[:devices]
  @project_name = options[:project_name]
  @api_key = options[:api_key]
  @app_version = options[:app_version]
  @email = options[:email]
  @pwd = options[:pwd]

  if @path.include?('ipa')
    @os_type = 2
  else
    @os_type = 1
  end
end

Instance Method Details

#create_task_for_fastObject



396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
# File 'lib/testin.rb', line 396

def create_task_for_fast
  upload_file_path = upload_file
  task_param =  {
      "apikey": Testin::get_task.get_api_key,
      "timestamp": Time.now.to_i * 1000,
      "sid": self.get_sid,
      "mkey": "realtest",
      "action": "app",
      "op": "Task.add",
      "data": {
          "projectid": self.get_project_id,
          "bizCode": "4001" ,# 4000 自动化兼容测试; 4001 自动化功能测试
          "taskDescr": "autotest" ,
          "appinfo": {
              "syspfId": self.get_os_type, #1:android; 2:ios
              "packageUrl": upload_file_path
          }, # 应用信息
          "devices": @devices,
          "scripts": Testin::TestinNetwork.all_scripts,
          "execStandard": {
              #4000 自动化兼容测试:
              #simple 安装+启动;
              #monkey 安装+启动+monkey;
              #script 安装+执行脚本
              #4001 自动化功能测试:
              #normal 普通执行;
              #fast 快速执行
              "standardType": "fast",
          } # 执行策略
      }
  }
  config = {:param => task_param}
  task = Testin::TestinNetwork.new(config)
  begin
    task.creat_task.to_s
  rescue StandardError => e
    raise e.to_s
  end
end

#create_task_for_normalObject

create task#######



353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/testin.rb', line 353

def create_task_for_normal
  upload_file_path = upload_file
  all_scripts = Testin::TestinNetwork.all_scripts
  raise 'script is empty' if all_scripts == nil || all_scripts.length == 0
  puts("all script length:#{all_scripts.length}")
  task_param =  {
      "apikey": Testin::get_task.get_api_key,
      "timestamp": Time.now.to_i * 1000,
      "sid": self.get_sid,
      "mkey": "realtest",
      "action": "app",
      "op": "Task.add",
      "data": {
          "projectid": self.get_project_id,
          "bizCode": "4001" ,# 4000 自动化兼容测试; 4001 自动化功能测试
          "taskDescr": "autotest" ,
          "appinfo": {
              "syspfId": self.get_os_type, #1:android; 2:ios
              "packageUrl": upload_file_path
          }, # 应用信息
          "devices": @devices,
          "scripts": all_scripts,
          "execStandard": {
              #4000 自动化兼容测试:
              #simple 安装+启动;
              #monkey 安装+启动+monkey;
              #script 安装+执行脚本
              #4001 自动化功能测试:
              #normal 普通执行;
              #fast 快速执行
              "standardType": "normal",
          } # 执行策略
      }
  }
  config = {:param => task_param}
  task = Testin::TestinNetwork.new(config)
  begin
    task.creat_task.to_s
  rescue StandardError => e
    raise e.to_s
  end
end

#get_api_keyObject



251
252
253
# File 'lib/testin.rb', line 251

def get_api_key()
  @api_key
end

#get_app_versionObject



243
244
245
# File 'lib/testin.rb', line 243

def get_app_version()
  @app_version
end

#get_os_typeObject



311
312
313
# File 'lib/testin.rb', line 311

def get_os_type()
  @os_type
end

#get_project_idObject



307
308
309
# File 'lib/testin.rb', line 307

def get_project_id()
  @project_id
end

#get_project_nameObject



247
248
249
# File 'lib/testin.rb', line 247

def get_project_name()
  @project_name
end

#get_sidObject



279
280
281
# File 'lib/testin.rb', line 279

def get_sid()
  @sid
end

#set_project_idObject



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/testin.rb', line 283

def set_project_id()
  project_param = {
      "apikey": @api_key,
      "mkey":"usermanager",
      "op":"Project.getUserProjectList",
      "data":{
          "page":1,
          "pageSize":10
      },
      "action":"user",
      "timestamp":Time.now.to_i * 1000,
      "sid": @sid
  }
  config = {:param => project_param}
  project = Testin::TestinNetwork.new(config)

  begin
    project_id = project.get_project_list
  rescue StandardError => e
    puts e.to_s
  end
  @project_id = project_id
end

#set_sidObject



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/testin.rb', line 255

def set_sid()
   = {
      :apikey => @api_key,
      :mkey => 'usermanager',
      :op => 'Login.login',
      :data => {
          :email => @email,
          :pwd => @pwd
      },
      :action => 'user',
      :timestamp => Time.now.to_i * 1000,
  }

  config = { param:  }
  net = Testin::TestinNetwork.new(config)

  begin
    sid = net.
  rescue StandardError => e
    raise e.to_s
  end
  @sid = sid
end

#set_upObject



228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/testin.rb', line 228

def set_up
  self.set_sid
  self.set_project_id
  puts("project_name:#{@project_name}")
  puts("sid:#{@sid}")
  puts("projectId:#{@project_id}")
  puts("devices:#{@devices}")
  puts("api_key:#{@api_key}")
  puts("email:#{@email}")
  puts("pwd:#{@pwd}")
  puts("app_version:#{@app_version}")
  puts("type:(android=1 iOS=2):#{@os_type}")
  puts('**********************init successed**********************')
end