calabash-cucumber 0.9.139 → 0.9.140.pre1

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.
data/bin/calabash-ios CHANGED
@@ -34,6 +34,9 @@ elsif cmd == 'console'
34
34
  elsif cmd == 'build'
35
35
  build
36
36
  exit 0
37
+ elsif cmd == 'update'
38
+ update(ARGV)
39
+ exit 0
37
40
  elsif cmd == 'run'
38
41
  run
39
42
  exit 0
@@ -1,6 +1,7 @@
1
1
  require 'tempfile'
2
2
  require 'json'
3
3
 
4
+ UPDATE_TARGETS = ['hooks']
4
5
 
5
6
  def msg(title, &block)
6
7
  puts "\n" + "-"*10 + title + "-"*10
@@ -21,6 +22,8 @@ def print_usage
21
22
  starts an interactive console to interact with your app via Calabash
22
23
  setup [<path>]
23
24
  setup your XCode project for calabash-ios (EXPERIMENTAL)
25
+ update [target]
26
+ updates one of the following targets: hooks
24
27
  download
25
28
  install latest compatible version of calabash.framework
26
29
  check [{<path to .ipa>|<path to .app>}]
@@ -290,4 +290,50 @@ def validate_app(app)
290
290
  end
291
291
  end
292
292
 
293
+ end
294
+
295
+
296
+ def update(args)
297
+ if args.length > 0
298
+ target = args[0]
299
+ unless UPDATE_TARGETS.include?(target)
300
+ msg("Error") do
301
+ puts "Invalid target #{target}. Must be one of: #{UPDATE_TARGETS.join(' ')}"
302
+ end
303
+ exit 1
304
+ end
305
+
306
+
307
+
308
+ target_file = "features/support/launch.rb"
309
+ msg("Question") do
310
+ puts "I'm about to update the #{target_file} file."
311
+ puts "Please hit return to confirm that's what you want."
312
+ end
313
+ exit 2 unless STDIN.gets.chomp == ''
314
+
315
+
316
+ unless File.exist?(target_file)
317
+ msg("Error") do
318
+ puts "Unable to find file #{target_file}"
319
+ puts "Please change directory so that #{target_file} exists."
320
+ end
321
+ exit 1
322
+ end
323
+ new_launch_script = File.join(@script_dir,"launch.rb")
324
+
325
+ FileUtils.cp(new_launch_script, target_file, :verbose => true)
326
+
327
+ msg("Info") do
328
+ puts "File copied.\n"
329
+ puts "Launch on device using environment variable DEVICE_TARGET=device."
330
+ end
331
+ else
332
+ msg("Error") do
333
+ puts "update must take one of the following targets: #{UPDATE_TARGETS.join(' ')}"
334
+ end
335
+ exit 1
336
+
337
+ end
338
+
293
339
  end
@@ -44,6 +44,9 @@ Usage: calabash-ios <command-name> [parameters]
44
44
  If something goes wrong. Close Xcode and copy project.pbxproj.bak
45
45
  to project.pbxproj inside your .xcodeproj folder.
46
46
 
47
+ update [target]
48
+ updates one of the following targets: hooks
49
+
47
50
  download [opt_path]?
48
51
  copies current compatible version of calabash.framework to your project.
49
52
  It should be run from a directory containing an Xcode project,
@@ -325,7 +325,12 @@ module Calabash
325
325
  device = options["DEVICE"] || ENV["DEVICE"] || "iphone"
326
326
 
327
327
  unless os
328
- major = Calabash::Cucumber::SimulatorHelper.ios_major_version
328
+ if @calabash_launcher && @calabash_launcher.active?
329
+ major = @calabash_launcher.ios_major_version
330
+ else
331
+ major = Calabash::Cucumber::SimulatorHelper.ios_major_version
332
+ end
333
+
329
334
  unless major
330
335
  raise <<EOF
331
336
  Unable to determine iOS major version
@@ -471,24 +476,28 @@ EOF
471
476
  end
