testdroid-api-client 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,9 @@
1
1
  module TestdroidAPI
2
- class Config < CloudResource
3
- def initialize(uri, client, params={})
4
- super uri, client,"config", params
5
- @uri, @client = uri, client
6
- sub_items :parameters
7
- end
8
- end
2
+ class Config < CloudResource
3
+ def initialize(uri, client, params={})
4
+ super uri, client, "config", params
5
+ @uri, @client = uri, client
6
+ sub_items :parameters
7
+ end
8
+ end
9
9
  end
@@ -1,12 +1,11 @@
1
-
2
1
  module TestdroidAPI
3
- class DeviceGroups < CloudListResource
4
- end
5
- class DeviceGroup < CloudResource
6
- def initialize(uri, client, params= {})
7
- super uri, client,"deviceGroup", params
8
- @uri, @client = uri, client
9
- end
2
+ class DeviceGroups < CloudListResource
3
+ end
4
+ class DeviceGroup < CloudResource
5
+ def initialize(uri, client, params= {})
6
+ super uri, client, "deviceGroup", params
7
+ @uri, @client = uri, client
8
+ end
10
9
 
11
- end
10
+ end
12
11
  end
@@ -1,18 +1,20 @@
1
-
2
1
  module TestdroidAPI
3
2
  class DeviceRuns < CloudListResource
4
3
  end
5
4
  class DeviceRun < CloudResource
6
5
  def initialize(uri, client, params= {})
7
- super uri, client,"deviceRun", params
6
+ super uri, client, "deviceRun", params
8
7
  @uri, @client = uri, client
9
8
  end
9
+
10
10
  def download_performance(file_name="performance_data.txt")
11
11
  @client.download("#{@uri}/performance", file_name)
12
12
  end
13
+
13
14
  def download_junit(file_name="junit.xml")
14
15
  @client.download("#{@uri}/junit.xml", file_name)
15
16
  end
17
+
16
18
  def download_logs(file_name="log.txt")
17
19
  @client.download("#{@uri}/logs", file_name)
18
20
  end
@@ -0,0 +1,10 @@
1
+ module TestdroidAPI
2
+ class DeviceSessionConnections < CloudListResource
3
+ end
4
+ class DeviceSessionConnection < CloudResource
5
+ def initialize(uri, client, params= {})
6
+ super uri, client, "DeviceSessionConnection", params
7
+ @uri, @client = uri, client
8
+ end
9
+ end
10
+ end
@@ -1,14 +1,14 @@
1
-
2
1
  module TestdroidAPI
3
- class DeviceSessions < CloudListResource
4
- end
5
- class DeviceSession < CloudResource
6
- def initialize(uri, client, params= {})
7
- super uri, client,"deviceSession", params
8
- @uri, @client = uri, client
9
- end
10
- def release
11
- resp = @client.post("#{@uri}/release", params= {})
12
- end
13
- end
2
+ class DeviceSessions < CloudListResource
3
+ end
4
+ class DeviceSession < CloudResource
5
+ def initialize(uri, client, params= {})
6
+ super uri, client, "deviceSession", params
7
+ @uri, @client = uri, client
8
+ end
9
+
10
+ def release
11
+ resp = @client.post("#{@uri}/release", params= {})
12
+ end
13
+ end
14
14
  end
@@ -1,13 +1,10 @@
1
-
2
1
  module TestdroidAPI
3
- class Devices < CloudListResource
4
- end
5
- class Device < CloudResource
6
- def initialize(uri, client, params= {})
7
- super uri, client,"device", params
8
- @uri, @client = uri, client
9
-
10
- end
11
-
12
- end
2
+ class Devices < CloudListResource
3
+ end
4
+ class Device < CloudResource
5
+ def initialize(uri, client, params= {})
6
+ super uri, client, "device", params
7
+ @uri, @client = uri, client
8
+ end
9
+ end
13
10
  end
@@ -1,12 +1,11 @@
1
-
2
1
  module TestdroidAPI
3
- class FileSets < CloudListResource
2
+ class FileSets < CloudListResource
3
+ end
4
+ class FileSet < CloudResource
5
+ def initialize(uri, client, params= {})
6
+ super uri, client, "fileSet", params
7
+ @uri, @client = uri, client
8
+ sub_items :files
4
9
  end
