flaky 0.0.17 → 0.0.18

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: 114eb59e36a70bf9654f2ff5b456325bdff0ab70
4
- data.tar.gz: 3e201be6fc05c9d2786067aa7971d9dfe48b432b
3
+ metadata.gz: 1230df6faa06f97954248aa5ecdce8c96ad43495
4
+ data.tar.gz: e1af21e3f6f1f43893ae8d5305253299f095d6ae
5
5
  SHA512:
6
- metadata.gz: 13e0202fd081788b1c49d3ce80454ecf606e2408711b113f86f7215d96526991ddaa5ee3b052e4b9ee1e4b863b2a16ac3f0fab0086c77623ff6f04071f611f47
7
- data.tar.gz: 1a123780cacd99a3f9af0da8ea64b303558336c0629e793b76d5e59b7c8c0529967cf0e628c0cd8f899f7c2282784b3d5f78bfe3cc56912736d1302fceef5f67
6
+ metadata.gz: 1b9041b34ae739d33093955b91379a0e0571d7a2f24c8df9570eaf97952c2635f779f994bd4ed529279be39c08686fc8ab18da7eca934d45fee5c17f173afcc0
7
+ data.tar.gz: c314d8c08a8d2544ffaa1e80ae6edbf6647a2825bcd83371f4f1759d15496573423b06bf2ea41b636aefe4b02c968a4493b643dcb34dd246986b50e7e68e06ab
data/lib/flaky.rb CHANGED
@@ -9,26 +9,15 @@ require 'posix/spawn' # http://rubygems.org/gems/posix-spawn
9
9
  require 'digest/md5'
10
10
 
11
11
  module Flaky
12
- VERSION = '0.0.17' unless defined? ::Flaky::VERSION
13
- DATE = '2013-12-10' unless defined? ::Flaky::DATE
12
+ VERSION = '0.0.18' unless defined? ::Flaky::VERSION
13
+ DATE = '2013-12-23' unless defined? ::Flaky::DATE
14
14
 
15
- # https://github.com/appium/ruby_lib/blob/0e203d76610abd519ba9d2fe9c14b50c94df5bbd/lib/appium_lib.rb#L24
16
- def self.add_to_path file, path=false
17
- path = path ? "../#{path}/" : '..'
18
- path = File.expand_path path, file
19
-
20
- $:.unshift path unless $:.include? path
21
- end
22
-
23
- add_to_path __FILE__ # add this dir to path
24
-
25
- # TODO: Use require_relative instead of add_to_path
26
15
  # require internal files
27
- require 'flaky/appium'
28
- require 'flaky/applescript'
29
- require 'flaky/run'
16
+ require_relative 'flaky/appium'
17
+ require_relative 'flaky/applescript'
18
+ require_relative 'flaky/run'
30
19
 
31
- require 'flaky/run/all_tests'
32
- require 'flaky/run/from_file'
33
- require 'flaky/run/one_test'
20
+ require_relative 'flaky/run/all_tests'
21
+ require_relative 'flaky/run/from_file'
22
+ require_relative 'flaky/run/one_test'
34
23
  end
data/lib/flaky/appium.rb CHANGED
@@ -22,8 +22,7 @@ module Flaky
22
22
  #noinspection RubyResolve
23
23
  class Appium
24
24
  include POSIX::Spawn
25
- # logcat is read & stopped by run.execute
26
- attr_reader :ready, :pid, :in, :out, :err, :log, :logcat, :ios, :android
25
+ attr_reader :ready, :pid, :in, :out, :err, :log, :ios, :android
27
26
  @@thread = nil
28
27
 
29
28
  def self.remove_ios_apps
@@ -33,9 +32,13 @@ module Flaky
33
32
  # Must kill iPhone simulator or strange install errors will occur.
34
33
  self.kill_all 'iPhone Simulator'
35
34
 
36
- app_glob = "/Users/#{user}/Library/Application Support/iPhone Simulator/**/Applications/*"
35
+ app_glob = "/Users/#{user}/Library/Application Support/iPhone Simulator/**/Applications"
37
36
  Dir.glob(app_glob) do |ios_app_folder|
38
37
  FileUtils.rm_rf ios_app_folder
38
+ root = File.dirname ios_app_folder
39
+ FileUtils.rm_rf File.join(root, 'Library/TCC')
40
+ FileUtils.rm_rf File.join(root, 'Library/Caches')
41
+ FileUtils.rm_rf File.join(root, 'Library/Media')
39
42
  end
40
43
  end
41
44
 
@@ -59,7 +62,6 @@ module Flaky
59
62
  @android = opts.fetch(:android, false)
