calabash-cucumber 0.9.152 → 0.9.153

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e5d32bd3de7fc4255e3c73c5c94a1b437445bda
4
- data.tar.gz: def9cece9fcf16b4e2f1dc552b0cb0faa0e9b095
3
+ metadata.gz: 0013596c606dae1ae15bdd511ff80df2828f5cd1
4
+ data.tar.gz: e7b227e7ed17db7c74590184fa245204510bf503
5
5
  SHA512:
6
- metadata.gz: 24b3c029c87ec6c03e1303726298590e02dd4fcc21d9fdc49f456f2b0cf34e8f7cdfaaa5ac41a23e9dd49a1ed4b7ee41edf7a4d2949a09f3065a85bd7cdc0a71
7
- data.tar.gz: e83946d9e1bb3725edaa5240541ca55e18a9356a0e063bfd071a48b790a8f04eefc41154882adaeb59f78d78aca04f385238563fe959a1803f2f606414d0b7b1
6
+ metadata.gz: ed9bb7e55df24f89f862bb87e62fd8ed29ca3bc2160e674e60ba7330b1b7f57d235b60e9051e69d55738acf56d24ae7388e0e86f05d4e1af56530233b0df4db9
7
+ data.tar.gz: e5b448303482fece80fc706b37e292624aab14b09e4589a41e4f120388ed2639aad59b9bcf0ad0a8a31609af69821a73a41036e934b1a0babcc23fe4f63be936
@@ -186,8 +186,8 @@ def validate_setup(args)
186
186
  else
187
187
  dd_dir = Calabash::Cucumber::SimulatorHelper.derived_data_dir_for_project
188
188
  if not dd_dir
189
- puts "Unable to find iOS project."
190
- puts "You should run this command from an iOS project directory."
189
+ puts "Unable to find iOS XCode project."
190
+ puts "You should run this command from an XCode project directory."
191
191
  exit 1
192
192
  end
193
193
  app_bundles = Dir.glob(File.join(dd_dir, "Build", "Products", "*", "*.app"))
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  s.add_dependency( "location-one", "~>0.0.10")
27
27
  s.add_dependency( "httpclient","~> 2.3.3")
28
28
  s.add_dependency( "bundler", "~> 1.1")
29
- s.add_dependency( "run_loop", "~> 0.0.19" )
29
+ s.add_dependency( "run_loop", "~> 0.0.20" )
30
30
  s.add_dependency( "awesome_print")
31
31
 
32
32
  end
@@ -341,7 +341,7 @@ module Calabash
341
341
  end
342
342
  end
343
343
 
344
- def background(secs)
344
+ def send_app_to_background(secs)
345
345
  uia_send_app_to_background(secs)
346
346
  end
347
347
 
@@ -514,7 +514,6 @@ EOF
514
514
  res['results']
515
515
  end
516
516
 
517
- # not called? -jjm 2013-08-16
518
517
  def interpolate(recording, options={})
519
518
  data = load_playback_data(recording)
520
519
 
@@ -548,7 +547,12 @@ EOF
548
547
  os = ENV['OS']
549
548
 
550
549
  unless os
551
- major = Calabash::Cucumber::SimulatorHelper.ios_major_version
550
+ if @calabash_launcher && @calabash_launcher.active?
551
+ major = @calabash_launcher.ios_major_version
552
+ else
553
+ major = Calabash::Cucumber::SimulatorHelper.ios_major_version
554
+ end
555
+
552
556
  unless major
553
557
  raise <<EOF
554
558
  Unable to determine iOS major version
@@ -645,11 +649,10 @@ EOF
645
649
  ## args :app for device bundle id, for sim path to app
646
650
  ##
647
651
  def start_test_server_in_background(args={})
648
- target = args[:device_target] || :simulator
649
652
  stop_test_server