5
- class FileSet < CloudResource
6
- def initialize(uri, client, params= {})
7
- super uri, client,"fileSet", params
8
- @uri, @client = uri, client
9
- sub_items :files
10
- end
11
- end
10
+ end
12
11
  end
@@ -1,60 +1,59 @@
1
-
2
1
  module TestdroidAPI
3
- class Files < CloudResource
4
- def initialize(uri, client, params= {})
5
-
6
- super uri, client,"files", params
7
- @uri, @client = uri, client
8
-
9
- end
10
-
11
- def uploadApplication(filename, mime_type = "application/vnd.android.package-archive")
12
- if !File.exist?(filename)
13
- @client.logger.error( "Invalid filename")
14
- return
15
- end
16
- reply = @client.upload("#{@uri}/application", filename, mime_type)
17
-
18
- Application.new(nil, nil, reply)
19
- end
20
- def uploadData(filename, mime_type = "application/zip")
21
- if !File.exist?(filename)
22
- @client.logger.error( "Invalid filename")
23
- return
24
- end
25
- reply = @client.upload("#{@uri}/data", filename, mime_type)
26
-
27
- Data.new(nil, nil, reply)
28
- end
29
- def uploadTest(filename, mime_type = "application/vnd.android.package-archive")
30
- if !File.exist?(filename)
31
- @client.logger.error( "Invalid filename")
32
- return
33
- end
34
- reply = @client.upload("#{@uri}/test", filename, mime_type)
35
-
36
- Test.new(nil, nil, reply)
37
- end
38
- end
39
- class Application < CloudResource
40
- def initialize(uri, client, params= {})
41
- super uri, client,"app", params
42
- @uri, @client = uri, client
43
-
44
- end
45
- end
46
- class Test < CloudResource
47
- def initialize(uri, client, params= {})
48
- super uri, client,"test", params
49
- @uri, @client = uri, client
50
-
51
- end
52
- end
53
- class Data < CloudResource
54
- def initialize(uri, client, params= {})
55
- super uri, client,"data", params
56
- @uri, @client = uri, client
57
-
58
- end
59
- end
2
+ class Files < CloudResource
3
+ def initialize(uri, client, params= {})
4
+ super uri, client, "files", params
5
+ @uri, @client = uri, client
6
+ end
7
+
8
+ def uploadApplication(filename)
9
+ if !File.exist?(filename)
10
+ @client.logger.error("Invalid filename")
11
+ return
12
+ end
13
+ reply = @client.upload("#{@uri}/application", filename)
14
+
15
+ Application.new(nil, nil, reply)
16
+ end
17
+
18
+ def uploadData(filename)
19
+ if !File.exist?(filename)
20
+ @client.logger.error("Invalid filename")
21
+ return
22
+ end
23
+ reply = @client.upload("#{@uri}/data", filename)
24
+
25
+ Data.new(nil, nil, reply)
26
+ end
27
+
28
+ def uploadTest(filename)
29
+ if !File.exist?(filename)
30
+ @client.logger.error("Invalid filename")
31
+ return
32
+ end
33
+ reply = @client.upload("#{@uri}/test", filename)
34
+
35
+ Test.new(nil, nil, reply)
36
+ end
37
+ end
38
+ class Application < CloudResource
39
+ def initialize(uri, client, params= {})
40
+ super uri, client, "app", params
41
+ @uri, @client = uri, client
42
+
43
+ end
44
+ end
45
+ class Test < CloudResource
46
+ def initialize(uri, client, params= {})
47
+ super uri, client, "test", params
48
+ @uri, @client = uri, client
49
+
50
+ end
51
+ end
52
+ class Data < CloudResource
53
+ def initialize(uri, client, params= {})
54
+ super uri, client, "data", params
55
+ @uri, @client = uri, client
56
+
57
+ end
58
+ end
60
59
  end
@@ -1,13 +1,12 @@
1
-
2
1
  module TestdroidAPI
3
- class LabelGroups < CloudListResource
4
- end
5
- class LabelGroup < CloudResource
6
- def initialize(uri, client, params= {})
7
- super uri, client,"labelGroup", params
8
- @uri, @client = uri, client
9
- sub_items :labels
10
- end
2
+ class LabelGroups < CloudListResource
3
+ end
4
+ class LabelGroup < CloudResource
5
+ def initialize(uri, client, params= {})
6
+ super uri, client, "labelGroup", params
7
+ @uri, @client = uri, client
8
+ sub_items :labels
9
+ end
11
10
 
