selendroid 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7781e4c0ddf416bd42dec1e3e51cec402f3a7903
4
- data.tar.gz: b904903697ac1afb4874e2e72af12edf617d622d
3
+ metadata.gz: 14c9a302e098b43e724d3a8da6cdec5f1031f09d
4
+ data.tar.gz: 1f607d7aacbbfab0e272e34fa7cdee3dbe8fc480
5
5
  SHA512:
6
- metadata.gz: 395dc79ce0bb8a460addcc4e628e72b2313a3d1283ae020c6afc83375e5085037f65a9fd39255aca76619a800018f9a6f8a3716afc22a613918c74efcb473ac3
7
- data.tar.gz: 091b3564573432bece4525dbbfe7373212a6cf399463e0c5558e0d23d86ab9c50271c337b589097b37b027986b57276b3a174bdc4b1cc3c77945562ba884e69d
6
+ metadata.gz: 1c958e755785e94a6a0a8c25e5cf89088be2e36d8525116436bee62601a6f097e2fb820ae122c4801715b33b8eb4c383de81005a8908ec862831baa8a6adf9be
7
+ data.tar.gz: 52f7b559fa48d33c40c5586dc5c92c4f83f91c83e4916c120f7d2c898624a6ecd4e6a52edad9cc2a7b20f648cd64a5cd73c008fbd9dec09479882319cb76dead
data/bin/selendroid CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'fileutils'
4
4
  require 'selendroid/selendroid_builder'
5
+ require 'selendroid/selendroid_driver'
5
6
  require 'rbconfig'
6
7
 
7
8
  # for ruby 1.9.1 and earlier
@@ -19,12 +20,21 @@ def print_comamndline_help
19
20
  Prints more detailed help information.
20
21
  build <apk>
21
22
  Builds the selendroid-server for the given apk.
23
+ build-and-start <apk>
24
+ Builds the selendroid-server for the given apk and starts the
25
+ selendroid server. The app will be resigned with the debug
26
+ certificate and will be installed on the first available An-
27
+ droid device.
28
+ start <apk>
29
+ Starts the selendroid server on the first available Android device.
30
+ Commamd expects that the apps are already installed on the device.
22
31
  shell
23
- Starts the selendroid-server on the device (apps must be already installed) and opens an irb shell with an active WebDriver session.
24
- The selendroid-inspector web app is running on: http://localhost:8080/inspector.
32
+ Starts the selendroid-server on the device (apps must be already in-
33
+ stalled) and opens an irb shell with an active WebDriver session.
25
34
  version
26
35
  prints the gem version
27
- To find help, please visit the official selendroid wiki: http://goo.gl/z30pj
36
+ To find help, please visit the official selendroid wiki:
37
+ http://goo.gl/z30pj
28
38
  EOF
29
39
  end
30
40
 
@@ -56,11 +66,32 @@ elsif cmd == 'shell'
56
66
  exit 0
57
67
  elsif cmd == 'build'
58
68
  raise_if_android_home_not_set
59
- puts "Please specify the app you want to build a selendroid-server for" if (ARGV.empty? or not is_apk_file?(ARGV.first))
69
+ puts "Please specify the app you want to build a selendroid-server for!" if (ARGV.empty? or not is_apk_file?(ARGV.first))
60
70
  while not ARGV.empty? and is_apk_file?(ARGV.first)
61
71
  rebuild_selendroid(relative_to_full_path(ARGV.shift))
62
72
  end
63
73
  exit 0
74
+ elsif cmd=='build-and-start'
75
+ raise_if_android_home_not_set
76
+ puts "Please specify the app you want to automate!" if (ARGV.empty? or not is_apk_file?(ARGV.first))
77
+ while not ARGV.empty? and is_apk_file?(ARGV.first)
78
+ app_apk_under_test = relative_to_full_path(ARGV.shift)
79
+ prepare_device(app_apk_under_test)
80
+ main_activity = get_app_main_activity(app_apk_under_test)
81
+ start_selendroid_server(main_activity)
82
+ wait_for_selendroid_server
83
+ end
84
+ exit 0
85
+ elsif cmd=='start'
86
+ raise_if_android_home_not_set
87
+ puts "Please specify the app you want to automate!" if (ARGV.empty? or not is_apk_file?(ARGV.first))
88
+ while not ARGV.empty? and is_apk_file?(ARGV.first)
89
+ app_apk_under_test = relative_to_full_path(ARGV.shift)
90
+ main_activity = get_app_main_activity(app_apk_under_test)
91
+ start_selendroid_server(main_activity)
92
+ wait_for_selendroid_server
93
+ end
94
+ exit 0
64
95
  elsif cmd == 'version'
