briar 0.1.3 → 0.1.4.b1

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: 01af1105eafa64b8a8e2763cf9f2e61196317422
4
- data.tar.gz: 9fc4979cb92bf1d3045f99f2b685cd3c26b7e4cd
3
+ metadata.gz: f2de2d2410ddc9524589489604312c5b4a6512f1
4
+ data.tar.gz: 548da4584b0f8fbafa8d5fae39b469bef887cbfe
5
5
  SHA512:
6
- metadata.gz: 16a81550bb111ba11b13c729e14fca3b357d7aadbc12f4acd7f357272766ccdc214e96354fadfe57b33aad2fe6b85fdcaf7720305cbff0e59310c1c14661c041
7
- data.tar.gz: b37580bc3a4716308584c2d453a4b04744ea10b9d8d73da6e24467f22b16a54733ad6181e65b41049268873c652de9bc41b8e9540dd15c2238a470b0704476ec
6
+ metadata.gz: cc2e61cae457c7343a72fbccf4ba67491c786aea152734873dcda30419268e508c28eec564c6cf2a2eb7656fd0eb7c5beca0e3102190516644177720142b6b02
7
+ data.tar.gz: 62857537e5d132f602138a1f0cad5790e303edbd19914e9da6cfbb71ba656fece8025d2fe8759f93cd5768d61161f58c29d4ec538784872f748e9e4f6c0cea3e
data/bin/briar CHANGED
@@ -18,12 +18,13 @@ require_relative './briar_rm'
18
18
  require_relative './briar_xtc'
19
19
  require_relative './briar_report'
20
20
  require_relative './briar_sim'
21
+ require_relative './briar_tags'
21
22
 
22
23
  num_args = ARGV.length
23
24
 
24
25
 
25
26
  def briar_version
26
- Briar::VERSION
27
+ puts "#{Briar::VERSION}"
27
28
  end
28
29
 
29
30
  if num_args == 0
@@ -63,6 +64,8 @@ if num_args == 2 and ARGV[0] == 'help'
63
64
  print_rm_help
64
65
  when 'sim'
65
66
  print_sim_help
67
+ when 'tags'
68
+ print_tags_help
66
69
  when 'version'
67
70
  print_version_help
68
71
  when '.xamarin'
@@ -95,6 +98,8 @@ case command
95
98
  briar_rm(args)
96
99
  when 'sim'
97
100
  briar_sim(args)
101
+ when 'tags'
102
+ briar_tags(args)
98
103
  when 'xtc'
99
104
  briar_xtc(args)
100
105
 
@@ -1,6 +1,7 @@
1
1
  require_relative './briar_dot_xamarin'
2
2
  require_relative './briar_env'
3
3
 
4
+
4
5
  require 'ansi/logger'
5
6
  @log = ANSI::Logger.new(STDOUT)
6
7
 
@@ -34,16 +35,19 @@ def screenshot_path
34
35
  path
35
36
  end
36
37
 
38
+ #noinspection RubyStringKeysInHashInspection
37
39
  def logging_level
38
40
  {'DEBUG' => ENV['DEBUG'] || '1',
39
41
  'CALABASH_FULL_CONSOLE_OUTPUT' => ENV['CALABASH_FULL_CONSOLE_OUTPUT'] || '1'}
40
42
  end
41
43
 
44
+ #noinspection RubyStringKeysInHashInspection
42
45
  def simulator_variables(sdk_version)
43
46
  {'DEVICE_TARGET' => 'simulator',
44
47
  'SKD_VERSION' => sdk_version}
45
48
  end
46
49
 
50
+ #noinspection RubyStringKeysInHashInspection
47
51
  def device_variables(device)