12
- end
11
+ end
13
12
  end
@@ -1,13 +1,12 @@
1
-
2
1
  module TestdroidAPI
3
- class Labels < CloudListResource
4
- end
5
- class Label < CloudResource
6
- def initialize(uri, client, params= {})
7
- super uri, client,"label", params
8
- @uri, @client = uri, client
9
- sub_items :devices
10
- end
2
+ class Labels < CloudListResource
3
+ end
4
+ class Label < CloudResource
5
+ def initialize(uri, client, params= {})
6
+ super uri, client, "label", params
7
+ @uri, @client = uri, client
8
+ sub_items :devices
9
+ end
11
10
 
12
- end
11
+ end
13
12
  end
@@ -1,11 +1,10 @@
1
-
2
1
  module TestdroidAPI
3
- class Parameters < CloudListResource
4
- end
5
- class Parameter < CloudResource
6
- def initialize(uri, client, params= {})
7
- super uri, client,"parameter", params
8
- end
2
+ class Parameters < CloudListResource
3
+ end
4
+ class Parameter < CloudResource
5
+ def initialize(uri, client, params= {})
6
+ super uri, client, "parameter", params
7
+ end
9
8
 
10
- end
9
+ end
11
10
  end
@@ -1,21 +1,19 @@
1
-
2
1
  module TestdroidAPI
3
- class Projects < CloudListResource
4
- end
2
+ class Projects < CloudListResource
3
+ end
5
4
 
6
- class Project < CloudResource
5
+ class Project < CloudResource
7
6
 
8
- def initialize(uri, client, params= {})
9
- super uri, client,"project", params
10
- @uri, @client = uri, client
11
- sub_items :runs, :files, :config
12
- end
13
- #Start a new test run
14
- #run_parameters - example {:params => {'name' => 'test'}}
15
- def run(run_parameters={:params => {}})
16
- resp = @client.post("#{@uri}/runs", run_parameters)
17
- Run.new("#{@uri}/runs/#{resp['id']}", @client, resp)
18
- end
7
+ def initialize(uri, client, params= {})
8
+ super uri, client, "project", params
9
+ @uri, @client = uri, client
10
+ sub_items :runs, :files, :config
11
+ end
19
12
 
13
+ def run(run_parameters = {})
14
+ resp = @client.post("#{@uri}/runs", run_parameters)
15
+ Run.new("#{@uri}/runs/#{resp['id']}", @client, resp)
20
16
  end
17
+
18
+ end
21
19
  end
@@ -0,0 +1,13 @@
1
+ module TestdroidAPI
2
+ class Properties < CloudListResource
3
+ def initialize(uri, client)
4
+ super uri, client, "Property"
5
+ end
6
+ end
7
+ class Property < CloudResource
8
+ def initialize(uri, client, params= {})
9
+ super uri, client, "property", params
10
+ end
11
+
12
+ end
13
+ end
@@ -1,14 +1,15 @@
1
1
  module TestdroidAPI
2
- class Runs < CloudListResource
3
- end
4
- class Run < CloudResource
5
- def initialize(uri, client, params= {})
6
- super uri, client,"run", params
7
- @uri, @client = uri, client
8
- sub_items :device_runs
9
- end
10
- def abort()
11
- resp = @client.post("#{@uri}/abort", params= {})
12
- end
13
- end
2
+ class Runs < CloudListResource
3
+ end
4
+ class Run < CloudResource
5
+ def initialize(uri, client, params= {})
6
+ super uri, client, "run", params
7
+ @uri, @client = uri, client
8
+ sub_items :device_runs
9
+ end
10
+
11
+ def abort()
12
+ @client.post("#{@uri}/abort", params= {})
13
+ end
14
+ end
14
15
  end
