lib/calabash-android/operations.rb in calabash-android-0.5.13.pre1 vs lib/calabash-android/operations.rb in calabash-android-0.5.14
- old
+ new
@@ -395,10 +395,29 @@
log "It looks like your app is no longer running. \nIt could be because of a crash or because your test script shut it down."
raise e
end
end
+ def http_put(path, data = {}, options = {})
+ begin
+
+ configure_http(@http, options)
+ make_http_request(
+ :method => :put,
+ :body => data,
+ :uri => url_for(path),
+ :header => {"Content-Type" => "application/octet-stream"})
+
+ rescue HTTPClient::TimeoutError,
+ HTTPClient::KeepAliveDisconnected,
+ Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ECONNABORTED,
+ Errno::ETIMEDOUT => e
+ log "It looks like your app is no longer running. \nIt could be because of a crash or because your test script shut it down."
+ raise e
+ end
+ end
+
def set_http(http)
@http = http
end
def url_for(method)
@@ -425,10 +444,12 @@
options[:header] = header
response = if options[:method] == :post
@http.post(options[:uri], options)
+ elsif options[:method] == :put
+ @http.put(options[:uri], options)
else
@http.get(options[:uri], options)
end
raise Errno::ECONNREFUSED if response.status_code == 502
response.body
@@ -841,9 +862,27 @@
puts 'Warning: This predefined step is deprecated.'
end
def http(path, data = {}, options = {})
default_device.http(path, data, options)
+ end
+
+ def http_put(path, data = {}, options = {})
+ default_device.http_put(path, data, options)
+ end
+
+ # @return [String] The path of the uploaded file on the device
+ def upload_file(file_path)
+ name = File.basename(file_path)
+ device_tmp_path = http_put('/add-file', File.binread(file_path))
+ http('/move-cache-file-to-public', {from: device_tmp_path, name: name})
+ end
+
+ # @param [String] file_path Path of the file to load (.apk or .jar)
+ # @param [Array<String>] classes A list of classes to load from the file
+ def load_dylib(file_path, classes = [])
+ uploaded_file = upload_file(file_path)
+ http('/load-dylib', {path: uploaded_file, classes: classes})
end
def html(q)
query(q).map {|e| e['html']}
end