650
- @calabash_launcher = Calabash::Cucumber::Launcher.new(target)
653
+ @calabash_launcher = Calabash::Cucumber::Launcher.new()
651
654
  @calabash_launcher.relaunch(args)
652
-
655
+ @calabash_launcher
653
656
  end
654
657
 
655
658
  def stop_test_server
@@ -43,6 +43,7 @@ module Calabash
43
43
  raise "Char #{chr} is not yet supported in iOS7"
44
44
  end
45
45
  end
46
+ res = {'results' => []}
46
47
  else
47
48
  res = http({:method => :post, :path => 'keyboard'},
48
49
  {:key => chr, :events => load_playback_data("touch_done")})
@@ -35,7 +35,6 @@ module Calabash
35
35
  simulator.quit_simulator
36
36
  end
37
37
 
38
-
39
38
  def self.derived_data_dir_for_project
40
39
  dir = project_dir
41
40
  xcode_workspace_name = ''
@@ -117,19 +116,39 @@ module Calabash
117
116
  File.expand_path(ENV['PROJECT_DIR'] || Dir.pwd)
118
117
  end
119
118
 
120
- def self.app_bundle_or_raise(path)
119
+ def self.detect_app_bundle(path=nil,device_build_dir='iPhoneSimulator')
120
+ begin
121
+ app_bundle_or_raise(path,device_build_dir)
122
+ rescue =>e
123
+ nil
124
+ end
125
+ end
126
+
127
+ def self.app_bundle_or_raise(path=nil, device_build_dir='iPhoneSimulator')
121
128
  bundle_path = nil
122
129
  path = File.expand_path(path) if path
123
130
 
124
131
  if path and not File.directory?(path)
125
- puts "Unable to find .app bundle at #{path}. It should be an .app directory."
126
- dd_dir = derived_data_dir_for_project
127
- app_bundles = Dir.glob(File.join(dd_dir, "Build", "Products", "*", "*.app"))
128
- msg = "Try setting APP_BUNDLE_PATH in features/support/01_launch.rb to one of:\n\n"
129
- msg << app_bundles.join("\n")
130
- raise msg
132
+ raise "Unable to find .app bundle at #{path}. It should be an .app directory."
131
133
  elsif path
132
134
  bundle_path = path
135
+ elsif xamarin_project?
136
+ bundle_path = bundle_path_from_xamarin_project(device_build_dir)
137
+ unless bundle_path
138
+ msg = ["Detected Xamarin project, but did not detect built app linked with Calabash"]
139
+ msg << "You should build your project from Xamarin Studio"
140
+ msg << "Make sure you build for Simulator and that you're using the Calabash components"
141
+ raise msg.join("\n")
142
+ end
143
+ if FULL_CONSOLE_OUTPUT
144
+ puts("-"*37)
145
+ puts "Auto detected APP_BUNDLE_PATH:\n\n"
146
+
147
+ puts "APP_BUNDLE_PATH=#{preferred_dir || sim_dirs[0]}\n\n"
148
+ puts "Please verify!"
149
+ puts "If this is wrong please set it as APP_BUNDLE_PATH in features/support/01_launch.rb\n"
150
+ puts("-"*37)
151
+ end
133
152
  else
134
153
  dd_dir = derived_data_dir_for_project
135
154
  sim_dirs = Dir.glob(File.join(dd_dir, "Build", "Products", "*-iphonesimulator", "*.app"))
@@ -169,10 +188,50 @@ module Calabash
169
188
  bundle_path
170
189
  end
171
190
 
