testin 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.idea/.rakeTasks +7 -0
  4. data/.idea/testin.iml +83 -0
  5. data/.rspec +3 -0
  6. data/.travis.yml +7 -0
  7. data/CODE_OF_CONDUCT.md +74 -0
  8. data/Gemfile +6 -0
  9. data/Gemfile.lock +182 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +43 -0
  12. data/Rakefile +6 -0
  13. data/bin/console +14 -0
  14. data/bin/setup +8 -0
  15. data/fastlane-plugin-testintask/.circleci/config.yml +43 -0
  16. data/fastlane-plugin-testintask/.gitignore +12 -0
  17. data/fastlane-plugin-testintask/.rspec +5 -0
  18. data/fastlane-plugin-testintask/.rubocop.yml +180 -0
  19. data/fastlane-plugin-testintask/.travis.yml +4 -0
  20. data/fastlane-plugin-testintask/Gemfile +6 -0
  21. data/fastlane-plugin-testintask/LICENSE +21 -0
  22. data/fastlane-plugin-testintask/README.md +52 -0
  23. data/fastlane-plugin-testintask/Rakefile +9 -0
  24. data/fastlane-plugin-testintask/fastlane/Fastfile +3 -0
  25. data/fastlane-plugin-testintask/fastlane/Pluginfile +1 -0
  26. data/fastlane-plugin-testintask/fastlane-plugin-testintask.gemspec +35 -0
  27. data/fastlane-plugin-testintask/lib/fastlane/plugin/testintask/actions/testintask_action.rb +67 -0
  28. data/fastlane-plugin-testintask/lib/fastlane/plugin/testintask/helper/testintask_helper.rb +16 -0
  29. data/fastlane-plugin-testintask/lib/fastlane/plugin/testintask/version.rb +5 -0
  30. data/fastlane-plugin-testintask/lib/fastlane/plugin/testintask.rb +16 -0
  31. data/fastlane-plugin-testintask/spec/spec_helper.rb +15 -0
  32. data/fastlane-plugin-testintask/spec/testintask_action_spec.rb +9 -0
  33. data/lib/testin/version.rb +3 -0
  34. data/lib/testin.rb +436 -0
  35. data/testin.gemspec +31 -0
  36. metadata +120 -0
