Skip to content

Commit

Permalink
Merge pull request #592 from calabash/feature/issue-577-console-attac…
Browse files Browse the repository at this point in the history
…h-loses-track-of-uia-strategy

Issue 577 console_attach loses track of uia strategy
  • Loading branch information
jmoody committed Nov 5, 2014
2 parents 2a81beb + add4188 commit f777470
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
22 changes: 15 additions & 7 deletions calabash-cucumber/lib/calabash-cucumber/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,29 +105,37 @@ def attach(max_retry=1, timeout=10)
pids_str = `ps x -o pid,command | grep -v grep | grep "instruments" | awk '{printf "%s,", $1}'`
pids = pids_str.split(',').map { |pid| pid.to_i }
pid = pids.first
rl = {}
run_loop = {}
if pid
rl[:pid] = pid
run_loop[:pid] = pid
self.actions= Calabash::Cucumber::InstrumentsActions.new
else
self.actions= Calabash::Cucumber::PlaybackActions.new
end

self.run_loop= rl

# Sets the device attribute.
ensure_connectivity(max_retry, timeout)

if self.device.simulator?
run_loop[:uia_strategy] = :preferences
else
if self.device.ios_major_version < '8'
run_loop[:uia_strategy] = :preferences
else
run_loop[:uia_strategy] = :host
end
end

self.run_loop = run_loop
major = self.device.ios_major_version
if major.to_i >= 7 && self.actions.is_a?(Calabash::Cucumber::PlaybackActions)
puts "\n\n WARNING \n\n"
puts 'Warning Trying to connect to simulator that was not launched by Calabash/instruments.'
puts 'To fix this you must let Calabash or instruments launch the app'
puts 'Continuing... query et al will work.'
puts "\n\n WARNING \n\n"
puts "Please read: https://github.com/calabash/calabash-ios/wiki/A0-UIAutomation---instruments-problems"
puts 'Please read: https://github.com/calabash/calabash-ios/wiki/A0-UIAutomation---instruments-problems'
end


self
end

Expand Down
32 changes: 32 additions & 0 deletions calabash-cucumber/spec/integration/launcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,36 @@
end
end

describe '#attach' do
it 'can attach to a running instruments instance' do
ENV.delete('DEVICE_TARGET')
sim_control = RunLoop::SimControl.new
options =
{
:app => Resources.shared.app_bundle_path(:lp_simple_example),
:device_target => 'simulator',
:no_stop => true,
:sim_control => sim_control,
:launch_retries => Resources.shared.travis_ci? ? 5 : 2
}
launcher.relaunch(options)
expect(launcher.run_loop).not_to be == nil

other_launcher = Calabash::Cucumber::Launcher.new
other_launcher.attach

expect(other_launcher.run_loop).not_to be nil
expect(other_launcher.run_loop[:uia_strategy]).to be == :preferences

Open3.popen3('sh') do |stdin, stdout, stderr, _|
stdin.puts 'bundle exec calabash-ios console <<EOF'
stdin.puts 'console_attach'
stdin.puts "touch 'textField'"
stdin.puts 'EOF'
stdin.close
expect(stdout.read.strip[/Error/,0]).to be == nil
expect(stderr.read.strip).to be == ''
end
end
end
end

0 comments on commit f777470

Please sign in to comment.