472
477
 
473
478
 
474
- def start_app_in_background(path=nil, sdk = nil, version = 'iphone', args = nil)
475
-
476
- if path.nil?
477
- path = ENV['APP_BUNDLE_PATH'] || (defined?(APP_BUNDLE_PATH) && APP_BUNDLE_PATH)
478
- end
479
- app_bundle_path = Calabash::Cucumber::SimulatorHelper.app_bundle_or_raise(path)
479
+ ## args :app for device bundle id, for sim path to app
480
+ ##
481
+ def start_test_server_in_background(args={})
482
+ target = args[:device_target] || :simulator
483
+ stop_test_server
484
+ @calabash_launcher = Calabash::Cucumber::Launcher.new(target)
485
+ @calabash_launcher.relaunch(args)
480
486
 
481
- @ios_device = RunLoop.run(:app => app_bundle_path)
482
487
  end
483
488
 
484
- def send_uia_command(opts ={})
485
- RunLoop.send_command(opts[:device] ||@ios_device, opts[:command])
489
+ def stop_test_server
490
+ if @calabash_launcher
491
+ @calabash_launcher.stop
492
+ end
486
493
  end
487
494
 
488
- def stop_background_app(stop_spec = nil)
489
-
490
- @ios_device = RunLoop.stop(stop_spec || @ios_device)
491
-
495
+ def send_uia_command(opts ={})
496
+ run_loop = opts[:run_loop] || (@calabash_launcher && @calabash_launcher.active? && @calabash_launcher.run_loop)
497
+ command = opts[:command]
498
+ raise ArgumentError, 'please supply :run_loop or instance var @calabash_launcher' unless run_loop
499
+ raise ArgumentError, 'please supply :command' unless command
500
+ RunLoop.send_command(run_loop, opts[:command])
492
501
  end
493
502
 
494
503
 
