brazenhead 0.4.1 → 0.4.2

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.
Binary file
@@ -0,0 +1,15 @@
1
+ Feature: Using the Brazenhead target
2
+
3
+ Scenario: Retrieving Id Values
4
+ When I call "id_from_name" with "snack" on the target "Brazenhead"
5
+ Then I should receive an id value back from the Brazenhead module
6
+
7
+ Scenario: Clicking on spinner items by id
8
+ Given I'm on the controls screen
9
+ When I select item "4" from the spinner with id "spinner1"
10
+ Then the text "Jupiter" is selected in the spinner
11
+
12
+ Scenario: Clicking on spinner items by view
13
+ Given I'm on the controls screen
14
+ When I select item "6" from the spinner view with id "spinner1"
15
+ Then the text "Uranus" is selected in the spinner
@@ -0,0 +1,32 @@
1
+ When /^I call "(.*?)" with "(.*?)" on the target "(.*?)"$/ do |method, arg, target|
2
+ @driver.send method, arg, :target => target
3
+ end
4
+
5
+ Then /^I should receive an id value back from the Brazenhead module$/ do
6
+ @driver.last_response.body.to_i.should be > 0
7
+ end
8
+
9
+ Given /^I'm on the controls screen$/ do
10
+ @driver.click_on_text "Views"
11
+ @driver.click_on_text "Controls"
12
+ @driver.click_on_text "Light Theme"
13
+ end
14
+
15
+ When /^I select item "(.*?)" from the spinner with id "(.*?)"$/ do |index, id|
16
+ @driver.chain_calls do |device|
17
+ device.id_from_name id, :variable => '@@the_id@@', :target => 'Brazenhead'
18
+ device.press_spinner_item_by_id '@@the_id@@', index.to_i, :target => 'Brazenhead'
19
+ end
20
+ end
21
+
22
+ When /^I select item "(.*?)" from the spinner view with id "(.*?)"$/ do |index, id|
23
+ @driver.chain_calls do |device|
24
+ device.id_from_name id, :variable => '@@the_id@@', :target => 'Brazenhead'
25
+ device.get_view '@@the_id@@', :variable => '@@the_view@@', :target => 'Robotium'
26
+ device.press_spinner_item '@@the_view@@', index.to_i, :target => 'Brazenhead'
27
+ end
28
+ end
29
+
30
+ Then /^the text "(.*?)" is selected in the spinner$/ do |spinner_text|
31
+ @driver.is_spinner_text_selected(spinner_text).should be_true
32
+ end
data/lib/brazenhead.rb CHANGED
@@ -20,6 +20,10 @@ module Brazenhead
20
20
  @last_response
21
21
  end
22
22
 
23
+ def last_json
24
+ device.last_json
25
+ end
26
+
23
27
  private
24
28
 
25
29
  def call_method_on_driver(method, args)
@@ -28,7 +28,6 @@ module Brazenhead
28
28
  Dir.chdir(dir) do |here|
29
29
  copy_base_files
30
30
  update_test_manifest
31
- store_resources
32
31
  sign test_apk, @keystore
33
32
  reinstall test_apk
34
33
  reinstall @source_apk
@@ -58,12 +57,6 @@ module Brazenhead
58
57
  File.write(file, File.read(file).gsub(match, replacement))
59
58
  end
60
59
 
61
- def store_resources
62
- Dir.mkdir "assets"
63
- dump_resources @source_apk, "assets/resources.txt"
64
- add_file test_apk, "assets/resources.txt"
65
- end
66
-
67
60
  def the_target
68
61
  @the_target ||= manifest_info.package
69
62
  end
@@ -26,11 +26,24 @@ module Brazenhead
26
26
  @last_response
27
27
  end
28
28
 
29
+ def last_json
30
+ body = last_response.body
31
+ begin
32
+ JSON.parse body
33
+ rescue
34
+ primitive_to_json body
35
+ end
36
+ end
37
+
29
38
  private
30
39
 
31
40
  def http
32
41
  @http ||= Net::HTTP.new '127.0.0.1', 7777
33
42
  end
