Class: Testin::TestinNetwork
Class Method Summary collapse
Instance Method Summary collapse
-
#creat_task ⇒ Object
创建任务.
-
#get_device_list ⇒ Object
获取设备列表.
-
#get_login_token ⇒ Object
登录获取token.
-
#get_project_list ⇒ Object
获取项目列表.
-
#get_script_list ⇒ Object
获取脚本列表.
-
#upload_file(file_name) ⇒ Object
上传文件.
Methods inherited from Network
#initialize, #request, testin_hostname, #validation_response
Constructor Details
This class inherits a constructor from Testin::Network
Class Method Details
.all_scripts ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 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 |
# File 'lib/testin.rb', line 165 def self.all_scripts () start_page_no = 1 array = [] while #######获取脚本####### script_param = { 'apikey': Testin::get_task.get_api_key, 'mkey': 'script', 'sid':Testin::get_task.get_sid, 'op': 'Script.listScriptFile', 'action': 'script', 'timestamp': Time.now.to_i * 1000, 'data': { 'scriptDesc': '', 'appId': 0, 'startPageNo': start_page_no, 'osType': Testin::get_task.get_os_type, 'pageSize': 15, 'projectId': Testin::get_task.get_project_id } } config = {:param => script_param} script = Testin::TestinNetwork.new(config) begin script_array = script.get_script_list break if script_array == nil || script_array.length == 0 scripts = script_array.inject([]) do |r, e| 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 r end if scripts.length > 0 array = array + scripts end start_page_no += 1 rescue StandardError => e raise e.to_s end end array.uniq end |
Instance Method Details
#creat_task ⇒ Object
创建任务
155 156 157 158 159 160 161 162 163 |
# File 'lib/testin.rb', line 155 def creat_task begin info = request.body info = JSON.parse(info) validation_response info raise 'Error CREAT_TASK' if info['data']['result'].empty? info['data'] end end |
#get_device_list ⇒ Object
获取设备列表
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/testin.rb', line 116 def get_device_list begin info = request.body info = JSON.parse(info) validation_response info raise 'Error FetchDeviceNetwork' if info['data']['list'].empty? info['data']['list'] rescue StandardError => e raise e.to_s end end |
#get_login_token ⇒ Object
登录获取token
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/testin.rb', line 68 def get_login_token begin info = request.body info = JSON.parse(info) validation_response info raise 'Error Login' if info['data']['result'].empty? info['data']['result'] rescue StandardError => e raise e.to_s end end |
#get_project_list ⇒ Object
获取项目列表
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/testin.rb', line 95 def get_project_list begin info = request.body info = JSON.parse(info) validation_response info raise 'Error FetchProjectNetWork' if info['data']['list'].empty? end begin arr = info['data']['list'].inject([]) do |r, e| r << e['projectid'] if e['name'] == Testin::get_task.get_project_name r end raise "Project #{Testin::get_task.get_project_name} is empty" if arr.empty? arr[0] end end |
#get_script_list ⇒ Object
获取脚本列表
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/testin.rb', line 81 def get_script_list begin info = request.body info = JSON.parse(info) validation_response info raise 'Error FetchScriptNetwork' if info['data']['list'].empty? info['data']['list'] rescue StandardError => e #raise e.to_s puts(e.to_s) end end |
#upload_file(file_name) ⇒ Object
上传文件
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/testin.rb', line 129 def upload_file(file_name) conn = Faraday.new(self.class.testin_hostname,@conn_options) do |c| c.request :multipart c.adapter :net_http c.response :json, :content_type => /\bjson$/ end response = conn.post do |req| req.headers['Host'] = 'openapi.pro.testin.cn' req.headers['Transfer-Encoding'] = 'chunked' req.headers['Content-Type'] = 'application/octet-stream' req.headers['UPLOAD-JSON'] = @options[:param].to_json req.body = Faraday::UploadIO.new(file_name, 'application/octet-stream') end begin info = response.body info = JSON.parse(info) validation_response info raise 'Error UPLOAD_FILE' if info['data']['result'].empty? info['data']['result'] end end |