191
+ def self.xamarin_project?
192
+ xamarin_ios_csproj_path != nil
193
+ end
194
+
195
+ def self.xamarin_ios_csproj_path
196
+ solution_path = Dir['*.Xamarin.sln'].first
197
+ if solution_path
198
+ project_dir = Dir.pwd
199
+ else
200
+ solution_path = Dir[File.join('..','*.Xamarin.sln')].first
201
+ project_dir = File.expand_path('..') if solution_path
202
+ end
203
+ return nil unless project_dir
204
+
205
+ ios_project_dir = Dir[File.join(project_dir,'*.iOS')].first
206
+ return nil unless ios_project_dir && File.directory?(ios_project_dir)
207
+ ios_project_dir
208
+ end
209
+
210
+ def self.bundle_path_from_xamarin_project(device_build_dir='iPhoneSimulator')
211
+ ios_project_path = xamarin_ios_csproj_path
212
+ conf_glob = File.join(ios_project_path,'bin',device_build_dir,'*')
213
+ built_confs = Dir[conf_glob]
214
+
215
+ calabash_build = built_confs.find {|path| File.basename(path) == 'Calabash'}
216
+ debug_build = built_confs.find {|path| File.basename(path) == 'Debug'}
217
+
218
+ bundle_path = [calabash_build, debug_build, *built_confs].find do |path|
219
+ next unless path && File.directory?(path)
220
+ app_dir = Dir[File.join(path,'*.app')].first
221
+ app_dir && linked_with_calabash?(app_dir)
222
+ end
223
+
224
+ Dir[File.join(bundle_path,'*.app')].first if bundle_path
225
+ end
226
+
227
+ def self.linked_with_calabash?(d)
228
+ out = `otool "#{File.expand_path(d)}"/* -o 2> /dev/null | grep CalabashServer`
229
+ /CalabashServer/.match(out)
230
+ end
231
+
172
232
  def self.find_preferred_dir(sim_dirs)
173
233
  sim_dirs.find do |d|
174
- out = `otool "#{File.expand_path(d)}"/* -o 2> /dev/null | grep CalabashServer`
175
- /CalabashServer/.match(out)
234
+ linked_with_calabash?(d)
176
235
  end
177
236
  end
178
237
 
@@ -2,15 +2,17 @@ require 'calabash-cucumber/launch/simulator_helper'
2
2
  require 'sim_launcher'
3
3
  require 'calabash-cucumber/device'
4
4
  require 'run_loop'
5
-
5
+ require 'cfpropertylist'
6
6
 
7
7
  class Calabash::Cucumber::Launcher
8
8
  attr_accessor :run_loop
9
- attr_accessor :device_target
10
9
  attr_accessor :device
11
10
 
11
+ @@launcher = nil
12
+
12
13
  class StartError < RuntimeError
13
14
  attr_accessor :error
15
+
14
16
  def initialize(err)
15
17
  self.error= err
16
18
  end
@@ -20,52 +22,19 @@ class Calabash::Cucumber::Launcher
20
22
  end
21
23
  end
22
24
 
23
- def self.launcher(device_target=:simulator)
24
- @@launcher ||= Launcher.new(device_target)
25
- end
26
-
27
- def self.launcher_if_used
28
- @@launcher
29
- end
30
-
31
- def initialize(device_target=:simulator)
32
- self.device_target = device_target
33
- @@launcher = self
34
- end
35
-
36
25
  class CalabashLauncherTimeoutErr < Timeout::Error
37
26
  end
38
27
 
39
- def calabash_no_stop?
40
- calabash_no_launch? or ENV['NO_STOP']=="1"
41
- end
42
-
43
- def calabash_no_launch?
44
- ENV['NO_LAUNCH']=='1'
45
- end
46
-
47
- def device_target?
48
- (ENV['DEVICE_TARGET'] != nil) && (not simulator_target?)
49
- end
50
-
51
- def simulator_target?
52
- ENV['DEVICE_TARGET'] == 'simulator'
53
- end
54
-
55
- def sdk_version
56
- ENV['SDK_VERSION']
57
- end
58
-
59
- def reset_between_scenarios?
60
- ENV['RESET_BETWEEN_SCENARIOS']=="1"
28
+ def self.launcher
29
+ @@launcher ||= Launcher.new
61
30
  end
62
31
 