34
43
 
44
+ def primitive_to_json(string)
45
+ JSON.parse("{\"value\": #{string}}")["value"]
46
+ end
47
+
35
48
  end
36
49
  end
@@ -10,11 +10,6 @@ module Brazenhead
10
10
  process.run(*update, *package(apk), *with_the(manifest), *using(path_to(min_sdk)))
11
11
  end
12
12
 
13
- def dump_resources(apk, resource_file)
14
- process.run(*"aapt dump resources".split, apk)
15
- File.write resource_file, process.last_stdout
16
- end
17
-
18
13
  def add_file(apk, file)
19
14
  process.run(*"aapt add".split, apk, file)
20
15
  end
@@ -11,9 +11,9 @@ module Brazenhead
11
11
  @keystore = keystore
12
12
  end
13
13
 
14
- def start(activity)
14
+ def start(activity, base_package = nil)
15
15
  build
16
- instrument(runner, :packageName => their_package, :fullLauncherName => full(activity) , :class => the_test)
16
+ instrument(runner, :packageName => their_package, :fullLauncherName => full(activity, base_package) , :class => the_test)
17
17
  end
18
18
 
19
19
  def stop
@@ -34,8 +34,8 @@ module Brazenhead
34
34
  "#{leandog}.TheTest"
35
35
  end
36
36
 
37
- def full(activity)
38
- "#{their_package}.#{activity}"
37
+ def full(activity, base_package)
38
+ "#{base_package || their_package}.#{activity}"
39
39
  end
40
40
 
41
41
  def their_package
@@ -1,3 +1,3 @@
1
1
  module Brazenhead
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -70,30 +70,6 @@ describe Brazenhead::Builder do
70
70
  end
71
71
  end
72
72
 
73
- context "grabbing resource information" do
74
- it "should retrieve resource information from the target package" do
75
- process.should_receive(:run).with(*"aapt dump resources #{expanded_apk}".split)
76
- server.build_for apk, keystore
77
- end
78
-
79
- it "should create an assets directory for the resource information" do
80
- Dir.should_receive(:mkdir).with("assets")
81
- server.build_for apk, keystore
82
- end
83
-
84
- it "should write the resource information to the assets directory" do
85
- process.should_receive(:last_stdout).and_return("resource info")
86
- resources = "assets/resources.txt"
87
- File.should_receive(:write).with(resources, "resource info")
88
- server.build_for apk, keystore
89
- end
90
-
91
- it "should store the resources in the test server" do
92
- process.should_receive(:run).with(*"aapt add #{driver_apk} assets/resources.txt".split)
93
- server.build_for apk, keystore
94
- end
95
- end
96
-
97
73
  context "updating the manifest" do
98
74
  it "should load the contents of the existing manifest" do
99
75
  File.should_receive(:read).with("AndroidManifest.xml")
@@ -34,4 +34,31 @@ describe Brazenhead::Device do
34
34
  http_response.stub(:body).and_return("the error message")
35
35
  expect { device.send "blah" }.to raise_error(Exception, "the error message")
36
36
  end
37
+
38
+ context "json responses" do
39
+ it "should be able to be returned" do
40
+ http_response.should_receive(:body).and_return("{\"some_actual\": \"json object\"}")
41
+ device.send ""
42
+ device.last_json.should eq({"some_actual" => "json object"})
43
+ end
44
+
45
+ it "should be able to send back strings as normal strings" do
46
+ http_response.should_receive(:body).and_return("\"string only\"")
47
+ device.send ""
48
+ device.last_json.should eq("string only")
49
+ end
50
+
51
+ it "should be able to return numbers only" do
52
+ http_response.should_receive(:body).and_return("123")
53
+ device.send ""
54
+ device.last_json.should eq(123)
55
+ end
56
+
57
+ it "should be able to return boolean values" do
58
+ http_response.should_receive(:body).and_return("false")
59
+ device.send ""
60
+ device.last_json.should be_false
61
+ end
62
+ end
63
+
37
64
  end
@@ -63,6 +63,12 @@ describe Brazenhead::Server do
63
63
  server.start(activity)