48
52
  {'DEVICE_TARGET' => read_device_info(device, :udid),
49
53
  'DEVICE_ENDPOINT' => read_device_info(device, :ip),
@@ -90,12 +94,16 @@ def console(device, opts={})
90
94
  # do not be tempted to use IRB.start
91
95
  # this can cause some terrible problems at > exit
92
96
  ##################
93
-
94
- default_opts = default_console_opts()
97
+ default_opts = default_console_opts()
95
98
  opts = default_opts.merge(opts)
96
99
  cmd = ios_console_cmd(device, opts)
97
100
  puts Rainbow(cmd).green
98
- exec cmd
101
+
102
+ if RUBY_VERSION.start_with?('1.8')
103
+ raise 'not supported in ruby 1.8'
104
+ else
105
+ exec cmd
106
+ end
99
107
  end
100
108
 
101
109
 
@@ -27,6 +27,7 @@ def expect_ideviceinstaller
27
27
  @log.fatal{ "expected it here '#{bin_path}'"}
28
28
  exit 1
29
29
  end
30
+ bin_path
30
31
  end
31
32
 
32
33
  def expect_ipa(ipa_path)
@@ -26,6 +26,10 @@ def help_experimental
26
26
  Rainbow('EXPERIMENTAL').underline.magenta
27
27
  end
28
28
 
29
+ def help_not_available_ruby18
30
+ Rainbow('RUBY > 1.8').underline.magenta
31
+ end
32
+
29
33
  def help_deprecated(version, msg)
30
34
  ANSI.cyan { "DEPRECATED #{version} - #{msg}" }
31
35
  end
@@ -74,7 +78,6 @@ def help_see_xtc_profiles_help
74
78
  "see #{Rainbow('$ briar help xtc-profiles').yellow} for details"
75
79
  end
76
80
 
77
-
78
81
  def help_customize
79
82
  Rainbow('CUSTOMIZATION').green
80
83
  end
@@ -207,6 +210,7 @@ def print_console_help
207
210
  #{help_env_var(' IRBRC', 'location of custom .irbrc file - defaults to ./.irbrc')}
208
211
  #{help_env_var(' BUNDLE_EXEC', 'start console with bundle exec - defaults to 0')}
209
212
 
213
+ #{help_not_available_ruby18}
210
214
  EOF
211
215
  end
212
216
 
@@ -309,17 +313,26 @@ def print_xtc_help
309
313
  #{help_command('xtc')}
310
314
  prints the available XTC device sets
311
315
 
312
- #{help_command('xtc <device-set> [profile]')} #{help_experimental} #{help_nyi}
313
- submits a job to the XTC targeting devices specified in < device-set >
314
316
 
317
+ #{help_command('xtc <device-set> [profile]')} #{help_experimental}
318
+ submits a job to the XTC targeting devices specified in < device-set >
315
319
  if no profile is set, the 'default' profile in the xtc-cucumber.yml will be used
316
320
 
321
+ #{help_command('xtc <device-set> <profile> [build args]')} #{help_experimental}
322
+ submits a job to the XTC targeting devices specified in < device-set > using
323
+ the cucumber profile specified by < profile >. you can optionally pass build
324
+ arguments to to control your xamarin build script.
325
+
317
326
  #{help_requires_env_vars}
318
- #{help_env_var(' IPA', 'path to the .ipa you submitting')}
319
- #{help_env_var(' XTC_PROFILES', 'cucumber profiles for the XTC')}
320
- #{help_env_var(' XTC_ACCOUNT', 'name of a directory in ~/.xamarin/test-cloud/<account> that contains the api token')}
327
+ #{help_env_var(' IPA', 'path to the .ipa you submitting')}
328
+ #{help_env_var(' XTC_PROFILES', 'cucumber profiles for the XTC')}
329
+ #{help_env_var(' XTC_ACCOUNT', 'name of a directory in ~/.xamarin/test-cloud/<account> that contains the api token')}
321
330
  #{help_example_comment('if a build script is defined, the .ipa will be built before submission')}
322
- #{help_env_var('IPA_BUILD_SCRIPT', '(optional) script that generates the IPA')}
331
+ #{help_env_var(' IPA_BUILD_SCRIPT', '(optional) script that generates the IPA')}
332
+ #{help_example_comment('if you require other gems besides briar')}
333
+ #{help_env_var(' XTC_OTHER_GEMS_FILE', 'path to a file describing other gems that should be installed on the XTC')}
334
+ #{help_env_var(' XTC_BRIAR_GEM_DEV', "set to '1' to ensure the local version of briar will be uploaded to the XTC'")}
335
+ #{help_env_var('XTC_CALABASH_GEM_DEV', "set to '1' to ensure the local version of calabash will be uploaded to the XTC'")}
323
336
 
324
337
  EOF
325
338
  end
@@ -354,20 +367,31 @@ command, set the #{Rainbow('XTC_PROFILES').cyan} variable to your xtc-profiles.y
354
367
  EOF
355
368
  end
356
369
 
370
+ def print_tags_help
371
+ puts <<EOF
372
+ #{help_command('tags')} #{help_experimental}
373
+ generates a cucumber tag report
374
+
375
+ requires list_tags.rb in features/support/ directory
376
+
377
+ EOF
378
+ end
379
+
357
380
  def print_usage
358
381
  puts <<EOF
359
382
  #{Rainbow("Welcome to briar #{Briar::VERSION}!").cyan}
360
383
 
361
384
  briar help { command } for more information a command
362
385
 
363
- console { sim6 [simulator version] | sim7 [simulator version] | <device-name> }
386
+ console { sim6 [simulator version] | sim7 [simulator version] | <device-name> } #{help_experimental}
364
387
  install { calabash-server | <device-name> }
365
388
  report [device]
366
389
  resign #{help_experimental}
367
390
  rm { sim-targets | dups [project-name] }
368
- sim [{quit | <simulator version>}]
391
+ sim [{quit | <simulator version>}] #{help_experimental}
392
+ tags #{help_experimental}
369
393
  version
370
- xtc [<device-set> [profile]] #{help_experimental} #{help_nyi}
394
+ xtc { [<device-set> [profile]] | [<device-set> <profile> [build args] } #{help_experimental}
371
395
 
372
396
  #{Rainbow('ADDITIONAL HELP TOPICS').green}
373
397
  help .xamarin
@@ -2,6 +2,7 @@ require_relative './briar_dot_xamarin'
2
2
  require_relative './briar_rm'
3
3
  require_relative './briar_env'
4
4
 
5
+ require 'rainbow'
5
6
  require 'ansi/logger'
6
7
 
7
8
  @log = ANSI::Logger.new(STDOUT)
@@ -10,7 +11,7 @@ def ideviceinstaller(device, cmd, opts={})
10
11
  default_opts = {:build_script => ENV['IPA_BUILD_SCRIPT'],
11
12
  :ipa => ENV['IPA'],
12
13
  :bundle_id => expect_bundle_id(),
13
- :ideviceinstaller => expect_ideviceinstaller()}
14
+ :idevice_installer => expect_ideviceinstaller()}
14
15
  opts = default_opts.merge(opts)
15
16
 
16
17
  cmds = [:install, :uninstall, :reinstall]
@@ -23,17 +24,25 @@ def ideviceinstaller(device, cmd, opts={})
23
24
 
24
25
  udid = read_device_info(device, :udid)
25
26
 
27
+ bin_path = opts[:idevice_installer]
28
+
26
29
  if cmd == :install
27
30
  if build_script
28
31
  system "#{build_script}"
29
32
  briar_remove_derived_data_dups
30
33
  end
34
+
31
35
  ipa = opts[:ipa]
32
36
  expect_ipa(ipa)
33
37
 
34
- system "#{bin_path} -u #{udid} --install #{ipa}"
38
+ cmd = "#{bin_path} -u #{udid} --install #{ipa}"
39
+ puts "#{Rainbow(cmd).green}"
40
+ system cmd
35
41
  elsif cmd == :uninstall
36
- system "#{bin_path} -u #{udid} --uninstall #{bundle_id}"
42
+ bundle_id = opts[:bundle_id]
43
+ cmd = "#{bin_path} -u #{udid} --uninstall #{bundle_id}"
44
+ puts "#{Rainbow(cmd).green}"
45
+ system cmd
37
46
  else
38
47
  ideviceinstaller(device, :uninstall)
39
48
  ideviceinstaller(device, :install)
@@ -13,19 +13,18 @@ def briar_remove_cal_targets
13
13
  cal_targets = []
14
14
  Find.find(sim_dir) do |path|
15
15
  if path =~ /.*\-cal.app/
16
- @log.fatal { "found '#{File.basename(path)}' in '#{File.dirname(path)}'" }
16
+ @log.info { "found '#{File.basename(path)}' in '#{File.dirname(path)}'" }
17
17
  cal_targets << File.dirname(path)
18
18
  Find.prune
19
19
  end
20
20
  end
21
21
 
22
22
  if cal_targets.empty?
23
- @log.fatal { "found no *-cal.app targets in '#{sim_dir}'" }
24
- exit 0
25
- end
26
-
27
- cal_targets.each do |path|
28
- FileUtils.rm_r path
23
+ @log.info { "found no *-cal.app targets in '#{sim_dir}'" }
24
+ else
25
+ cal_targets.each do |path|
26
+ FileUtils.rm_r path
27
+ end
29
28
  end
30
29
  end
31
30
 
@@ -53,6 +53,8 @@ def set_default_simulator(device_key)
53
53
  raise "#{device_key} was not one of '#{hash.keys}'"
54
54
  end
55
55
 
56
+ kill_simulator
57
+
56
58
  open_simulator
57
59
  current_device = default_simulated_device()
58
60
  unless current_device.eql?(device_key)
@@ -0,0 +1,19 @@
1
+ require 'rainbow'
2
+ require 'ansi/logger'
3
+
4
+
5
+ @log = ANSI::Logger.new(STDOUT)
6
+
7
+
8
+ def briar_tags(args)
9
+ arg_len = args.count
10
+
11
+ if arg_len != 0
12
+ @log.warn{ "expected no arguments but found '#{args}' - what can I do with that!?!" }
13
+ exit 1
14
+ end
15
+
16
+ cmd = 'cucumber -d -f Cucumber::Formatter::ListTags'
17
+ puts "#{Rainbow(cmd).green}"
18
+ system(cmd)
19
+ end
@@ -39,7 +39,12 @@ def briar_xtc_submit(device_set, profile, opts={})
39
39
  default_opts = {:build_script => ENV['IPA_BUILD_SCRIPT'],
40
40
  :ipa => ENV['IPA'],
41
41
  :profiles => ENV['XTC_PROFILES'],
42
- :account => expect_xtc_account()}
42
+ :account => expect_xtc_account(),
43
+ :other_gems => ENV['XTC_OTHER_GEMS_FILE'],
44
+ :briar_dev => ENV['XTC_BRIAR_GEM_DEV'],
45
+ :calabash_dev => ENV['XTC_CALABASH_GEM_DEV'],
46
+ :rebuild => true}
47
+
43
48
 