@@ -0,0 +1,18 @@
1
+ module TestdroidAPI
2
+ class Services < CloudListResource
3
+ end
4
+ class Service < CloudResource
5
+ def initialize(uri, client, params= {})
6
+ super uri, client, "service", params
7
+ end
8
+
9
+ def get_available
10
+ @client.get("#{@uri}/available")
11
+ end
12
+
13
+ def get_purchased
14
+ @client.get("#{@uri}/purchased")
15
+ end
16
+
17
+ end
18
+ end
@@ -1,8 +1,8 @@
1
1
  module TestdroidAPI
2
- class User < CloudResource
3
- def initialize(uri, client, params={})
4
- super uri, client,"users", params
5
- sub_items :projects, :device_groups, :device_sessions, :file_sets
6
- end
7
- end
2
+ class User < CloudResource
3
+ def initialize(uri, client, params={})
4
+ super uri, client, "users", params
5
+ sub_items :projects, :device_groups, :device_sessions, :file_sets
6
+ end
7
+ end
8
8
  end
@@ -1,26 +1,26 @@
1
1
  require 'testdroid-api-client'
2
2
 
3
- client = TestdroidAPI::Client.new('admin@localhost', 'admin')
3
+ #client = TestdroidAPI::Client.new(ENV['TESTDROID_USERNAME'],ENV['TESTDROID_PASSWORD'])
4
+ #or using api key:
5
+ client = TestdroidAPI::ApikeyClient.new(ENV['TESTDROID_APIKEY'])
4
6
  #to use private cloud specify cloud url as:
5
- #client = TestdroidAPI::Client.new('my@host.com', 'hostpass', 'https://customer.testdroid.com/cloud')
6
- #oauth
7
+ #client = TestdroidAPI::Client.new('API_KEY', 'https://customer.testdroid.com')
7
8
  user = client.authorize
8
9
 
9
10
  # Create Android project
10
- android_project = user.projects.create({:params => {:name => "Android robotium", :type => "ANDROID"}})
11
+ android_project = user.projects.create({:name => "Android robotium", :type => "ANDROID"})
11
12
 
12
13
  # Create iOS project
13
- ios_project = user.projects.create({:params => {:name => "iOS project", :type => "IOS"}})
14
+ ios_project = user.projects.create({:name => "iOS project", :type => "IOS"})
14
15
 
15
16
  #Android applicaiton
16
- android_project.files.uploadApplication("BitbarSampleApp.apk")
17
+ file_app = android_project.files.uploadApplication("BitbarSampleApp.apk")
17
18
 
18
19
  #instrumentation package
19
- android_project.files.uploadTest("BitbarSampleAppTests.apk")
20
-
20
+ file_test = android_project.files.uploadTest("BitbarSampleAppTest.apk")
21
21
 
22
22
  #Set custom runner and set mode for instrumentaiton test
23
- android_project.config.update({:params => {'instrumentationRunner' => 'com.testrunners.MyRunner', :mode=> 'FULL_RUN'}})
23
+ android_project.config.update({'instrumentationRunner' => 'com.testrunners.MyRunner', :mode=> 'FULL_RUN'})
24
24
 
25
25
  #get all the Android devices
26
26
  android_devices = client.devices.list.select {|device| device.os_type.casecmp("ANDROID") == 0 }
@@ -28,7 +28,12 @@ android_devices = client.devices.list.select {|device| device.os_type.casecmp("A
28
28
  #get IDs of the android devices
29
29
  id_list = android_devices.collect{|device| device.id }
30
30
 
31
- run_parameters = {:params => {:name => 'Test run 1', "usedDeviceIds[]" => id_list.join(',') }}
31
+ run_parameters = {
32
+ :name => 'Test run 1',
33
+ "usedDeviceIds[]" => id_list.join(','),
34
+ :appFileId => file_app.id,
35
+ :testFileId => file_test.id
36
+ }
32
37
  #Run project using the parameters
33
38
  android_project.run(run_parameters)
34
39
 
@@ -36,4 +41,4 @@ android_project.run(run_parameters)
36
41
  sleep 20 until android_project.runs.list.first.state == "FINISHED"
37
42
 
38
43
  #download junit xml from the all device runs
39
- android_project.runs.list.first.device_runs.list({:params => {:limit => 0}}).each { |device_run| device_run.download_junit("#{device_run.id}_junit.xml") }
44
+ android_project.runs.list.first.device_runs.list({:limit => 0}).each { |device_run| device_run.download_junit("#{device_run.id}_junit.xml") }