@@ -0,0 +1,155 @@
1
+ require 'calabash-cucumber/launch/simulator_helper'
2
+ require 'sim_launcher'
3
+ require 'run_loop'
4
+
5
+
6
+ class Calabash::Cucumber::Launcher
7
+ attr_accessor :run_loop
8
+ attr_accessor :device_target
9
+ attr_accessor :ios_version
10
+
11
+ def initialize(device_target=:simulator)
12
+ self.device_target = device_target
13
+ end
14
+
15
+ class CalabashLauncherTimeoutErr < Timeout::Error
16
+ end
17
+
18
+ def calabash_no_stop?
19
+ ENV['NO_LAUNCH']=="1" or ENV['NO_STOP']=="1"
20
+ end
21
+
22
+ def device_target?
23
+ ENV['DEVICE_TARGET'] == 'device'
24
+ end
25
+
26
+ def simulator_target?
27
+ ENV['DEVICE_TARGET'] == 'simulator'
28
+ end
29
+
30
+ def active?
31
+ (simulator_target? || device_target?) && (not run_loop.nil?)
32
+ end
33
+
34
+ def ios_major_version
35
+ v = ios_version
36
+ (v && v.split('.')[0])
37
+ end
38
+
39
+
40
+ def reset_app_jail(sdk, app_path)
41
+ return if device_target?
42
+
43
+ app = File.basename(app_path)
44
+ bundle = `find "#{ENV['HOME']}/Library/Application Support/iPhone Simulator/#{sdk}/Applications/" -type d -depth 2 -name "#{app}" | head -n 1`
45
+ return if bundle.empty? # Assuming we're already clean
46
+
47
+ sandbox = File.dirname(bundle)
48
+ ['Library', 'Documents', 'tmp'].each do |dir|
49
+ FileUtils.rm_rf(File.join(sandbox, dir))
50
+ end
51
+ end
52
+
53
+ def relaunch(args={})
54
+ RunLoop.stop(run_loop) if run_loop
55
+
56
+ if device_target?
57
+ default_args = {:app => ENV['BUNDLE_ID']}
58
+ self.run_loop = RunLoop.run(default_args.merge(args))
59
+ else
60
+
61
+ sdk = ENV['SDK_VERSION'] || SimLauncher::SdkDetector.new().latest_sdk_version
62
+ path = Calabash::Cucumber::SimulatorHelper.app_bundle_or_raise(app_path)
63
+ if ENV['RESET_BETWEEN_SCENARIOS']=="1"
64
+ reset_app_jail(sdk, path)
65
+ end
66
+
67
+ if simulator_target?
68
+ device = (ENV['DEVICE'] || 'iphone').to_sym
69
+ default_args = {:app => path, :device => device}
70
+ self.run_loop = RunLoop.run(default_args.merge(args))
71
+ else
72
+ ## sim launcher
73
+ Calabash::Cucumber::SimulatorHelper.relaunch(path, sdk, ENV['DEVICE'] || 'iphone', args)
74
+ end
75
+
76
+ end
77
+ ensure_connectivity
78
+ end
79
+
80
+
81
+ def ensure_connectivity
82
+ begin
83
+ max_retry_count = (ENV['MAX_CONNECT_RETRY'] || 10).to_i
84
+ timeout = (ENV['CONNECT_TIMEOUT'] || 30).to_i
85
+ retry_count = 0
86
+ connected = false
87
+ puts "Waiting for App to be ready"
88
+ until connected do
89
+ raise "MAX_RETRIES" if retry_count == max_retry_count
90
+ retry_count += 1
91
+ begin
92
+ Timeout::timeout(timeout, CalabashLauncherTimeoutErr) do
93
+ until connected
94
+ begin
95
+ connected = (ping_app == '200')
96
+ break if connected
97
+ rescue Exception => e
98
+ #p e
99
+ #retry
100
+ ensure
101
+ sleep 1 unless connected
102
+ end
103
+ end
104
+ end
105
+ rescue CalabashLauncherTimeoutErr => e
106
+ puts "Timed out...Retry.."
107
+ end
108
+ end
109
+ rescue e
110
+ p e
111
+ msg = "Unable to make connection to Calabash Server at #{ENV['DEVICE_ENDPOINT']|| "http://localhost:37265/"}\n"
112
+ msg << "Make sure you don't have a firewall blocking traffic to #{ENV['DEVICE_ENDPOINT']|| "http://localhost:37265/"}.\n"
113
+ raise msg
114
+ end
115
+ end
116
+
117
+ def ping_app
118
+ url = URI.parse(ENV['DEVICE_ENDPOINT']|| "http://localhost:37265/")
119
+
120
+ http = Net::HTTP.new(url.host, url.port)
121
+ res = http.start do |sess|
122
+ sess.request Net::HTTP::Get.new "version"
123
+ end
124
+ status = res.code
125
+ begin
126
+ http.finish if http and http.started?
127
+ rescue Exception => e
128
+
129
+ end
130
+
131
+ if status=='200'
132
+ version_body = JSON.parse(res.body)
133
+ if version_body['iOS_version']
134
+ self.ios_version = version_body['iOS_version']
135
+ end
136
+ end
137
+
138
+ status
139
+ end
140
+
141
+ def stop
142
+ RunLoop.stop(run_loop)
143
+ end
144
+
145
+ def app_path
146
+ ENV['APP_BUNDLE_PATH'] || (defined?(APP_BUNDLE_PATH) && APP_BUNDLE_PATH)
147
+ end
148
+
149
+ def calabash_notify(world)
150
+ if world.respond_to?(:on_launch)
151
+ world.on_launch
152
+ end
153
+ end
154
+ end
155
+
@@ -3,6 +3,7 @@ require 'calabash-cucumber/tests_helpers'
3
3
  require 'calabash-cucumber/keyboard_helpers'
4
4
  require 'calabash-cucumber/wait_helpers'
5
5
  require 'calabash-cucumber/location'
6
+ require 'calabash-cucumber/launcher'
6
7
  require 'net/http'
7
8
  require 'test/unit/assertions'