44
49
  opts = default_opts.merge(opts)
45
50
 
@@ -47,25 +52,71 @@ def briar_xtc_submit(device_set, profile, opts={})
47
52
 
48
53
  if build_script
49
54
  expect_build_script(build_script)
50
- system "#{build_script}"
55
+ if opts[:rebuild]
56
+ cmd = "#{build_script}"
57
+ else
58
+ cmd = "#{build_script} -"
59
+ end
60
+ system cmd
51
61
  briar_remove_derived_data_dups
52
62
  end
53
63
 
54
- xtc_gemfile = './xamarin/Gemfile'
55
-
56
- briar_path = `bundle show briar`.strip
57
- calabash_path = `bundle show calabash-cucumber`.strip
58
-
59
- File.open(xtc_gemfile, 'w') { |file|
60
- file.write("source 'https://rubygems.org'\n")
61
- file.write("gem 'calabash-cucumber', :path => '#{calabash_path}'\n")
62
- file.write("gem 'briar', :path => '#{briar_path}'\n")
63
- file.write("gem 'faker'\n")
64
- }
65
-
66
64
  account = opts[:account]
67
65
  api_key = read_api_token(account)
68
66
 
67
+ if opts[:briar_dev] == '1'
68
+ briar_path = `bundle show briar`.strip
69
+ system('gem uninstall briar --no-executables --ignore-dependencies --quiet',
70
+ :err => '/dev/null')
71
+ Dir.chdir(File.expand_path(briar_path)) do
72
+ system 'rake install'
73
+ end
74
+ end
75
+
76
+ if opts[:calabash_dev] == '1'
77
+ calabash_path = `bundle show calabash-cucumber`.strip
78
+ system('gem uninstall calabash-cucumber --no-executables --ignore-dependencies --quiet',
79
+ :err => '/dev/null')
80
+
81
+ Dir.chdir(File.expand_path(calabash_path)) do
82
+ system 'rake install'
83
+ end
84
+ end
85
+
86
+ other_gems = []
87
+ if opts[:other_gems]
88
+ path = File.expand_path(opts[:other_gems])
89
+ File.read(path).split("\n").each do |line|
90
+ # stay 1.8.7 compat
91
+ next if line.strip.length == 0 or line.chars.to_a.first.eql?('#')
92
+ other_gems << line.strip
93
+ end
94
+ end
95
+
96
+ if opts[:briar_dev] == '1' or opts[:calabash_dev] == '1'
97
+
98
+ xtc_gemfile = './xamarin/Gemfile'
99
+
100
+ File.open(xtc_gemfile, 'w') do |file|
101
+ file.write("source 'https://rubygems.org'\n")
102
+ if opts[:calabash_dev]
103
+ calabash_version = `bundle exec calabash-ios version`.strip
104
+ file.write("gem 'calabash-cucumber', '#{calabash_version}'\n")
105
+ end
106
+
107
+ if opts[:briar_dev]
108
+ briar_version = `bundle exec briar version`.strip
109
+ file.write("gem 'briar', '#{briar_version}'\n")
110
+ else
111
+ file.write("gem 'briar'")
112
+ end
113
+
114
+ other_gems.each do |gem|
115
+ file.write("#{gem}\n")
116
+ end
117
+ end
118
+
119
+ end
69
120
 