60
63
  if @android
61
64
  @droid = Flaky::Android.new
62
- @logcat = Flaky::Logcat.new
63
65
  end
64
66
  @ios = ! @android
65
67
  end
@@ -69,7 +71,6 @@ module Flaky
69
71
  @log = "/tmp/flaky/tmp_log_#{Random.rand(10**4..10**5-1)}"
70
72
  if @android
71
73
  @droid.reset
72
- @logcat.start
73
74
  else
74
75
  self.class.remove_ios_apps
75
76
  end
@@ -100,12 +101,12 @@ module Flaky
100
101
  end
101
102
 
102
103
  def flush_buffer
103
- return if @buffer.nil? || @buffer.empty?
104
+ return '' if @buffer.nil? || @buffer.empty?
104
105
  File.open(@log, 'a') do |f|
105
106
  f.write @buffer
106
107
  end
107
108
  @buffer = ''
108
- @log
109
+ @log || ''
109
110
  end
110
111
 
111
112
  ##
data/lib/flaky/run.rb CHANGED
@@ -28,7 +28,9 @@ module Flaky
28
28
  str = str + '_' if str[-1] != '_'
29
29
  str += @test_name.split('/').last
30
30
 
31
- File.join @result_dir, @pass_str, str, file_name
31
+ filename_only = File.basename(@test_name)
32
+
33
+ File.join @result_dir, @pass_str, filename_only, str, file_name
32
34
  end
33
35
  end
34
36
 
@@ -87,7 +89,7 @@ module Flaky
87
89
  puts out
88
90
  end
89
91
 
90
- def _execute run_cmd, test_name, runs, appium
92
+ def _execute run_cmd, test_name, runs, appium, sauce
91
93
  # must capture exit code or log is an array.
92
94
  log, exit_code = Open3.capture2e run_cmd
93
95
 
@@ -139,24 +141,28 @@ module Flaky
139
141
  # f.write appium.tail.out.readpartial(999_999_999)
140
142
  # end
141
143
 
142
- # adb logcat log
143
- logcat = appium.logcat ? appium.logcat.stop : nil
144
- logcat_file_path = log_file.name("#{postfix}.logcat.txt")
145
- FileUtils.mkdir_p File.dirname(logcat_file_path)
146
- File.open(logcat_file_path, 'w') do |f|
147
- f.write logcat
148
- end if logcat
149
-
150
- # appium server log
151
- appium_server_path = log_file.name("#{postfix}.appium.html")
152
- FileUtils.mkdir_p File.dirname(appium_server_path)
153
- File.open(appium_server_path, 'w') do |f|
154
- # this may return nil
155
- tmp_file = appium.flush_buffer
156
-
157
- if !tmp_file.nil? && !tmp_file.empty?
158
- f.write File.read tmp_file
159
- File.delete tmp_file
144
+ unless sauce
145
+ src_system_log = '/tmp/flaky_logs.txt'
146
+ if File.exists? src_system_log
147
+ # postfix is required! or the log will be saved to an incorrect path
148
+ system_log_path = log_file.name("#{postfix}.system.txt")
149
+ FileUtils.mkdir_p File.dirname(system_log_path)
150
+ FileUtils.copy_file src_system_log, system_log_path
151
+ File.delete src_system_log
152
+ end
153
+
154
+ # appium server log
155
+ appium_server_path = log_file.name("#{postfix}.appium.html")
156
+ FileUtils.mkdir_p File.dirname(appium_server_path)
157
+ File.open(appium_server_path, 'w') do |f|
158
+ # this may return nil
159
+ tmp_file = appium.flush_buffer
160
+
161
+ # todo: copy file instead of read & delete
162
+ if !tmp_file.nil? && !tmp_file.empty?
163
+ f.write File.read tmp_file
164
+ File.delete tmp_file
165
+ end
160
166
  end
161
167
  end
162
168
 
@@ -174,27 +180,36 @@ module Flaky
174
180
  run_cmd = opts[:run_cmd]
175
181
  test_name = opts[:test_name]
176
182
  appium = opts[:appium]
183
+ sauce = opts[:sauce]
177
184
 
178
185
  old_crash_files = []
179
- if appium.ios
186
+ # appium is nil when on sauce
187
+ if !sauce && appium && appium.ios
180
188
  collect_crashes old_crash_files
181
189
  end
182
190
 
183
191
  raise 'must pass :run_cmd' unless run_cmd
184
192
  raise 'must pass :test_name' unless test_name
185
- raise 'must pass :appium' unless appium
193
+ # local appium is not required when running on Sauce
194
+ raise 'must pass :appium' unless appium || sauce
186
195
 
