Ruby_AppThwack 0.0.8 → 0.0.8.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0231d4e43df05a72e4183412e4e260f4621c3de2
4
- data.tar.gz: 7434bcec5bd022443438ff85ac4db229bb6729d4
3
+ metadata.gz: 0cd4b08a721c892c9ded4ac4fb7d74cf0ac3db06
4
+ data.tar.gz: ebca17f72f26570c02dadf6039a9efefd6653b5b
5
5
  SHA512:
6
- metadata.gz: 0dfcc92bacb3f368a8d7b22af7856c4e1c25ffad2db115f7c4f74225fa2175b34c6819961f50810f8d94453b397e845b58bbdb861402993d0c17b255e504e8e4
7
- data.tar.gz: 25d1fe040f1be17dad913da85396749d4a9196ec52d19ef405bd511b75ace54f1db592a9d847132296e6824151fa0ee2105241e227bba20e851f2a46f78eb4f5
6
+ metadata.gz: 15e64edbca5b30dcbdc3c4cb0ad279b07a0e1e35ef664e945ae9d28544505eb62a0c7f54072f58c7b290fa3a60f8a89fab58bb2fae39917f683a41693409be03
7
+ data.tar.gz: 25789f0f34188d3b3554dacbde5896e33c70e74f82ce9da0defca7c06c1d5948e6b513b7ebdec293e35b6a53b98e3431ed91ffdb8213d834ab6c31b13e327af2
@@ -0,0 +1,102 @@
1
+
2
+ require 'ostruct'
3
+ require "json"
4
+ require "typhoeus"
5
+
6
+ module AppThwack::API
7
+
8
+ class << self
9
+ def get_project_id(name)
10
+ res =
11
+ JSON.parse(
12
+ Typhoeus.get(
13
+ "https://appthwack.com/api/project/",
14
+ userpwd: "#{ENV['APPTHWACK_API_KEY']}:"
15
+ ).body
16
+ )
17
+
18
+ return (res.select { |project| project['name'].eql? name }).first['id']
19
+ end
20
+
21
+ def get_device_pool(proj_id, name)
22
+
23
+ res =
24
+ JSON.parse(
25
+ Typhoeus.get(
26
+ "https://appthwack.com/api/devicepool/#{proj_id}",
27
+ userpwd: "#{ENV['APPTHWACK_API_KEY']}:"
28
+ ).body
29
+ )
30
+
31
+ return (res.select { |pool| pool['name'].eql? name }).first['id']
32
+ end
33
+
34
+
35
+ def download_file(src, dst)
36
+ # We use curl to download the file to avoid running out of RAM
37
+ return dst if system "curl -X GET '#{src}' -o '#{dst}' --silent"
38
+ end
39
+
40
+ def upload_file(src)
41
+ f = Dir.glob( src ).first
42
+
43
+ res = JSON.parse(
44
+ Typhoeus.post(
45
+ "https://appthwack.com/api/file",
46
+ userpwd: "#{ENV['APPTHWACK_API_KEY']}:",
47
+ params: {
48
+ name: File.basename(f)
49
+ },
50
+ body: {
51
+ file: File.open(f,"r")
52
+ }
53
+ ).body
54
+ )
55
+
56
+ return { :file_id => res["file_id"], :succeeded? => res['message'].nil?, :message => res['message'] }
57
+ end
58
+
59
+ def start_test(name, proj_id, app_id, pool_id, params = {})
60
+
61
+ params.merge! project: proj_id, name: name, app: app_id, pool: pool_id
62
+
63
+ res = JSON.parse(
64
+ Typhoeus.post(
65
+ "https://appthwack.com/api/run",
66
+ userpwd: "#{ENV['APPTHWACK_API_KEY']}:",
67
+ params: params
68
+ ).body
69
+ )
70
+
71
+ return { :run_id => res['run_id'], :succeeded? => res['message'].nil?, :message => res['message'] }
72
+ end
73
+
74
+ def test_status?(proj_id, run_id)
75
+ res = JSON.parse(
76
+ Typhoeus.get(
77
+ "https://appthwack.com/api/run/#{proj_id}/#{run_id}/status",
78
+ userpwd: "#{ENV['APPTHWACK_API_KEY']}:",
79
+ ).body
80
+ )
81
+
82
+ return res['status']
83
+ end
84
+
85
+ def test_running?(proj_id, run_id)
86
+ return test_status?( proj_id, run_id ) != 'completed'
87
+ end
88
+
89
+ def download_results(proj_id, run_id, output)
90
+
91
+ resp = Typhoeus.get(
92
+ "https://appthwack.com/api/run/#{proj_id}/#{run_id}",
93
+ userpwd: "#{ENV['APPTHWACK_API_KEY']}:",
94
+ params: {
95
+ format: "archive"
96
+ }
97
+ )
98
+
99
+ return ( download_file resp.headers_hash['Location'], output ) if resp.code == 303
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,13 @@
1
+ command :convert do |c|
2
+ c.syntax = 'appthwack convert [options]'
3
+ c.option '--reports STRING', String, 'Location of reports folder.'
4
+ c.option '--platform STRING', String, 'Platform of tests.'
5
+ c.summary = 'Converts the AppThwack results into something readable for the Jenkins'
6
+ c.description = ''
7
+
8
+ c.action do |args, options|
9
+ dst = AppThwack::Reports.convert_reports options.reports, options.platform
10
+
11
+ say_ok "Converted reports to #{dst}"
12
+ end
13
+ end
@@ -0,0 +1,33 @@
1
+ command :reports do |c|
2
+ c.syntax = 'appthwack reports [arguments]'
3
+ c.summary = 'Downloads reports and tidies reports'
4
+ c.description = ''
5
+
6
+ c.option '--project PROJECT', 'The project name of the running tests'
7
+ c.option '--runid INT', 'The run ID of the test'
8
+ c.option '--platform PLATFORM', 'The mobile platform of the app under test'
9
+ c.option '--reports REPORTS', 'The location of the downloaded reports'
10
+
11
+ c.action do |args, options|
12
+ say_error 'Need project name and run ID' if options.runid.nil? or options.project.nil?
13
+
14
+ options.proj_id = AppThwack::API.get_project_id(options.project)
15
+
16
+ say_ok "Project ID: #{options.proj_id}"
17
+
18
+ status = AppThwack::API.test_status? options.proj_id, options.runid
19
+
20
+ say_error 'Project is not finished' unless status.eql? 'completed'
21
+
22
+ say_ok 'Downloading reports...'
23
+
24
+ reports = AppThwack::API.download_results options.proj_id, options.runid, options.reports
25
+
26
+ say_ok "Downloaded raw reports to #{reports}"
27
+
28
+ reports = AppThwack::Reports.extract_reports reports
29
+
30
+ say_ok "Extracted reports to #{reports}"
31
+
32
+ end
33
+ end
@@ -0,0 +1,88 @@
1
+ command :run do |c|
2
+ c.syntax = 'appthwack run [options]'
3
+ c.summary = 'Packages tests and pushes them to AppThwack for Running'
4
+ c.description = ''
5
+
6
+ c.option '--platform PLATFORM', 'The platform of the application under test'
7
+ c.option '--project PROJECT', 'Name of AppThwack project'
8
+ c.option '--devices DEVICES', 'Name of device pool to use'
9
+ c.option '--testtype TYPE', 'Scheme used to build iOS app'
10
+ c.option '--app TEST', 'Path of the application (can be Glob syntax)'
11
+ c.option '--test TEST', 'Path of the test package'
12
+ c.option '--wait', 'Wait for the tests to complete'
13
+ c.option '--scheme SCHEME', 'XCode scheme for packaging the IPA'
14
+ c.option '--results STRING', String, 'Location of downloaded results.'
15
+
16
+
17
+ c.action do |args, options|
18
+
19
+ options.proj_id = AppThwack::API.get_project_id options.project
20
+ options.pool_id = AppThwack::API.get_device_pool options.proj_id, options.devices
21
+
22
+ say_ok "Project ID: #{options.proj_id}"
23
+ say_ok "Pool ID: #{options.pool_id}"
24
+
25
+ # Feature: list of tests to include via command line?
26
+ if options.testtype.eql? 'calabash'
27
+ options.test = AppThwack::Packaging.create_calabash_package options.proj_id, options.test
28
+ end
29
+
30
+ # if the platform is iOS, make an IPA before building
31
+ if options.platform.eql? 'ios'
32
+ options.app = AppThwack::Packaging.create_ipa(options.scheme)
33
+ end
34
+
35
+ # start by uploading the app
36
+ options.app_id = (AppThwack::API.upload_file options.app)[:file_id]
37
+ say_ok "App package ID: #{options.app_id}"
38
+
39
+ exit 3 if options.app_id.nil?
40
+
41
+ # now upload the test package
42
+ options.test_id = (AppThwack::API.upload_file options.test)[:file_id]
43
+
44
+ say_ok "Test packagae ID: #{options.test_id}"
45
+
46
+ exit 4 if options.test_id.nil?
47
+
48
+ params = {}
49
+
50
+ params['calabash'] = { calabash: options.test_id }
51
+
52
+ params['junit'] = { junit: options.test_id }
53
+
54
+ result = AppThwack::API.start_test(
55
+ File.basename(Dir.glob(options.app).first) + ' -- CLI',
56
+ options.proj_id,
57
+ options.app_id,
58
+ options.pool_id,
59
+ params[options.testtype]
60
+ )
61
+
62
+ options.run_id = result[:run_id]
63
+
64
+ say_ok "Run ID: #{options.run_id} with message: #{result[:message]}"
65
+
66
+ exit 5 if options.run_id.nil?
67
+
68
+ sleep 5
69
+
70
+ print "\n"
71
+
72
+ # wait for test to terminate
73
+ until not AppThwack::API.test_running? options.proj_id, options.run_id or not options.wait
74
+ print "."
75
+ sleep 30
76
+ end
77
+
78
+ print "\n"
79
+
80
+ # download the results if we waited..
81
+ if options.results and options.wait
82
+ `appthwack reports --project #{options.project} --runid #{options.run_id} --platform #{options.platform} --reports #{options.results}`
83
+ end
84
+
85
+ say_ok "Tests started successfully"
86
+
87
+ end
88
+ end
@@ -0,0 +1,15 @@
1
+ command :status do |c|
2
+ c.syntax = 'appthwack status [arguments]'
3
+ c.summary = 'Check on the status of a running test'
4
+ c.description = ''
5
+
6
+ c.option '--project PROJECT', 'The project name of the running tests'
7
+ c.option '--runid INT', 'The run ID of the test'
8
+
9
+
10
+ c.action do |args, options|
11
+ say_error 'Need project and run ID' if options.runid.nil? or options.project.nil?
12
+
13
+ puts AppThwack::API.test_status? AppThwack::API.get_project_id(options.project), options.runid
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ $:.push File.expand_path('../', __FILE__)
2
+
3
+ require 'commands/status'
4
+ require 'commands/run'
5
+ require 'commands/report'
6
+ require 'commands/convert'
@@ -0,0 +1,31 @@
1
+
2
+ module AppThwack::Packaging
3
+
4
+ class << self
5
+ def create_ipa(scheme)
6
+ #uses Shenzhen gem
7
+ abort unless system "ipa build --scheme #{scheme} --configuration Release --no-archive"
8
+
9
+ return Dir.glob('*.ipa').first
10
+ end
11
+
12
+ def create_calabash_package proj_id, src, opts = {}
13
+ o = { :include_tests=> ["*.feature"], :exclude_tests=> nil}.merge opts
14
+
15
+ # create the archive if it doesn't already exist
16
+ unless File.extname(src) == '.zip'
17
+ # delete any old archives we have laying about
18
+ File.delete(src + '.zip') if File.exists?(src + '.zip')
19
+
20
+ included = (o[:include_tests].map { |t| "'#{src}/#{t}'"}).join(' ')
21
+ excluded = if o[:exclude_tests]; "-x #{ (o[:exclude_tests].map { |t| "'#{calabash}/#{t}'"}).join(' ') }" else "" end
22
+
23
+ `zip #{src}.zip #{src} . -r #{excluded} -i '#{src}/support/*' '#{src}/step_definitions/*' #{included}`
24
+ end
25
+
26
+ src << '.zip'
27
+
28
+ return src
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,73 @@
1
+ require 'json'
2
+ require 'pp'
3
+
4
+ module AppThwack::Reports
5
+ class << self
6
+
7
+ def extract_reports(reports)
8
+ # make new folder name by chopping off .zip file
9
+ out = reports.sub('.zip', '')
10
+ # unzip then return the new folder name
11
+ out if system "rm -rf #{out} && unzip -qq #{reports} -d #{out}"
12
+ end
13
+
14
+ # Converts Android reports into results readable by Cucumber plugin.
15
+ # You should pass in the folder locatino of the reports
16
+ def convert_reports(reports, platform='android')
17
+ # default to android folder
18
+ intermediate_folders = 'calabash_tests_from_features.zip'
19
+
20
+ dst = 'cucumber-html-reports'
21
+
22
+ # unless platform is explicitly ios
23
+ if platform.eql? 'ios'
24
+ intermediate_folders = 'calabash'
25
+ end
26
+
27
+ folders = Dir["#{reports}/*"]
28
+
29
+ # extract for each of the devices
30
+ folders.each do |f|
31
+
32
+ # capitalize every word
33
+ device = f.gsub('_', ' ').split.map(&:capitalize).join(' ')
34
+
35
+ report = File.join(f, intermediate_folders, 'raw_calabash_json_output.instrtxt')
36
+
37
+ if File.exists? report
38
+ features = []
39
+
40
+
41
+ # now we just add the device prefix to each feature name to make it unique
42
+ File.open(report, 'r') do |io|
43
+
44
+ features = JSON.load(io)
45
+
46
+ if not features.nil?
47
+
48
+ features.each_index do |i|
49
+ # append the device name to the feature name
50
+ features[i]['name'] = "#{features[i]['name']} on #{device}"
51
+ end
52
+ end
53
+
54
+ Dir.mkdir dst if not Dir.exists? dst
55
+
56
+ # original folder name
57
+ folder_name = f.sub(reports + "/", '')
58
+
59
+ # now write out the new file
60
+ File.open(File.join(dst, "#{Time.now.to_i}_#{folder_name}.json"), 'w') do |io|
61
+ JSON.dump(features, io) unless features.nil?
62
+
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ dst
69
+ end
70
+
71
+
72
+ end
73
+ end
@@ -1,5 +1,5 @@
1
1
  module AppThwack
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.8.1'
3
3
  end
4
4
 
5
5
  require'ruby_appthwack/reports.rb'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Ruby_AppThwack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Stewart
@@ -144,6 +144,14 @@ extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
146
  - lib/ruby_appthwack.rb
147
+ - lib/ruby_appthwack/appthwack_api.rb
148
+ - lib/ruby_appthwack/commands.rb
149
+ - lib/ruby_appthwack/packaging.rb
150
+ - lib/ruby_appthwack/reports.rb
151
+ - lib/ruby_appthwack/commands/convert.rb
152
+ - lib/ruby_appthwack/commands/report.rb
153
+ - lib/ruby_appthwack/commands/run.rb
154
+ - lib/ruby_appthwack/commands/status.rb
147
155
  - bin/appthwack
148
156
  homepage: https://github.com/samstewart/ruby_appthwack
149
157
  licenses: []