70
121
  sets = read_device_sets
71
122
  if sets[device_set]
@@ -76,15 +127,10 @@ def briar_xtc_submit(device_set, profile, opts={})
76
127
 
77
128
  ipa = File.basename(File.expand_path(expect_ipa(opts[:ipa])))
78
129
 
79
- cmd = "bundle exec test-cloud submit #{ipa} #{api_key} -d #{device_set} -c cucumber.yml -p #{profile}"
130
+ cmd = "test-cloud submit #{ipa} #{api_key} -d #{device_set} -c cucumber.yml -p #{profile}"
80
131
  puts Rainbow("cd xamarin; #{cmd}").green
81
- begin
82
- Dir.chdir('./xamarin') do
83
- system cmd
84
- end
85
- rescue
86
- # probably useless
87
- @log.fatal{ 'could not submit job' }
132
+ Dir.chdir('./xamarin') do
133
+ exec cmd
88
134
  end
89
135
  end
90
136
 
@@ -99,10 +145,22 @@ def briar_xtc(args)
99
145
  device_set = args[0]
100
146
  profile = arg_len == 1 ? nil : args[1]
101
147
 
102
- if arg_len > 2
103
- @log.warn{ "expected at most 2 args by found '#{args}' - ignoring extra input" }
148
+
149
+ if arg_len == 3
150
+ rebuild_arg = args[2]
151
+ unless rebuild_arg == '-'
152
+ @log.fatal { "unknown optional argument '#{rebuild_arg}' expected '-'" }
153
+ exit 1
154
+ end
155
+ opts = {:rebuild => false}
156
+ else
157
+ opts = {:rebuild => true}
158
+ end
159
+
160
+ if arg_len > 3
161
+ @log.warn{ "expected at most 3 args by found '#{args}' - ignoring extra input" }
104
162
  end