8
9
  require 'json'
@@ -99,7 +100,6 @@ module Calabash
99
100
  end
100
101
 
101
102
 
102
-
103
103
  #not officially supported yet
104
104
  #def change_slider_value_to(q, value)
105
105
  # target = value.to_f
@@ -1,6 +1,6 @@
1
1
  module Calabash
2
2
  module Cucumber
3
- VERSION = '0.9.139'
3
+ VERSION = '0.9.140.pre1'
4
4
  FRAMEWORK_VERSION = '0.9.139'
5
5
  end
6
6
  end
data/scripts/launch.rb ADDED
@@ -0,0 +1,49 @@
1
+ ########################################
2
+ # #
3
+ # Important Note #
4
+ # #
5
+ # When running calabash-ios tests at #
6
+ # www.lesspainful.com #
7
+ # this file will be overwritten by #
8
+ # a file which automates #
9
+ # app launch on devices. #
10
+ # #
11
+ # Don't rely on this file being #
12
+ # present when running at #
13
+ # www.lesspainful.com. #
14
+ # #
15
+ # Only put stuff here to automate #
16
+ # iOS Simulator. #
17
+ # #
18
+ # You can put your app bundle path #
19
+ # for automating simulator app start: #
20
+ # Uncomment APP_BUNDLE_PATH =.. #
21
+ # #
22
+ ########################################
23
+
24
+ require 'calabash-cucumber/launcher'
25
+
26
+ # Uncomment and replace ?? appropriately
27
+ # This should point to your Simulator build
28
+ # which includes calabash framework
29
+ # this is usually the Calabash build configuration
30
+ # of your production target.
31
+ #APP_BUNDLE_PATH = "~/Library/Developer/Xcode/DerivedData/??/Build/Products/Calabash-iphonesimulator/??.app"
32
+ #
33
+
34
+
35
+ Before do |scenario|
36
+ @calabash_launcher = Calabash::Cucumber::Launcher.new
37
+ @calabash_launcher.relaunch
38
+ @calabash_launcher.calabash_notify(self)
39
+ end
40
+
41
+ After do |scenario|
42
+ unless @calabash_launcher.calabash_no_stop?
43
+ if @calabash_launcher.active?
44
+ @calabash_launcher.stop
45
+ else
46
+ Calabash::Cucumber::SimulatorHelper.stop
47
+ end
48
+ end
49
+ end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calabash-cucumber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.139
5
- prerelease:
4
+ version: 0.9.140.pre1
5
+ prerelease: 8
6
6
  platform: ruby
7
7
  authors:
8
8
  - Karl Krukow
@@ -211,6 +211,7 @@ files:
211
211
  - lib/calabash-cucumber/ibase.rb
212
212
  - lib/calabash-cucumber/keyboard_helpers.rb
213
213
  - lib/calabash-cucumber/launch/simulator_helper.rb
214
+ - lib/calabash-cucumber/launcher.rb
214
215
  - lib/calabash-cucumber/location.rb
215
216
  - lib/calabash-cucumber/operations.rb
216
217
  - lib/calabash-cucumber/resources/cell_swipe_ios4_ipad.base64
@@ -298,6 +299,7 @@ files:
298
299
  - scripts/data/.GlobalPreferences.plist
299
300
  - scripts/data/clients.plist
300
301
  - scripts/data/com.apple.Accessibility.plist
302
+ - scripts/launch.rb
301
303
  - scripts/reset_simulator.scpt
302
304
  - staticlib/calabash.framework.zip
303
305
  homepage: http://calaba.sh
@@ -315,9 +317,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
315
317
  required_rubygems_version: !ruby/object:Gem::Requirement
316
318
  none: false
317
319
  requirements:
318
- - - ! '>='
320
+ - - ! '>'
319
321
  - !ruby/object:Gem::Version
320
- version: '0'
322
+ version: 1.3.1
321
323
  requirements: []
322
324
  rubyforge_project:
323
325
  rubygems_version: 1.8.23