-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from bbc/reboot
Add reboot and screenshot options
- Loading branch information
Showing
15 changed files
with
208 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
language: ruby | ||
rvm: | ||
- 2.2 | ||
|
||
script: bundle exec rspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# DeviceAPI - an interface to allow for automation of devices | ||
module DeviceAPI | ||
# iOS component of DeviceAPI | ||
module IOS | ||
# Namespace for all methods encapsulating idevicename calls | ||
class IDeviceDiagnostics < Execution | ||
|
||
# Reboot the device | ||
def self.reboot(device_id) | ||
self.restart(device_id) | ||
end | ||
|
||
def self.restart(device_id) | ||
result = execute("idevicediagnostics restart -u #{device_id}") | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# DeviceAPI - an interface to allow for automation of devices | ||
module DeviceAPI | ||
# iOS component of DeviceAPI | ||
module IOS | ||
# Namespace for all methods encapsulating idevicescreenshot calls | ||
class IDeviceScreenshot < Execution | ||
|
||
# Take a screenshot of the device based on the provided UUID | ||
# @param filename for the output file | ||
def self.capture(args) | ||
result = execute("idevicescreenshot #{args[:filename]} -u #{args[:device_id]}") | ||
raise IDeviceScreenshotError.new(result.stderr) if result.exit != 0 | ||
end | ||
end | ||
|
||
# Error class for the IDeviceScreenshot class | ||
class IDeviceScreenshotError < StandardError | ||
def initialize(msg) | ||
super(msg) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
The directory structure mirrors the directory structure of the `lib` directory. | ||
For example: | ||
|
||
| Module/Class | Lib File | Spec file | | ||
|---|---|--- | ||
| `DeviceAPI::IOS` | `lib/device_api/ios.rb` | `spec/lib/device_api/ios_spec.rb` | | ||
| `DeviceAPI::IOS:IDevice` | `lib/device_api/ios/idevice.rb` | `spec/lib/device_api/ios/idevice_spec.rb` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'device_api/ios/device' | ||
|
||
RSpec.describe DeviceAPI::IOS::Device do | ||
describe '.create' do | ||
it 'creates an instance of DeviceAPI::IOS::Device' do | ||
expect(DeviceAPI::IOS::Device.create({qualifier: '12345'})).to be_a DeviceAPI::IOS::Device | ||
end | ||
|
||
it 'sets the serial to be the qualifier' do | ||
expect(DeviceAPI::IOS::Device.create({qualifier: '12345'}).serial).to eq '12345' | ||
end | ||
|
||
it 'uses serial to override the qualifer if it is set' do | ||
expect(DeviceAPI::IOS::Device.create({qualifier: '12345', serial: '98765'}).serial).to eq '98765' | ||
end | ||
|
||
it 'sets the qualifier' do | ||
expect(DeviceAPI::IOS::Device.create({qualifier: '12345'}).qualifier).to eq '12345' | ||
end | ||
|
||
it 'does not override the qualifier with the serial' do | ||
expect(DeviceAPI::IOS::Device.create({qualifier: '12345', serial: '98765'}).qualifier).to eq '12345' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'device_api/ios/idevice' | ||
|
||
RSpec.describe DeviceAPI::IOS::IDevice do | ||
describe '.devices' do | ||
it 'detects devices attached to device' do | ||
allow(Open3).to receive(:capture3).with('idevice_id -l').and_return( [ "12345678\n23451234\n", '', Struct.new(:exitstatus).new(0) ] ) | ||
allow(Open3).to receive(:capture3).with('ideviceinfo -u 12345678 -k DeviceName').and_return( [ "Device-1\n", '', Struct.new(:exitstatus).new(0) ] ) | ||
allow(Open3).to receive(:capture3).with('ideviceinfo -u 23451234 -k DeviceName').and_return( [ "Device-2\n", '', Struct.new(:exitstatus).new(0) ] ) | ||
|
||
expect(DeviceAPI::IOS::IDevice.devices).to match( | ||
{ | ||
'12345678' => 'Device-1', | ||
'23451234' => 'Device-2' | ||
} | ||
) | ||
end | ||
|
||
it 'detects an empty list of devices' do | ||
allow(Open3).to receive(:capture3).with('idevice_id -l').and_return( [ '', '', Struct.new(:exitstatus).new(0) ] ) | ||
|
||
expect(DeviceAPI::IOS::IDevice.devices).to match({}) | ||
end | ||
end | ||
|
||
describe '#trusted?' do | ||
it 'reports a connected device as trusted' do | ||
allow(Open3).to receive(:capture3).with("ideviceinfo -u '00000001'").and_return( [ "ActivationState: Activated\nActivationStateAcknowledged: true\nBasebandActivationTicketVersion: V2\nBasebandCertId: 2\n", '', Struct.new(:exitstatus).new(0) ] ) | ||
expect(DeviceAPI::IOS::IDevice.trusted?('00000001')).to be_truthy | ||
end | ||
|
||
it 'reports a connected device as not trusted' do | ||
allow(Open3).to receive(:capture3).with("ideviceinfo -u '00000001'").and_return( [ '', "ERROR: Could not connect to lockdownd, error code -19\n", Struct.new(:exitstatus).new(255) ] ) | ||
expect(DeviceAPI::IOS::IDevice.trusted?('00000001')).to be_falsey | ||
end | ||
|
||
it 'reports a not connected device as not trusted' do | ||
# So apparently calling ideviceinfo with an unknown id results in a success | ||
allow(Open3).to receive(:capture3).with("ideviceinfo -u '00000001'").and_return( [ "Usage: ideviceinfo [OPTIONS]\nShow information about a connected device.\n\n -d, --debug enable communication debugging\n", '', Struct.new(:exitstatus).new(0) ] ) | ||
expect(DeviceAPI::IOS::IDevice.trusted?('00000001')).to be_falsey | ||
end | ||
|
||
it 'reports a success with no output as not trusted' do | ||
# This is unlikely but can occur | ||
# Possibly due to a race condition | ||
allow(Open3).to receive(:capture3).with("ideviceinfo -u '00000001'").and_return( [ '', '', Struct.new(:exitstatus).new(0) ] ) | ||
expect(DeviceAPI::IOS::IDevice.trusted?('00000001')).to be_falsey | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.