105
163
 
106
- briar_xtc_submit(device_set, profile)
164
+ briar_xtc_submit(device_set, profile, opts)
107
165
  end
108
166
 
@@ -42,7 +42,6 @@ require 'calabash-cucumber'
42
42
  require 'briar/version'
43
43
  require 'briar/briar_core'
44
44
  require 'briar/uia/briar_uia'
45
- require 'briar/uia/briar_ipad_emulation'
46
45
 
47
46
  require 'briar/alerts_and_sheets/alert_view'
48
47
  require 'briar/alerts_and_sheets/action_sheet'
@@ -5,7 +5,7 @@ require_relative '../briar'
5
5
  World(Briar)
6
6
  World(Briar::Core)
7
7
  World(Briar::UIA)
8
- World(Briar::UIA::IPadEmulation)
8
+ #World(Briar::UIA::IPadEmulation)
9
9
  World(Briar::Alerts_and_Sheets)
10
10
  World(Briar::Bars)
11
11
  World(Briar::Control::Button)
@@ -34,10 +34,13 @@ require 'calabash-cucumber/operations'
34
34
  require 'calabash-cucumber/launch/simulator_helper'
35
35
  #noinspection RubyResolve
36
36
  require 'calabash-cucumber/launcher'
37
+ #noinspection RubyResolve
38
+ require 'calabash-cucumber/uia'
37
39
 