187
196
  test = @tests[test_name] ||= {runs: 0, pass: 0, fail: 0}
188
197
  runs = test[:runs] += 1
189
198
 
190
- passed = _execute run_cmd, test_name, runs, appium
191
-
199
+ passed = _execute run_cmd, test_name, runs, appium, sauce
200
+ unless sauce
192
201
  print cyan("\n #{test_name} ") if @last_test.nil? ||
193
202
  @last_test != test_name
194
203
 
195
204
  print passed ? green(' ✓') : red(' ✖')
205
+ else
206
+ print cyan("\n #{test_name} ")
207
+ print passed ? green(' ✓') : red(' ✖')
208
+ print " https://saucelabs.com/tests/#{File.read('/tmp/appium_lib_session').chomp}\n"
209
+ end
196
210
 
197
- if appium.ios
211
+ # appium is nil when running on Sauce
212
+ if !sauce && appium && appium.ios
198
213
  new_crash_files = []
199
214
  collect_crashes new_crash_files
200
215
 
@@ -9,8 +9,9 @@ module Flaky
9
9
  raise ':count must be an int' unless count.kind_of?(Integer)
10
10
  raise ':os must be a string' unless os.kind_of?(String)
11
11
 
12
+ running_on_sauce = ENV['SAUCE_USERNAME'] ? true : false
12
13
  flaky = Flaky::Run.new
13
- appium = Appium.new
14
+ appium = Appium.new unless running_on_sauce
14
15
 
15
16
  current_dir = Dir.pwd
16
17
  raise "Rakefile doesn't exist in #{current_dir}" unless File.exists?(File.join(current_dir, 'Rakefile'))
@@ -26,14 +27,14 @@ module Flaky
26
27
 
27
28
  count.times do
28
29
  File.open('/tmp/flaky/current.txt', 'a') { |f| f.puts "Running: #{test_name} on #{os}" }
29
- appium.start
30
+ appium.start unless running_on_sauce
30
31
  run_cmd = "cd #{current_dir}; rake #{os.downcase}['#{name}']"
31
- passed = flaky.execute run_cmd: run_cmd, test_name: test_name, appium: appium
32
+ passed = flaky.execute run_cmd: run_cmd, test_name: test_name, appium: appium, sauce: running_on_sauce
32
33
  break if passed # move onto the next test after one successful run
33
34
  end
34
35
  end
35
36
 
36
- appium.stop
37
+ appium.stop unless running_on_sauce
37
38
  flaky.report
38
39
  end
39
40
  end # module Flaky
@@ -30,8 +30,9 @@ module Flaky
30
30
  raise "Missing tests #{missing_tests}"
31
31
  end
32
32
 
33
+ running_on_sauce = ENV['SAUCE_USERNAME'] ? true : false
33
34
  flaky = Flaky::Run.new
34
- appium = Appium.new
35
+ appium = Appium.new unless running_on_sauce
35
36
 
36
37
  raise "Rakefile doesn't exist in #{current_dir}" unless File.exists?(File.join(current_dir, 'Rakefile'))
37
38
 
@@ -45,14 +46,14 @@ module Flaky
45
46
  test_name = File.join(File.dirname(test_name), File.basename(test_name, '.*'))
46
47
 
47
48
  count.times do
48
- appium.start
49
+ appium.start unless running_on_sauce
49
50
  run_cmd = "cd #{current_dir}; rake #{os.downcase}['#{name}']"
50
- passed = flaky.execute run_cmd: run_cmd, test_name: test_name, appium: appium
51
+ passed = flaky.execute run_cmd: run_cmd, test_name: test_name, appium: appium, sauce: running_on_sauce
51
52
  break if passed # move onto the next test after one successful run
52
53
  end
53
54
  end
54
55
 
55
- appium.stop
56
+ appium.stop unless running_on_sauce
56
57
  flaky.report
57
58
  end
58
59
  end # module Flaky
@@ -14,8 +14,9 @@ module Flaky
14
14
  # ensure file name does not contain an extension
15
15
  name = File.basename name, '.*'
16
16
 
17
+ running_on_sauce = ENV['SAUCE_USERNAME'] ? true : false
17
18
  flaky = Flaky::Run.new
18
- appium = Appium.new
19
+ appium = Appium.new unless running_on_sauce
19
20
 
20
21
  current_dir = Dir.pwd
21
22
 
@@ -32,12 +33,12 @@ module Flaky
32
33
  test_name = File.join(File.dirname(test_name), File.basename(test_name, '.*'))
33
34
 