64
64
  end
65
65
 
66
+ it "should be able to start activites that are not relative to the base package" do
67
+ expected = {:packageName => 'com.example', :fullLauncherName => 'com.other.SomeActivity', :class => 'com.leandog.brazenhead.TheTest'}
68
+ server.should_receive(:instrument).with(runner, expected)
69
+ server.start(activity, 'com.other')
70
+ end
71
+
66
72
  it "should be able to stop instrumenting" do
67
73
  device = double('brazenhead-device')
68
74
  Brazenhead::Device.should_receive(:new).and_return(device)
@@ -34,5 +34,11 @@ describe Brazenhead do
34
34
  result = driver.foo_bar
35
35
  driver.last_response.should == result
36
36
  end
37
+
38
+ it "should be able to return the json result" do
39
+ http_response.stub(:body).and_return("false")
40
+ driver.foo_bar
41
+ driver.last_json.should be_false
42
+ end
37
43
  end
38
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brazenhead
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-25 00:00:00.000000000 Z
13
+ date: 2012-09-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: childprocess
@@ -87,15 +87,15 @@ extra_rdoc_files: []
87
87
  files:
88
88
  - driver/AndroidManifest.xml
89
89
  - features/brazenhead.feature
90
+ - features/brazenhead_target.feature
90
91
  - features/exception.feature
91
92
  - features/robotium.feature
92
93
  - features/serialization.feature
93
94
  - features/step_definitions/brazenhead_steps.rb
95
+ - features/step_definitions/brazenhead_target_steps.rb
94
96
  - features/step_definitions/exception_steps.rb
95
97
  - features/step_definitions/robotium_steps.rb
96
98
  - features/step_definitions/serialization_steps.rb
97
- - features/step_definitions/string_ids_steps.rb
98
- - features/strings_ids.feature
99
99
  - features/support/ApiDemos.apk
100
100
  - features/support/debug.keystore
101
101
  - features/support/env.rb
@@ -137,12 +137,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
137
  - - ! '>='
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
+ segments:
141
+ - 0
142
+ hash: -1605593656851575320
140
143
  required_rubygems_version: !ruby/object:Gem::Requirement
141
144
  none: false
142
145
  requirements:
143
146
  - - ! '>='
144
147
  - !ruby/object:Gem::Version
145
148
  version: '0'
149
+ segments:
150
+ - 0
151
+ hash: -1605593656851575320
146
152
  requirements: []
147
153
  rubyforge_project:
148
154
  rubygems_version: 1.8.24
@@ -152,15 +158,15 @@ summary: Driver that accepts remote json requests and invokes methods inside And
152
158
  emulator / device.
153
159
  test_files:
154
160
  - features/brazenhead.feature
161
+ - features/brazenhead_target.feature
155
162
  - features/exception.feature
156
163
  - features/robotium.feature
157
164
  - features/serialization.feature
158
165
  - features/step_definitions/brazenhead_steps.rb
166
+ - features/step_definitions/brazenhead_target_steps.rb
159
167
  - features/step_definitions/exception_steps.rb
160
168
  - features/step_definitions/robotium_steps.rb
161
169
  - features/step_definitions/serialization_steps.rb
162
- - features/step_definitions/string_ids_steps.rb
163
- - features/strings_ids.feature
164
170
  - features/support/ApiDemos.apk
165
171
  - features/support/debug.keystore
166
172
  - features/support/env.rb
@@ -1,8 +0,0 @@
1
- When /^I call "(.*?)" with "(.*?)" on the target "(.*?)"$/ do |method, arg, target|
2
- @driver.send method, arg, :target => target
3
- end
4
-
5
- Then /^I should receive an id value back from the Brazenhead module$/ do
6
- @driver.last_response.body.to_i.should be > 0
7
- end
8
-
@@ -1,5 +0,0 @@
1
- Feature: Retrieving id information from Brazenhead
2
-
3
- Scenario: Retrieving Id Values
4
- When I call "id_from_name" with "snack" on the target "Brazenhead"
5
- Then I should receive an id value back from the Brazenhead module