38
40
  SIM=Calabash::Cucumber::SimulatorHelper
39
41
 
40
42
  extend Calabash::Cucumber::Operations
43
+ include Calabash::Cucumber::IPad
41
44
 
42
45
  #noinspection RubyUnusedLocalVariable
43
46
  def embed(x,y=nil,z=nil)
@@ -58,7 +61,6 @@ include Briar::Picker::DateManipulation
58
61
  include Briar::Picker::DateSteps
59
62
  include Briar::Core
60
63
  include Briar::UIA
61
- include Briar::UIA::IPadEmulation
62
64
  include Briar::Table
63
65
  include Briar::ImageView
64
66
  include Briar::Label
@@ -1,3 +1,3 @@
1
1
  module Briar
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4.b1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: briar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4.b1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Moody
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-10 00:00:00.000000000 Z
11
+ date: 2014-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbx-require-relative
@@ -145,6 +145,7 @@ files:
145
145
  - bin/briar_resign.rb
146
146
  - bin/briar_rm.rb
147
147
  - bin/briar_sim.rb
148
+ - bin/briar_tags.rb
148
149
  - bin/briar_xtc.rb
149
150
  - briar.gemspec
150
151
  - features/step_definitions/alerts_and_sheets/action_sheet_steps.rb
@@ -199,7 +200,6 @@ files:
199
200
  - lib/briar/table.rb
200
201
  - lib/briar/text_field.rb
201
202
  - lib/briar/text_view.rb
202
- - lib/briar/uia/briar_ipad_emulation.rb
203
203
  - lib/briar/uia/briar_uia.rb
204
204
  - lib/briar/version.rb
205
205
  - spec/spec_helper.rb
@@ -219,14 +219,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
219
219
  version: 1.8.7
220
220
  required_rubygems_version: !ruby/object:Gem::Requirement
221
221
  requirements:
222
- - - '>='
222
+ - - '>'
223
223
  - !ruby/object:Gem::Version
224
- version: '0'
224
+ version: 1.3.1
225
225
  requirements: []
226
226
  rubyforge_project:
227
227
  rubygems_version: 2.2.2
228
228
  signing_key:
229
229
  specification_version: 4
230
- summary: briar-0.1.3
230
+ summary: briar-0.1.4.b1
231
231
  test_files:
232
232
  - spec/spec_helper.rb