34
35
  count.times do
35
- appium.start
36
+ appium.start unless running_on_sauce
36
37
  run_cmd = "cd #{current_dir}; rake #{os.downcase}['#{name}']"
37
- flaky.execute run_cmd: run_cmd, test_name: test_name, appium: appium
38
+ flaky.execute run_cmd: run_cmd, test_name: test_name, appium: appium, sauce: running_on_sauce
38
39
  end
39
40
 
40
- appium.stop
41
+ appium.stop unless running_on_sauce
41
42
  flaky.report
42
43
  end
43
44
  end # module Flaky
data/release_notes.md CHANGED
@@ -1,3 +1,12 @@
1
+ #### v0.0.17 2013-12-10
2
+
3
+ - [64078c1](https://github.com/appium/flaky/commit/64078c1ed2ee8a96a52f05aefb460216b48ea2b5) Release 0.0.17
4
+ - [208c9bb](https://github.com/appium/flaky/commit/208c9bbbeb17f2a70965cd530c3f5ee8d9a32369) Disable coloring
5
+ - [bf30e8e](https://github.com/appium/flaky/commit/bf30e8ed918a184f34ba316f472e5c0bfe9c0bb1) Fix nil error
6
+ - [b19f9e5](https://github.com/appium/flaky/commit/b19f9e548bcc40f70b232ac2225b7c71abd01415) Don't escape appium log. Timeout after 60s of color
7
+ - [a4a569f](https://github.com/appium/flaky/commit/a4a569fbaebdce9683d8294afae61ff7712a0e92) Record crashes per test in crashes.txt
8
+
9
+
1
10
  #### v0.0.16 2013-12-09
2
11
 
3
12
  - [fed719a](https://github.com/appium/flaky/commit/fed719af184a6f38a4d29b3c65f1906d6917c1fb) Release 0.0.16
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flaky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - code@bootstraponline.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-10 00:00:00.000000000 Z
11
+ date: 2013-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chronic_duration
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.10.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.10.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: posix-spawn
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.3.6
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.3.6
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: 10.1.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 10.1.0
55
55
  description: Measure flaky Ruby Appium tests.
@@ -60,7 +60,7 @@ executables:
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - ".gitignore"
63
+ - .gitignore
64
64
  - LICENSE-2.0.txt
65
65
  - Rakefile
66
66
  - bin/flake
@@ -70,7 +70,6 @@ files:
70
70
  - lib/flaky.rb
71
71
  - lib/flaky/appium.rb
72
72
  - lib/flaky/applescript.rb
73
- - lib/flaky/logcat.rb
74
73
  - lib/flaky/reset_android.rb
75
74
  - lib/flaky/run.rb
76
75
  - lib/flaky/run/all_tests.rb
@@ -92,12 +91,12 @@ require_paths:
92
91
  - lib
93
92
  required_ruby_version: !ruby/object:Gem::Requirement
94
93
  requirements:
95
- - - ">="
94
+ - - '>='
96
95
  - !ruby/object:Gem::Version
97
96
  version: 1.9.3
98
97
  required_rubygems_version: !ruby/object:Gem::Requirement
99
98
  requirements:
100
- - - ">="
99
+ - - '>='
101
100
  - !ruby/object:Gem::Version
102
101
  version: '0'
103
102
  requirements: []
data/lib/flaky/logcat.rb DELETED
@@ -1,41 +0,0 @@
1
- # encoding: utf-8
2
- # log = Flaky::Logcat.new
3
- # log.start; log.stop
4
- module Flaky
5
- class Logcat
6
- attr_reader :pid, :in, :out, :err
7
- @@thread = nil
8
- @@data = nil
9
-
10
- # Start the logcat process and capture the output
11
- def start
12
- # make sure the adb devices command doesn't error.
13
- while (!POSIX::Spawn::Child.new('adb kill-server; adb devices').err.empty?)
14
- sleep 0.5
15
- end
16
-
17
- cmd = 'adb logcat'
18
- @pid, @in, @@out, @err = POSIX::Spawn::popen4 cmd
19
- @in.close
20
- @data = ''
21
-
22
- @@thread.exit if @@thread
23
- @@thread = Thread.new do
24
- # out.read blocks until the process ends
25
- @@data = @@out.read
26
- end
27
- end
28
-
29
- # Stop and return the data
30
- def stop
31
- begin
32
- [@in, @out, @err].each { |io| io.close unless io.nil? || io.closed? }
33
- Process.kill 'KILL', @pid
34
- Process.waitpid @pid
35
- rescue
36
- end
37
-
38
- @@data
39
- end
40
- end
41
- end