63
- def device_env
64
- ENV['DEVICE'] || 'iphone'
32
+ def self.launcher_if_used
33
+ @@launcher
65
34
  end
66
35
 
67
- def active?
68
- (simulator_target? || device_target?) && (not run_loop.nil?)
36
+ def initialize
37
+ @@launcher = self
69
38
  end
70
39
 
71
40
  def ios_major_version
@@ -78,12 +47,9 @@ class Calabash::Cucumber::Launcher
78
47
  device.ios_version
79
48
  end
80
49
 
81
-
82
50
  def reset_app_jail(sdk=nil, path=nil)
83
- return if device_target?
84
-
85
- sdk = sdk || ENV['SDK_VERSION'] || SimLauncher::SdkDetector.new().latest_sdk_version
86
- path = path || Calabash::Cucumber::SimulatorHelper.app_bundle_or_raise(app_path)
51
+ sdk ||= sdk_version || SimLauncher::SdkDetector.new().latest_sdk_version
52
+ path ||= Calabash::Cucumber::SimulatorHelper.app_bundle_or_raise(app_path)
87
53
 
88
54
  app = File.basename(path)
89
55
  bundle = `find "#{ENV['HOME']}/Library/Application Support/iPhone Simulator/#{sdk}/Applications/" -type d -depth 2 -name "#{app}" | head -n 1`
@@ -95,35 +61,136 @@ class Calabash::Cucumber::Launcher
95
61
  end
96
62
  end
97
63
 
98
- def relaunch(args={})
99
- RunLoop.stop(run_loop) if run_loop
64
+ def default_launch_args
65
+ # APP_BUNDLE_PATH
66
+ # BUNDLE_ID
67
+ # APP (unifies APP_BUNDLE_PATH, BUNDLE_ID)
68
+ # DEVICE_TARGET
69
+ # SDK_VERSION
70
+ # RESET_BETWEEN_SCENARIOS
71
+ # DEVICE
72
+ # NO_LAUNCH
73
+ # NO_STOP
74
+
75
+ args = {
76
+ :launch_method => default_launch_method,
77
+ :reset => reset_between_scenarios?,
78
+ :bundle_id => ENV['BUNDLE_ID'],
79
+ :device => device_env,
80
+ :no_stop => calabash_no_stop?,
81
+ :no_launch => calabash_no_launch?,
82
+ :sdk_version => sdk_version
83
+ }
84
+
85
+ #:device_target will be set
86
+
87
+ if run_with_instruments?(args) && !simulator_target?
88
+ device_tgt = ENV['DEVICE_TARGET']
89
+ if device_tgt.nil? || device_tgt.downcase == 'device'
90
+ device_tgt = RunLoop::Core.detect_connected_device
91
+ end
100
92
 
101
- if device_target?
102
- default_args = {:app => ENV['BUNDLE_ID']}
103
- target = ENV['DEVICE_TARGET']
104
- if target != 'DEVICE'
105
- default_args[:udid] = target
93
+ if device_tgt
94
+ args[:device_target] = args[:udid] = device_tgt
95
+ else
96
+ args[:device_target] = 'simulator'
106
97
  end
107
- default_args
108
- self.run_loop = new_run_loop(default_args.merge(args))
109
98
  else
99
+ args[:device_target] = 'simulator'
100
+ end
101
+
110
102
 
