Skip to content

Commit 69cdaaf

Browse files
committed
Allow configuring simulator keyboard
1 parent fc9f7c2 commit 69cdaaf

File tree

5 files changed

+40
-7
lines changed

5 files changed

+40
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
Under the hood, *xcmonkey* uses [iOS Development Bridge](https://fbidb.io/) as a driver, that's why it's pretty smart and can do a lot of things, such as taps, swipes and presses. All that comes «pseudo-random» because it has access to the screen hierarchy, and so can either do actions blindly (like tapping on random points) or precisely (like tapping on the existing elements).
1717

18-
## Requirements
18+
## Prerequisites
1919

2020
```bash
2121
brew install facebook/fb/idb-companion

bin/xcmonkey

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ module Xcmonkey
1616
c.description = 'Runs monkey test'
1717
c.option('-u', '--udid STRING', String, 'Set device UDID')
1818
c.option('-b', '--bundle-id STRING', String, 'Set target bundle identifier')
19-
c.option('-d', '--duration SECONDS', Integer, 'Test duration in seconds')
19+
c.option('-d', '--duration SECONDS', Integer, 'Test duration in seconds. Defaults to `60`')
20+
c.option('-k', '--enable-simulator-keyboard', 'Should simulator keyboard be enabled? Defaults to `true`')
2021
c.action do |args, options|
21-
options.default(duration: 60)
22+
options.default(duration: 60, enable_simulator_keyboard: true)
2223
params = {
2324
udid: options.udid,
2425
bundle_id: options.bundle_id,
25-
duration: options.duration
26+
duration: options.duration,
27+
simulator_keyboard: options.enable_simulator_keyboard
2628
}
2729
Xcmonkey.new(params).run
2830
end

lib/xcmonkey/driver.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
class Driver
2-
attr_accessor :udid, :bundle_id, :duration
2+
attr_accessor :udid, :bundle_id, :duration, :enable_simulator_keyboard
33

44
def initialize(params)
55
self.udid = params[:udid]
66
self.bundle_id = params[:bundle_id]
77
self.duration = params[:duration]
8+
self.enable_simulator_keyboard = params[:enable_simulator_keyboard]
89
ensure_driver_installed
910
end
1011

@@ -76,6 +77,12 @@ def shutdown_simulator
7677
`idb shutdown #{udid}`
7778
end
7879

80+
def configure_simulator_keyboard
81+
shutdown_simulator
82+
keyboard_status = enable_simulator_keyboard ? 0 : 1
83+
`defaults write com.apple.iphonesimulator ConnectHardwareKeyboard #{keyboard_status}`
84+
end
85+
7986
def list_targets
8087
@list_targets ||= `idb list-targets`.split("\n")
8188
@list_targets
@@ -92,8 +99,12 @@ def ensure_app_installed
9299
def ensure_device_exists
93100
device = list_targets.detect { |target| target.include?(udid) }
94101
Logger.error("Can't find device #{udid}") if device.nil?
102+
95103
Logger.info('Device info:', payload: device)
96-
boot_simulator if device.include?('simulator')
104+
if device.include?('simulator')
105+
configure_simulator_keyboard
106+
boot_simulator
107+
end
97108
end
98109

99110
def list_apps

lib/xcmonkey/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module Xcmonkey
2-
VERSION = '0.2.0'
2+
VERSION = '0.3.0'
33
GEM_NAME = 'xcmonkey'
44
end

spec/driver_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,26 @@
122122
expect(driver.press_duration).to be_between(0.5, 1.5)
123123
end
124124

125+
it 'verifies that simulator keyboard can be enabled' do
126+
allow(driver).to receive(:is_simulator_keyboard_enabled?).and_return(false)
127+
driver = described_class.new(udid: udid, bundle_id: bundle_id, enable_simulator_keyboard: true)
128+
expect(driver).to receive(:shutdown_simulator)
129+
driver.configure_simulator_keyboard
130+
keyboard_state = `defaults read com.apple.iphonesimulator`.split("\n").grep(/ConnectHardwareKeyboard/)
131+
expect(keyboard_state).not_to be_empty
132+
expect(keyboard_state.first).to include('0')
133+
end
134+
135+
it 'verifies that simulator keyboard can be disabled' do
136+
allow(driver).to receive(:is_simulator_keyboard_enabled?).and_return(true)
137+
driver = described_class.new(udid: udid, bundle_id: bundle_id, enable_simulator_keyboard: false)
138+
expect(driver).to receive(:shutdown_simulator)
139+
driver.configure_simulator_keyboard
140+
keyboard_state = `defaults read com.apple.iphonesimulator`.split("\n").grep(/ConnectHardwareKeyboard/)
141+
expect(keyboard_state).not_to be_empty
142+
expect(keyboard_state.first).to include('1')
143+
end
144+
125145
it 'verifies that app can be launched' do
126146
expect(Logger).not_to receive(:error)
127147
expect(Logger).to receive(:info)

0 commit comments

Comments
 (0)