@@ -1,174 +0,0 @@
1
- require 'calabash-cucumber'
2
-
3
- module Briar
4
- module UIA
5
- module IPadEmulation
6
-
7
- class Cache
8
-
9
- attr_accessor :window_index
10
-
11
- def initialize
12
- @window_index = nil
13
- end
14
-
15
-
16
- end
17
- # use the apple localization codes
18
- IPAD_1X_2X_BUTTON_LABELS = {
19
- :en => {:emulated_1x => 'Switch to full screen mode',
20
- :emulated_2x => 'Switch to normal mode'}
21
- }
22
-
23
- def ensure_uia_and_ipad()
24
- unless ipad?
25
- screenshot_and_raise 'this function is only for the iPad'
26
- end
27
-
28
- unless ios7?
29
- screenshot_and_raise 'this function only works on iOS 7'
30
- end
31
-
32
- unless uia_available?
33
- screenshot_and_raise 'this function requires the app be launched with instruments'
34
- end
35
- end
36
-
37
-
38
- def ipad_1x_2x_labels_hash(lang_code)
39
- ht = IPAD_1X_2X_BUTTON_LABELS[lang_code]
40
- if ht.nil?
41
- screenshot_and_raise "did not recognize language code '#{lang_code}'"
42
- end
43
- ht
44
- end
45
-
46
- def ipad_1x_2x_labels_array(lang_code)
47
- ht = ipad_1x_2x_labels_hash lang_code
48
- [ht[:emulated_1x], ht[:emulated_2x]]
49
- end
50
-
51
- def uia_ipad_scale(opts={})
52
- default_opts = {:language_code => :en,
53
- :ensure_uia_and_ipad => false,
54
- :cache => Cache.new}
55
- opts = default_opts.merge(opts)
56
-
57
- if opts[:ensure_uia_and_ipad]
58
- ensure_uia_and_ipad()
59
- opts[:ensure_uia_and_ipad] = false
60
- end
61
-
62
-
63
- idx = window_index_of_ipad_1x_2x_button opts
64
-
65
- res = uia("UIATarget.localTarget().frontMostApp().windows()[#{idx}].buttons()[0].label()")
66
- val = res['value']
67
-
68
- candidates = ipad_1x_2x_labels_array(opts[:language_code])
69
-
70
- if val.eql?(candidates[0])
71
- :emulated_1x
72
- else
73
- :emulated_2x
74
- end
75
- end
76
-
77
- def window_index_of_ipad_1x_2x_button(opts={})
78
-
79
- default_opts = {:language_code => :en,
80
- :ensure_uia_and_ipad => false,
81
- :raise_if_not_found => true,
82
- :cache => Cache.new}
83
- opts = default_opts.merge(opts)
84
-
85
- cache = opts[:cache]
86
- return cache.window_index unless cache.window_index.nil?
87
-
88
-
89
- ensure_uia_and_ipad() if opts[:ensure_uia_and_ipad]
90
-
91
- window_count = uia('UIATarget.localTarget().frontMostApp().windows().length')['value']
92
- index = 0
93
-
94
- lang_code = opts[:language_code]
95
- candidates = ipad_1x_2x_labels_array(lang_code)
96
- success = false
97
- loop do
98
- res = uia("UIATarget.localTarget().frontMostApp().windows()[#{index}].buttons()[0].label()")
99
- if candidates.include?(res['value'])
100
- success = true
101
- break
102
- end
103
- index = index + 1
104
- break unless index < window_count
105
- end
106
-
107
- unless success
108
- if opts[:raise_if_not_found]
109
- screenshot_and_raise "could not find window with button label '#{candidates[0]}' or '#{candidates[1]}' - is your an iphone app emulated on an ipad?"
110
- end
111
- index = -1
112
- end
113
- cache.window_index = index
114
- index
115
- end
116
-
117
- def uia_tap_ipad_scale_button(opts={})
118
- default_opts = {:language_code => :en,
119
- :ensure_uia_and_ipad => false,
120
- :step_pause_after_touch => BRIAR_STEP_PAUSE,
121
- :cache => Cache.new}
122
- opts = default_opts.merge(opts)
123
- ensure_uia_and_ipad() if opts[:ensure_uia_and_ipad]
124
-
125
- idx = window_index_of_ipad_1x_2x_button(opts)
126
- uia("UIATarget.localTarget().frontMostApp().windows()[#{idx}].buttons()[0].tap()")
127
- sleep(opts[:step_pause_after_touch])
128
- end
129
-
130
-
131
- def ensure_ipad_emulation_scale(scale, opts={})
132
- allowed = [:emulated_1x, :emulated_2x]
133
- unless allowed.include?(scale)
134
- screenshot_and_raise "'#{scale}' is not one of '#{allowed}' allowed args"
135
- end
136
-
137
- cache = Cache.new
138
-
139
- return unless iphone_app_emulated_on_ipad?
140
-
141
- default_opts = {:language_code => :en,
142
- :ensure_uia_and_ipad => false,
143
- :step_pause_after_touch => BRIAR_STEP_PAUSE,
144
- :cache => cache}
145
- opts = default_opts.merge(opts)
146
-
147
- actual_scale = uia_ipad_scale(opts)
148
-
149
- if actual_scale != scale
150
- uia_tap_ipad_scale_button opts
151
- end
152
- end
153
-
154
- def ensure_ipad_emulation_1x(opts={})
155
- default_opts = {:language_code => :en,
156
- :ensure_uia_and_ipad => false,
157
- :step_pause_after_touch => BRIAR_STEP_PAUSE,
158
- :cache => Cache.new}
159
- opts = default_opts.merge(opts)
160
- ensure_ipad_emulation_scale(:emulated_1x, opts)
161
- end
162
-
163
- def ensure_ipad_emulation_2x(opts={})
164
- default_opts = {:language_code => :en,
165
- :ensure_uia_and_ipad => false,
166
- :step_pause_after_touch => BRIAR_STEP_PAUSE,
167
- :cache => Cache.new}
168
- opts = default_opts.merge(opts)
169
- ensure_ipad_emulation_scale(:emulated_2x, opts)
170
- end
171
-
172
- end
173
- end
174
- end