111
- sdk = sdk_version || SimLauncher::SdkDetector.new().latest_sdk_version
103
+ args
104
+ end
105
+
106
+ def default_launch_method
107
+ return :instruments unless sdk_version
108
+ return :instruments if sdk_version.start_with?('7') # Only instruments supported for iOS7+
109
+ sim_detector = SimLauncher::SdkDetector.new()
110
+ available = sim_detector.available_sdk_versions.reject {|v| v.start_with?('7')}
111
+ if available.include?(sdk_version)
112
+ :sim_launcher
113
+ else
114
+ :instruments
115
+ end
116
+ end
117
+
118
+ def relaunch(args={})
119
+ RunLoop.stop(run_loop) if run_loop
120
+
121
+ args = default_launch_args.merge(args)
122
+
123
+ args[:app] = args[:app] || args[:bundle_id] || app_path || detect_app_bundle_from_args(args)
124
+
125
+ if File.directory?(args[:app])
126
+ args[:app] = File.expand_path(args[:app])
127
+ end
128
+
129
+ args[:bundle_id] ||= detect_bundle_id_from_app_bundle(args)
130
+
131
+ args[:device] ||= detect_device_from_args(args)
132
+
133
+
134
+ reset_app_jail if args[:reset]
135
+
136
+ if run_with_instruments?(args)
137
+ self.run_loop = new_run_loop(args)
138
+ else
139
+ # run with sim launcher
140
+ sdk = sdk_version || SimLauncher::SdkDetector.new().available_sdk_versions.reverse.find { |x| !x.start_with?('7') }
112
141
  path = Calabash::Cucumber::SimulatorHelper.app_bundle_or_raise(app_path)
113
- if reset_between_scenarios?
114
- reset_app_jail(sdk, path)
115
- end
142
+ Calabash::Cucumber::SimulatorHelper.relaunch(path, sdk, args[:device].to_s, args)
143
+ end
144
+ before = Time.now
145
+ ensure_connectivity
146
+ end
116
147
 
117
- if simulator_target?
118
- default_args = {:app => path, :device => device_env.to_sym}
119
- self.run_loop = new_run_loop(default_args.merge(args))
120
- else
121
- ## sim launcher
122
- Calabash::Cucumber::SimulatorHelper.relaunch(path, sdk, device_env, args)
148
+ def detect_device_from_args(args)
149
+ if args[:app] && File.directory?(args[:app])
150
+ # Derive bundle id from bundle_dir
151
+ plist_as_hash = info_plist_from_bundle_path(args[:app])
152
+ if plist_as_hash
153
+ device_family = plist_as_hash['UIDeviceFamily']
154
+ if device_family
155
+ first_device = device_family.first
156
+ if first_device == 2
157
+ return 'ipad'
158
+ else
159
+ return 'iphone'
160
+ end
161
+ end
123
162
  end
163
+ else
164
+ args[:app]
165
+ end
166
+
167
+
168
+ end
124
169
 
170
+ def detect_app_bundle_from_args(args)
171
+ if args[:device_target]=='simulator'
172
+ device_xamarin_build_dir = 'iPhoneSimulator'
173
+ else
174
+ device_xamarin_build_dir = 'iPhone'
125
175
  end
126
- ensure_connectivity
176
+ Calabash::Cucumber::SimulatorHelper.detect_app_bundle(nil, device_xamarin_build_dir)
177
+ end
178
+
179
+ def detect_bundle_id_from_app_bundle(args)
180
+ if args[:app] && File.directory?(args[:app])
181
+ # Derive bundle id from bundle_dir
182
+ plist_as_hash = info_plist_from_bundle_path(args[:app])
183
+ if plist_as_hash
184
+ plist_as_hash['CFBundleIdentifier']
185
+ end
186
+ else
187
+ args[:app]
188
+ end
189
+ end
190
+
191
+ def info_plist_from_bundle_path(bundle_path)
192
+ plist_path = File.join(bundle_path, 'Info.plist')
193
+ info_plist_as_hash(plist_path) if File.exist?(plist_path)
127
194
  end
128
195
 
129
196
  def new_run_loop(args)
@@ -132,6 +199,7 @@ class Calabash::Cucumber::Launcher
132
199
  begin
133
200
  return RunLoop.run(args)
134
201
  rescue RunLoop::TimeoutError => e
202
+ last_err = e
135
203
  if ENV['CALABASH_FULL_CONSOLE_OUTPUT'] == '1'