65
96
  puts Selendroid::VERSION
66
97
  exit 0
data/irbrc CHANGED
@@ -17,7 +17,8 @@ IRB.conf[:SAVE_HISTORY] = 50
17
17
  IRB.conf[:HISTORY_FILE] = ".irb-history"
18
18
 
19
19
  require 'selendroid/selendroid_driver'
20
- start_selendroid_server
20
+ start_selendroid_server(nil)
21
+ wait_for_selendroid_server
21
22
  start_selendroid_client
22
23
  puts "#################### Selendroid shell ###################".green
23
24
  puts "Selendroid inspector: http://localhost:8090/inspector".green
@@ -0,0 +1,39 @@
1
+ def log(message)
2
+ $stdout.puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} - #{message}".green
3
+ end
4
+
5
+ def adb_command
6
+ if is_windows?
7
+ "#{ENV["ANDROID_HOME"]}\\platform-tools\\adb.exe"
8
+ else
9
+ "#{ENV["ANDROID_HOME"]}/platform-tools/adb"
10
+ end
11
+ end
12
+
13
+ def is_windows?
14
+ (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
15
+ end
16
+
17
+ def aapt_command
18
+ if is_windows?
19
+ "#{ENV["ANDROID_HOME"]}\\platform-tools\\aapt.exe"
20
+ else
21
+ "#{ENV["ANDROID_HOME"]}/platform-tools/aapt"
22
+ end
23
+ end
24
+
25
+ def java_command
26
+ if is_windows?
27
+ "#{ENV["JAVA_HOME"]}\\bin\\java.exe"
28
+ else
29
+ "#{ENV["JAVA_HOME"]}/bin/java"
30
+ end
31
+ end
32
+
33
+ def jarsigner_command
34
+ if is_windows?
35
+ "#{ENV["JAVA_HOME"]}\\bin\\jarsigner.exe"
36
+ else
37
+ "#{ENV["JAVA_HOME"]}/bin/jarsigner"
38
+ end
39
+ end
@@ -1,11 +1,12 @@
1
1
  require "selendroid/version"
2
+ require "selendroid/commands"
2
3
  require 'zip/zip'
3
4
  require 'tempfile'
5
+ require 'colorize'
4
6
 
5
7
  def rebuild_selendroid(app)
6
- aut_base_package = %x[ aapt dump badging '#{app}' | grep package | cut -d '=' -f2-|awk '{ print $1}' | tr -d "'" ]
7
- aut_base_package = aut_base_package.tr("\n","")
8
- puts "Building selendroid-server for package #{aut_base_package.dump}"
8
+ aut_base_package = get_app_base_package(app)
9
+ log "Building selendroid-server for package #{aut_base_package.dump}".green
9
10
 
10
11
  test_server_file_name = selendroid_server_path(aut_base_package)
11
12
  FileUtils.mkdir_p File.dirname(test_server_file_name) unless File.exist? File.dirname(test_server_file_name)
@@ -39,23 +40,84 @@ def rebuild_selendroid(app)
39
40
  raise "Could not sign test server"
40
41
  end
41
42
  end
42
- puts "Done signing the test server. Moved it to #{test_server_file_name}"
43
+ log "Done signing the test server. Moved it to #{test_server_file_name}".green
44
+ test_server_file_name
45
+ end
46
+
47
+ def get_app_base_package(app)
48
+ cmd = "#{aapt_command} dump badging '#{app}' | grep package | cut -d '=' -f2-|awk '{ print $1}' | tr -d \"'\""
49
+ app_base_package = %x[ #{cmd}]
50
+ app_base_package = app_base_package.tr("\n","")
51
+ app_base_package
52
+ end
53
+
54
+ def get_app_main_activity(app)
55
+ cmd ="#{aapt_command} dump badging '#{app}' | grep launchable-activity | cut -d '=' -f2-|awk '{ print $1}' | tr -d \"'\""
56
+ app_main_activity = %x[ #{cmd} ]
57
+ app_main_activity = app_main_activity.tr("\n","")
58
+ app_main_activity
59
+ end
60
+
61
+ def is_app_installed_on_device(app_base_package, device_arg)
62
+ cmd = "#{adb_command} -s #{device_arg} shell pm list packages #{app_base_package}"
63
+ package_name = %x[ #{cmd}]
64
+ if package_name.nil? || package_name.empty?
65
+ return false
66
+ else
67
+ return true
68
+ end
69
+ end
70
+
71
+ def get_first_android_device
72
+ cmd = "#{adb_command} devices | head -2 | tail -1 | awk '{ print $1}'"
73
+ device = %x[ #{cmd}]
74
+ device = device.tr("\n","")
75
+ puts "device '#{device}'"
76
+ if device.nil? || device.empty?
77
+ raise "No running Android device was found. Is the device plugged in or the emulator started?"
78
+ end
79
+ device
80
+ end
81
+
82
+ def prepare_device(app)
83
+ device_serial = get_first_android_device
84
+ log "Using first Android device with serial: #{device_serial}".green
85
+ if is_app_installed_on_device("org.openqa.selndroid",device_serial)
86
+ uninstall_cmd = "#{adb_command} -s #{device_serial} uninstall org.openqa.selendroid"
87
+ %x[ #{uninstall_cmd}]
88
+ end
89
+ selendroid_file_name = rebuild_selendroid(app)
90
+ install_cmd = "#{adb_command} -s #{device_serial} install #{File.expand_path(selendroid_file_name)}"
91
+ %x[ #{install_cmd}]
92
+ log "The selendroid server has been rebuild and installed on the device.".green
93
+
94
+ aut_base_package = get_app_base_package(app)
95
+ aut_main_activity = get_app_main_activity(app)
96
+ if is_app_installed_on_device(aut_base_package,device_serial)
97
+ uninstall_cmd = "#{adb_command} -s #{device_serial} uninstall #{aut_base_package}"
98
+ %x[ #{uninstall_cmd}]
99
+ end
100
+ resigned_apk = "#{app.chomp('.apk')}-debug.apk"
101
+ resign_apk(app,resigned_apk)
102
+ install_cmd = "#{adb_command} -s #{device_serial} install #{resigned_apk}"
103
+ %x[ #{install_cmd}]
104
+ log "The app has been resigned #{File.basename(resigned_apk)} and installed on the device.".green
43
105
  end
44
106
 
45
107
  def is_windows?
46
108
  (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
47
109
  end
48
110
 
111
+ def resign_apk(app_path, dest_path)
112
+ troido_jar = File.join(File.dirname(__FILE__), '..','..', 'lib/troido/re-sign.jar')
113
+ cmd = "#{java_command} -cp #{troido_jar} de.troido.resigner.main.Main #{File.expand_path(app_path)} #{File.expand_path(dest_path)}"
114
+ resign_output= %x[ #{cmd}]
115
+ end
116
+
49
117
  def sign_apk(app_path, dest_path)
50
- if is_windows?
51
- jarsigner_path = "\"#{ENV["JAVA_HOME"]}/bin/jarsigner.exe\""
52
- else
53
- jarsigner_path = "jarsigner"
54
- end
55
118
 
56
- cmd = "#{jarsigner_path} -sigalg MD5withRSA -digestalg SHA1 -signedjar #{dest_path} -storepass android -keystore ~/.android/debug.keystore #{app_path} androiddebugkey"
119
+ cmd = "#{jarsigner_command} -sigalg MD5withRSA -digestalg SHA1 -signedjar #{dest_path} -storepass android -keystore ~/.android/debug.keystore #{app_path} androiddebugkey"
57
120
  unless system(cmd)
58
- puts "jarsigner command: #{cmd}"
59
121
  raise "Could not sign app (#{app_path}"
60
122
  end
61
123
  end
@@ -1,6 +1,10 @@
1
+ require "selendroid/commands"
1
2
  require 'selenium-webdriver'
2
3
  require 'json'
3
4
  require 'colorize'
5
+ require 'retriable'
6
+ require "net/http"
7
+ require 'uri'
4
8
 
5
9
  include Selenium::WebDriver::DriverExtensions::HasInputDevices
6
10
  include Selenium::WebDriver::DriverExtensions::HasTouchScreen
@@ -64,26 +68,39 @@ def helpme
64
68
 
65
69
  end
66
70
 
67
- def start_selendroid_server
68
- selendroid_server_start_cmd = "#{adb_command} shell am instrument -e main_activity '#{ENV["MAIN_ACTIVITY"]}' org.openqa.selendroid/org.openqa.selendroid.ServerInstrumentation"
71
+ def start_selendroid_server(activity)
72
+ main_activity = nil
73
+ if activity.nil?
74
+ main_activity = ENV["MAIN_ACTIVITY"]
75
+ else
76
+ main_activity =activity
77
+ end
78
+ log "Starting selendroid-server with main activity: #{main_activity}"
79
+ selendroid_server_start_cmd = "#{adb_command} shell am instrument -e main_activity '#{main_activity}' org.openqa.selendroid/org.openqa.selendroid.ServerInstrumentation"
69
80
  `#{selendroid_server_start_cmd}`
70
-
81
+ unless ENV["SELENDROID_SERVER_PORT"]
82
+ ENV["SELENDROID_SERVER_PORT"] = "8080"
83
+ end
71
84
  forward_cmd = "#{adb_command} forward tcp:#{ENV["SELENDROID_SERVER_PORT"]} tcp:8080"
72
85
  `#{forward_cmd}`
73
86
  end
74
87
 
75
- def log(message)
76
- $stdout.puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} - #{message}"
77
- end
88
+ def wait_for_selendroid_server
89
+ unless ENV["SELENDROID_SERVER_PORT"]
90
+ ENV["SELENDROID_SERVER_PORT"] = "8080"
91
+ end
92
+ retriable :tries => 5, :interval => 3 do
93
+ url = URI.parse("http://localhost:#{ENV["SELENDROID_SERVER_PORT"]}/wd/hub/status")
94
+ the_request = Net::HTTP::Get.new("#{url.path}")
78
95
 
79
- def adb_command
80
- if is_windows?
81
- %Q("#{ENV["ANDROID_HOME"]}\\platform-tools\\adb.exe")
82
- else
83
- %Q("#{ENV["ANDROID_HOME"]}/platform-tools/adb")
84
- end
85
- end
96
+ the_response = Net::HTTP.start(url.host, url.port) { |http|
97
+ http.request(the_request)
98
+ }
86
99
 
87
- def is_windows?
88
- (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
89
- end
100
+ raise "Response was not 200, response was #{the_response.code}" if the_response.code != "200"
101
+ log "Selendroid server is started.".green
102
+ end
103
+
104
+ end
105
+
106
+
@@ -1,3 +1,3 @@
1
1
  module Selendroid
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -0,0 +1,6 @@
1
+ The re-sign tool is created by troido.de and is published under
2
+ the apache 2.0 licence:
3
+
4
+ * Source code: https://github.com/troido/resign
5
+ * Jar download: http://www.troido.de/en/downloadslsmallgsoftware-a-driverslsmallg/files-download/1_0f7c0da1d4814335bd4142b87385e2ac
6
+
Binary file
data/selendroid.gemspec CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |gem|
17
17
  gem.require_paths = ["lib"]
18
18
  gem.add_dependency( "rubyzip")
19
19
  gem.add_dependency( "colorize")
20
+ gem.add_dependency( "retriable")
20
21
  gem.add_dependency( "awesome_print")
21
22
  gem.add_dependency( "selenium-webdriver")
22
23
  gem.add_dependency( "json")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selendroid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominik Dary
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-08 00:00:00.000000000 Z
11
+ date: 2013-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: retriable
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: awesome_print
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -98,9 +112,12 @@ files:
98
112
  - bin/selendroid-shell.rb
99
113
  - irbrc
100
114
  - lib/selendroid.rb
115
+ - lib/selendroid/commands.rb
101
116
  - lib/selendroid/selendroid_builder.rb
102
117
  - lib/selendroid/selendroid_driver.rb
103
118
  - lib/selendroid/version.rb
119
+ - lib/troido/README.md
120
+ - lib/troido/re-sign.jar
104
121
  - selendroid-prebuild/AndroidManifest.xml
105
122
  - selendroid-prebuild/selendroid-server.apk
106
123
  - selendroid.gemspec