data/lib/testin.rb ADDED
@@ -0,0 +1,436 @@
1
+ require "testin/version"
2
+ require 'faraday'
3
+ require 'faraday_middleware'
4
+ require 'json'
5
+ require "date"
6
+
7
+ module Testin
8
+ class Error < StandardError; end
9
+
10
+ def Testin.get_task
11
+ if @dynamic_param != nil
12
+ return @dynamic_param
13
+ end
14
+ @dynamic_param = Testin::Task.new($global_options)
15
+ @dynamic_param.set_up
16
+ @dynamic_param
17
+ end
18
+
19
+ def Testin.set_task options
20
+ $global_options = options
21
+ Testin.get_task
22
+ end
23
+
24
+ class Network
25
+ def self.testin_hostname
26
+ "http://fileupload.pro.testin.cn"
27
+ end
28
+
29
+ def initialize(options)
30
+ @options = options
31
+
32
+ @conn_options = {
33
+ request: {
34
+ timeout: 30,
35
+ open_timeout: 300
36
+ },
37
+ #proxy: "http://127.0.0.1:8888" # for debug
38
+ }
39
+ @testin_client = Faraday.new(self.class.testin_hostname, @conn_options) do |c|
40
+ c.request :url_encoded
41
+ c.adapter :net_http
42
+ c.response :json, :content_type => /\bjson$/
43
+ end
44
+
45
+ end
46
+
47
+ def request
48
+ path = ''
49
+ @testin_client.post do |req|
50
+ req.url path
51
+ req.headers['Host'] = 'openapi.pro.testin.cn'
52
+ req.headers['Content-Type'] = 'text/plain'
53
+ req.body = @options[:param].to_json
54
+ end
55
+ end
56
+
57
+ def validation_response response_data
58
+ error_code = response_data['code'].to_i
59
+ return if error_code.zero?
60
+ raise 'validation_response error' if response_data['msg'].empty?
61
+ raise response_data['msg']
62
+ end
63
+ end
64
+
65
+ class TestinNetwork < Network
66
+
67
+ # 登录获取token
68
+ def get_login_token
69
+ begin
70
+ info = request.body
71
+ info = JSON.parse(info)
72
+ validation_response info
73
+ raise 'Error Login' if info['data']['result'].empty?
74
+ info['data']['result']
75
+ rescue StandardError => e
76
+ raise e.to_s
77
+ end
78
+ end
79
+
80
+ # 获取脚本列表
81
+ def get_script_list
82
+ begin
83
+ info = request.body
84
+ info = JSON.parse(info)
85
+ validation_response info
86
+ raise 'Error FetchScriptNetwork' if info['data']['list'].empty?
87
+ info['data']['list']
88
+ rescue StandardError => e
89
+ #raise e.to_s
90
+ puts(e.to_s)
91
+ end
92
+ end
93
+
94
+ # 获取项目列表
95
+ def get_project_list
96
+
97
+ begin
98
+ info = request.body
99
+ info = JSON.parse(info)
100
+ validation_response info
101
+ raise 'Error FetchProjectNetWork' if info['data']['list'].empty?
102
+ end
103
+
104
+ begin
105
+ arr = info['data']['list'].inject([]) do |r, e|
106
+ r << e['projectid'] if e['name'] == Testin::get_task.get_project_name
107
+ r
108
+ end
109
+ raise "Project #{Testin::get_task.get_project_name} is empty" if arr.empty?
110
+ arr[0]
111
+ end
112
+ end
113
+
114
+
115
+ #获取设备列表
116
+ def get_device_list
117
+ begin
118
+ info = request.body
119
+ info = JSON.parse(info)
120
+ validation_response info
121
+ raise 'Error FetchDeviceNetwork' if info['data']['list'].empty?
122
+ info['data']['list']
123
+ rescue StandardError => e
124
+ raise e.to_s
125
+ end
126
+ end
127
+
128
+ # 上传文件
129
+ def upload_file(file_name)
130
+ conn = Faraday.new(self.class.testin_hostname,@conn_options) do |c|
131
+ c.request :multipart
132
+ c.adapter :net_http
133
+ c.response :json, :content_type => /\bjson$/
134
+ end
135
+
136
+ response = conn.post do |req|
137
+ req.headers['Host'] = 'openapi.pro.testin.cn'
138
+ req.headers['Transfer-Encoding'] = 'chunked'
139
+ req.headers['Content-Type'] = 'application/octet-stream'
140
+ req.headers['UPLOAD-JSON'] = @options[:param].to_json
141
+ req.body = Faraday::UploadIO.new(file_name, 'application/octet-stream')
142
+ end
143
+
144
+
145
+ begin
146
+ info = response.body
147
+ info = JSON.parse(info)
148
+ validation_response info
149
+ raise 'Error UPLOAD_FILE' if info['data']['result'].empty?
150
+ info['data']['result']
151
+ end
152
+ end
153
+
154
+ # 创建任务
155
+ def creat_task
156
+ begin
157
+ info = request.body
158
+ info = JSON.parse(info)
159
+ validation_response info
160
+ raise 'Error CREAT_TASK' if info['data']['result'].empty?
161
+ info['data']
162
+ end
163
+ end
164
+
165
+ def self.all_scripts ()
166
+
167
+ start_page_no = 1
168
+ array = []
169
+ while
170
+ #######获取脚本#######
171
+ script_param = {
172
+ 'apikey': Testin::get_task.get_api_key,
173
+ 'mkey': 'script',
174
+ 'sid':Testin::get_task.get_sid,
175
+ 'op': 'Script.listScriptFile',
176
+ 'action': 'script',
177
+ 'timestamp': Time.now.to_i * 1000,
178
+ 'data': {
179
+ 'scriptDesc': '',
180
+ 'appId': 0,
181
+ 'startPageNo': start_page_no,
182
+ 'osType': Testin::get_task.get_os_type,
183
+ 'pageSize': 15,
184
+ 'projectId': Testin::get_task.get_project_id
185
+ }
186
+ }
187
+ config = {:param => script_param}
188
+ script = Testin::TestinNetwork.new(config)
189
+
190
+ begin
191
+ script_array = script.get_script_list
192
+ break if script_array == nil || script_array.length == 0
193
+ scripts = script_array.inject([]) do |r, e|
194
+ r << {'scriptid': e['scriptid'],'scriptNo': e['scriptNo']} if e['taginfos'].include?'case' and e['projectId'].to_i == Testin::get_task.get_project_id and e['adapterversionname'].to_s == Testin::get_task.get_app_version
195
+ r
196
+ end
197
+ if scripts.length > 0
198
+ array = array + scripts
199
+ end
200
+ start_page_no += 1
201
+ rescue StandardError => e
202
+ raise e.to_s
203
+ end
204
+ end
205
+ array.uniq
206
+ end
207
+ end
208
+
209
+ class Task
210
+ def initialize(options)
211
+ # 1:安卓 2:IOS
212
+ @path = options[:path]
213
+
214
+ @devices = options[:devices]
215
+ @project_name = options[:project_name]
216
+ @api_key = options[:api_key]
217
+ @app_version = options[:app_version]
218
+ @email = options[:email]
219
+ @pwd = options[:pwd]
220
+
221
+ if @path.include?('ipa')
222
+ @os_type = 2
223
+ else
224
+ @os_type = 1
225
+ end
226
+ end
227
+
228
+ def set_up
229
+ self.set_sid
230
+ self.set_project_id
231
+ puts("project_name:#{@project_name}")
232
+ puts("sid:#{@sid}")
233
+ puts("projectId:#{@project_id}")
234
+ puts("devices:#{@devices}")
235
+ puts("api_key:#{@api_key}")
236
+ puts("email:#{@email}")
237
+ puts("pwd:#{@pwd}")
238
+ puts("app_version:#{@app_version}")
239
+ puts("type:(android=1 iOS=2):#{@os_type}")
240
+ puts('**********************init successed**********************')
241
+ end
242
+
243
+ def get_app_version()
244
+ @app_version
245
+ end
246
+
247
+ def get_project_name()
248
+ @project_name
249
+ end
250
+
251
+ def get_api_key()
252
+ @api_key
253
+ end
254
+
255
+ def set_sid()
256
+ login_param = {
257
+ :apikey => @api_key,
258
+ :mkey => 'usermanager',
259
+ :op => 'Login.login',
260
+ :data => {
261
+ :email => @email,
262
+ :pwd => @pwd
263
+ },
264
+ :action => 'user',
265
+ :timestamp => Time.now.to_i * 1000,
266
+ }
267
+
268
+ config = { param: login_param }
269
+ net = Testin::TestinNetwork.new(config)
270
+
271
+ begin
272
+ sid = net.get_login_token
273
+ rescue StandardError => e
274
+ raise e.to_s
275
+ end
276
+ @sid = sid
277
+ end
278
+
279
+ def get_sid()
280
+ @sid
281
+ end
282
+
283
+ def set_project_id()
284
+ project_param = {
285
+ "apikey": @api_key,
286
+ "mkey":"usermanager",
287
+ "op":"Project.getUserProjectList",
288
+ "data":{
289
+ "page":1,
290
+ "pageSize":10
291
+ },
292
+ "action":"user",
293
+ "timestamp":Time.now.to_i * 1000,
294
+ "sid": @sid
295
+ }
296
+ config = {:param => project_param}
297
+ project = Testin::TestinNetwork.new(config)
298
+
299
+ begin
300
+ project_id = project.get_project_list
301
+ rescue StandardError => e
302
+ puts e.to_s
303
+ end
304
+ @project_id = project_id
305
+ end
306
+
307
+ def get_project_id()
308
+ @project_id
309
+ end
310
+
311
+ def get_os_type()
312
+ @os_type
313
+ end
314
+
315
+ def upload_file()
316
+ if self.get_os_type == 2
317
+ suffix = 'ipa'
318
+ else
319
+ suffix = 'apk'
320
+ end
321
+
322
+ ####### upload file ##########
323
+ upload_param = {
324
+ "apikey":Testin::get_task.get_api_key,
325
+ "timestamp":Time.now.to_i * 1000,
326
+ "sid":self.get_sid,
327
+ "mkey":"fs",
328
+ "action":"fs",
329
+ "op":"File.upload",
330
+ "data":
331
+ {
332
+ "suffix":suffix #后缀必须写对
333
+ }
334
+ }
335
+ config = {:param => upload_param}
336
+ upload = Testin::TestinNetwork.new(config)
337
+ upload_file_path = ''
338
+ begin
339
+ raise "file does not exist #{@path}" if FileTest::exist?(@path) == false
340
+ puts '**********************start uploading**********************'
341
+ upload_file_path = upload.upload_file(@path)
342
+ puts '**********************end uploading**********************'
343
+ puts 'upload_file_path:' + upload_file_path
344
+ rescue StandardError => e
345
+ raise e.to_s
346
+ end
347
+ upload_file_path
348
+ end
349
+ private :upload_file
350
+
351
+
352
+ #######create task#######
353
+ def create_task_for_normal
354
+ upload_file_path = upload_file
355
+ all_scripts = Testin::TestinNetwork.all_scripts
356
+ raise 'scripts is empty' if all_scripts == nil || all_scripts.length == 0
357
+ puts("all scripts length:#{all_scripts.length}")
358
+ task_param = {
359
+ "apikey": Testin::get_task.get_api_key,
360
+ "timestamp": Time.now.to_i * 1000,
361
+ "sid": self.get_sid,
362
+ "mkey": "realtest",
363
+ "action": "app",
364
+ "op": "Task.add",
365
+ "data": {
366
+ "projectid": self.get_project_id,
367
+ "bizCode": "4001" ,# 4000 自动化兼容测试; 4001 自动化功能测试
368
+ "taskDescr": "autotest" ,
369
+ "appinfo": {
370
+ "syspfId": self.get_os_type, #1:android; 2:ios
371
+ "packageUrl": upload_file_path
372
+ }, # 应用信息
373
+ "devices": @devices,
374
+ "scripts": all_scripts,
375
+ "execStandard": {
376
+ #4000 自动化兼容测试:
377
+ #simple 安装+启动;
378
+ #monkey 安装+启动+monkey;
379
+ #script 安装+执行脚本
380
+ #4001 自动化功能测试:
381
+ #normal 普通执行;
382
+ #fast 快速执行
383
+ "standardType": "normal",
384
+ } # 执行策略
385
+ }
386
+ }
387
+ config = {:param => task_param}
388
+ task = Testin::TestinNetwork.new(config)
389
+ begin
390
+ task.creat_task.to_s
391
+ rescue StandardError => e
392
+ raise e.to_s
393
+ end
394
+ end
395
+
396
+ def create_task_for_fast
397
+ upload_file_path = upload_file
398
+ task_param = {
399
+ "apikey": Testin::get_task.get_api_key,
400
+ "timestamp": Time.now.to_i * 1000,
401
+ "sid": self.get_sid,
402
+ "mkey": "realtest",
403
+ "action": "app",
404
+ "op": "Task.add",
405
+ "data": {
406
+ "projectid": self.get_project_id,
407
+ "bizCode": "4001" ,# 4000 自动化兼容测试; 4001 自动化功能测试
408
+ "taskDescr": "autotest" ,
409
+ "appinfo": {
410
+ "syspfId": self.get_os_type, #1:android; 2:ios
411
+ "packageUrl": upload_file_path
412
+ }, # 应用信息
413
+ "devices": @devices,
414
+ "scripts": Testin::TestinNetwork.all_scripts,
415
+ "execStandard": {
416
+ #4000 自动化兼容测试:
417
+ #simple 安装+启动;
418
+ #monkey 安装+启动+monkey;
419
+ #script 安装+执行脚本
420
+ #4001 自动化功能测试:
421
+ #normal 普通执行;
422
+ #fast 快速执行
423
+ "standardType": "fast",
424
+ } # 执行策略
425
+ }
426
+ }
427
+ config = {:param => task_param}
428
+ task = Testin::TestinNetwork.new(config)
429
+ begin
430
+ task.creat_task.to_s
431
+ rescue StandardError => e
432
+ raise e.to_s
433
+ end
434
+ end
435
+ end
436
+ end
data/testin.gemspec ADDED
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "testin/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "testin"
8
+ spec.version = Testin::VERSION
9
+ spec.authors = ["rudy.li"]
10
+ spec.email = ["ss_lihao@163.com"]
11
+
12
+ spec.summary = %q{testin}
13
+ spec.description = %q{testin plug}
14
+ spec.homepage = "https://github.com/ss-lihao/testin.git"
15
+ spec.license = "MIT"
16
+
17
+
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.17"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: testin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - rudy.li
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: testin plug
56
+ email:
57
+ - ss_lihao@163.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".idea/.rakeTasks"
64
+ - ".idea/testin.iml"
65
+ - ".rspec"
66
+ - ".travis.yml"
67
+ - CODE_OF_CONDUCT.md
68
+ - Gemfile
69
+ - Gemfile.lock
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - bin/console
74
+ - bin/setup
75
+ - fastlane-plugin-testintask/.circleci/config.yml
76
+ - fastlane-plugin-testintask/.gitignore
77
+ - fastlane-plugin-testintask/.rspec
78
+ - fastlane-plugin-testintask/.rubocop.yml
79
+ - fastlane-plugin-testintask/.travis.yml
80
+ - fastlane-plugin-testintask/Gemfile
81
+ - fastlane-plugin-testintask/LICENSE
82
+ - fastlane-plugin-testintask/README.md
83
+ - fastlane-plugin-testintask/Rakefile
84
+ - fastlane-plugin-testintask/fastlane-plugin-testintask.gemspec
85
+ - fastlane-plugin-testintask/fastlane/Fastfile
86
+ - fastlane-plugin-testintask/fastlane/Pluginfile
87
+ - fastlane-plugin-testintask/lib/fastlane/plugin/testintask.rb
88
+ - fastlane-plugin-testintask/lib/fastlane/plugin/testintask/actions/testintask_action.rb
89
+ - fastlane-plugin-testintask/lib/fastlane/plugin/testintask/helper/testintask_helper.rb
90
+ - fastlane-plugin-testintask/lib/fastlane/plugin/testintask/version.rb
91
+ - fastlane-plugin-testintask/spec/spec_helper.rb
92
+ - fastlane-plugin-testintask/spec/testintask_action_spec.rb
93
+ - lib/testin.rb
94
+ - lib/testin/version.rb
95
+ - testin.gemspec
96
+ homepage: https://github.com/ss-lihao/testin.git
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.7.7
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: testin
120
+ test_files: []