136
204
  puts "retrying run loop..."
137
205
  end
@@ -192,7 +260,7 @@ class Calabash::Cucumber::Launcher
192
260
 
193
261
  end
194
262
 
195
- if status=='200'
263
+ if status == '200'
196
264
  version_body = JSON.parse(res.body)
197
265
  self.device = Calabash::Cucumber::Device.new(url, version_body)
198
266
  end
@@ -204,14 +272,72 @@ class Calabash::Cucumber::Launcher
204
272
  RunLoop.stop(run_loop)
205
273
  end
206
274
 
207
- def app_path
208
- ENV['APP_BUNDLE_PATH'] || (defined?(APP_BUNDLE_PATH) && APP_BUNDLE_PATH)
209
- end
210
-
211
275
  def calabash_notify(world)
212
276
  if world.respond_to?(:on_launch)
213
277
  world.on_launch
214
278
  end
215
279
  end
280
+
281
+
282
+
283
+ def info_plist_as_hash(plist_path)
284
+ unless File.exist?(plist_path)
285
+ raise "Unable to find Info.plist: #{plist_path}"
286
+ end
287
+ parsedplist = CFPropertyList::List.new(:file => plist_path)
288
+ CFPropertyList.native_types(parsedplist.value)
289
+ end
290
+
291
+ def detect_bundle_id
292
+ begin
293
+ bundle_path = Calabash::Cucumber::SimulatorHelper.app_bundle_or_raise(app_path)
294
+ plist_path = File.join(bundle_path, 'Info.plist')
295
+ info_plist_as_hash(plist_path)['CFBundleIdentifier']
296
+ rescue => e
297
+ raise "Unable to automatically find bundle id. Please set BUNDLE_ID environment variable. #{e}"
298
+ end
299
+ end
300
+
301
+ def calabash_no_stop?
302
+ calabash_no_launch? or ENV['NO_STOP']=="1"
303
+ end
304
+
305
+ def calabash_no_launch?
306
+ ENV['NO_LAUNCH']=='1'
307
+ end
308
+
309
+ def device_target?
310
+ (ENV['DEVICE_TARGET'] != nil) && (not simulator_target?)
311
+ end
312
+
313
+ def simulator_target?
314
+ ENV['DEVICE_TARGET'] == 'simulator'
315
+ end
316
+
317
+ def sdk_version
318
+ ENV['SDK_VERSION']
319
+ end
320
+
321
+ def reset_between_scenarios?
322
+ ENV['RESET_BETWEEN_SCENARIOS']=="1"
323
+ end
324
+
325
+ def device_env
326
+ ENV['DEVICE']
327
+ end
328
+
329
+ def app_path
330
+ ENV['APP_BUNDLE_PATH'] || (defined?(APP_BUNDLE_PATH) && APP_BUNDLE_PATH) || ENV['APP']
331
+ end
332
+
333
+ def run_with_instruments?(args)
334
+ args[:launch_method] == :instruments
335
+ end
336
+
337
+ def active?
338
+ not run_loop.nil?
339
+ end
340
+
341
+
216
342
  end
217
343
 
@@ -1,6 +1,6 @@
1
1
  module Calabash
2
2
  module Cucumber
3
- VERSION = '0.9.152'
4
- FRAMEWORK_VERSION = '0.9.151'
3
+ VERSION = '0.9.153'
4
+ FRAMEWORK_VERSION = '0.9.153'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calabash-cucumber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.152
4
+ version: 0.9.153
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karl Krukow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-07 00:00:00.000000000 Z
11
+ date: 2013-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - ~>
158
158
  - !ruby/object:Gem::Version
159
- version: 0.0.19
159
+ version: 0.0.20
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - ~>
165
165
  - !ruby/object:Gem::Version
166
- version: 0.0.19
166
+ version: 0.0.20
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: awesome_print
169
169
  requirement: !ruby/object:Gem::Requirement