selendroid 0.2.3 → 0.3.0

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: 12013bb253f5d28c4d82bddc15744e3db5c0536d
4
- data.tar.gz: 556b8e6f820a48be1250db7a85e843f92ac7f551
3
+ metadata.gz: 41fa062891d9e2bf72e3b4a3197293dae252d7e6
4
+ data.tar.gz: d6b9698f140dadeb70f9ed9c2a4c7d57a29d4156
5
5
  SHA512:
6
- metadata.gz: ddd47e822d1b4e813c20ca56ca8f320b5db126801ccd1ded22507fb0a15cee13474ae18440e85986504460555e7089d40fdc5bd954ea651677fd64d2b31d626d
7
- data.tar.gz: 33c46345cb7c0e957e6255d39d8f4e603416e045e56534aa2f5aa1a7231eb132bddbd0044da6dd65a6891105dde3ee7c3db52ee1bef23d0cd5597218b29a8dab
6
+ metadata.gz: 49a06488d8cc4696d0ea31d3edccc26eade1b64236125458423aedb3b252d4240c1cda6be219fd1e54b52d23df98e5223db2d40d05b13f2e501c53a307081b90
7
+ data.tar.gz: 13d08c92b0d7ed1869eea75d5a169be6e3330314d57683f9385e628510382fe3b1d62a094646227086e985e80d1203dc8b3006ecaa159d4519c6e96af4c12fd8
data/.gitignore CHANGED
@@ -8,8 +8,6 @@
8
8
  Gemfile.lock
9
9
  InstalledFiles
10
10
  _yardoc
11
- selendroid-test-app-0.1-SNAPSHOT.apk
12
- selendroid-server-0.0.1.apk
13
11
  coverage
14
12
  doc/
15
13
  lib/bundler/man
data/LICENSE.txt CHANGED
@@ -1,6 +1,4 @@
1
- Copyright (c) 2013 Dary, Dominik
2
-
3
- Apache License 2.0
1
+ Copyright 2013 Selendroid commiters
4
2
 
5
3
  Licensed under the Apache License, Version 2.0 (the "License");
6
4
  you may not use this file except in compliance with the License.
data/README.md CHANGED
@@ -24,6 +24,7 @@ Now you will find your customized selendroid-server. To run the server:
24
24
 
25
25
  A sample test looks like:
26
26
 
27
+ ```java
27
28
  driver = new AndroidDriver(new URL("http://localhost:8080/wd/hub"), getDefaultCapabilities());
28
29
  driver.findElement(By.id("startUserRegistration")).click();
29
30
 
@@ -36,14 +37,10 @@ A sample test looks like:
36
37
  nameInput.sendKeys(user.getName());
37
38
  takeScreenShot("User data entered.");
38
39
  driver.findElement(By.id("btnRegisterUser")).click();
40
+ ```
39
41
 
40
- More details about selendroid can be found in the [wiki](https://github.com/DominikDary/selendroid/wiki/).
42
+ ## You want more details?
41
43
 
42
- Current state
43
- -------------
44
-
45
- Please keep in mind that this project is in very early stages. Help is appreciated. Reach us out in the issues or via email.
46
-
47
- You can track the current progress on the following [link](https://github.com/DominikDary/selendroid/wiki/JSON-Wire-Protocol)
44
+ Please have a look at the [wiki](https://github.com/DominikDary/selendroid/wiki/).
48
45
 
49
46
 
data/bin/selendroid CHANGED
@@ -28,7 +28,7 @@ def print_comamndline_help
28
28
  start <apk>
29
29
  Starts the selendroid server on the first available Android device.
30
30
  Commamd expects that the apps are already installed on the device.
31
- shell
31
+ shell <apk>
32
32
  Starts the selendroid-server on the device (apps must be already in-
33
33
  stalled) and opens an irb shell with an active WebDriver session.
34
34
  version
@@ -47,12 +47,11 @@ def relative_to_full_path(file_path)
47
47
  File.expand_path(file_path)
48
48
  end
49
49
 
50
- def raise_if_android_home_not_set
50
+ def raise_if_android_and_java_home_not_set
51
51
  raise "Please set the ANDROID_HOME environment variable" unless ENV["ANDROID_HOME"]
52
+ raise "Please set the JAVA_HOME environment variable" unless ENV["JAVA_HOME"]
52
53
  end
53
54
 
54
- require File.join(File.dirname(__FILE__), "selendroid-shell")
55
-
56
55
  if (ARGV.length == 0)
57
56
  print_comamndline_help
58
57
  exit 0
@@ -62,17 +61,28 @@ if cmd == 'help'
62
61
  print_comamndline_help
63
62
  exit 0
64
63
  elsif cmd == 'shell'
65
- selendroid_shell
64
+ raise_if_android_and_java_home_not_set
65
+ puts "Please specify the app you want to automate!" if (ARGV.empty? or not is_apk_file?(ARGV.first))
66
+ unless ENV["SELENDROID_SERVER_PORT"]
67
+ ENV["SELENDROID_SERVER_PORT"] = "8080"
68
+ end
69
+ while not ARGV.empty? and is_apk_file?(ARGV.first)
70
+ ENV["MAIN_ACTIVITY"] = get_app_main_activity(relative_to_full_path(ARGV.shift))
71
+ ENV["IRBRC"] = File.join(File.dirname(__FILE__), '..', 'irbrc')
72
+
73
+ system "#{RbConfig.ruby} -S irb"
74
+ end
75
+
66
76
  exit 0
67
77
  elsif cmd == 'build'
68
- raise_if_android_home_not_set
78
+ raise_if_android_and_java_home_not_set
69
79
  puts "Please specify the app you want to build a selendroid-server for!" if (ARGV.empty? or not is_apk_file?(ARGV.first))
70
80
  while not ARGV.empty? and is_apk_file?(ARGV.first)
71
81
  rebuild_selendroid(relative_to_full_path(ARGV.shift))
72
82
  end
73
83
  exit 0
74
84
  elsif cmd=='build-and-start'
75
- raise_if_android_home_not_set
85
+ raise_if_android_and_java_home_not_set
76
86
  puts "Please specify the app you want to automate!" if (ARGV.empty? or not is_apk_file?(ARGV.first))
77
87
  while not ARGV.empty? and is_apk_file?(ARGV.first)
78
88
  app_apk_under_test = relative_to_full_path(ARGV.shift)
@@ -83,7 +93,7 @@ elsif cmd=='build-and-start'
83
93
  end
84
94
  exit 0
85
95
  elsif cmd=='start'
86
- raise_if_android_home_not_set
96
+ raise_if_android_and_java_home_not_set
87
97
  puts "Please specify the app you want to automate!" if (ARGV.empty? or not is_apk_file?(ARGV.first))
88
98
  while not ARGV.empty? and is_apk_file?(ARGV.first)
89
99
  app_apk_under_test = relative_to_full_path(ARGV.shift)
@@ -4,9 +4,9 @@ end
4
4
 
5
5
  def adb_command
6
6
  if is_windows?
7
- "#{ENV["ANDROID_HOME"]}\\platform-tools\\adb.exe"
7
+ "\"#{ENV["ANDROID_HOME"]}/platform-tools/adb.exe\""
8
8
  else
9
- "#{ENV["ANDROID_HOME"]}/platform-tools/adb"
9
+ "\"#{ENV["ANDROID_HOME"]}/platform-tools/adb\""
10
10
  end
11
11
  end
12
12
 
@@ -16,24 +16,32 @@ end
16
16
 
17
17
  def aapt_command
18
18
  if is_windows?
19
- "#{ENV["ANDROID_HOME"]}\\platform-tools\\aapt.exe"
19
+ "\"#{ENV["ANDROID_HOME"]}/platform-tools/aapt.exe\""
20
20
  else
21
- "#{ENV["ANDROID_HOME"]}/platform-tools/aapt"
21
+ "\"#{ENV["ANDROID_HOME"]}/platform-tools/aapt\""
22
22
  end
23
23
  end
24
24
 
25
25
  def java_command
26
26
  if is_windows?
27
- "#{ENV["JAVA_HOME"]}\\bin\\java.exe"
27
+ "\"#{ENV["JAVA_HOME"]}/bin/java.exe\""
28
28
  else
29
- "#{ENV["JAVA_HOME"]}/bin/java"
29
+ "\"#{ENV["JAVA_HOME"]}/bin/java\""
30
30
  end
31
31
  end
32
32
 
33
33
  def jarsigner_command
34
34
  if is_windows?
35
- "#{ENV["JAVA_HOME"]}\\bin\\jarsigner.exe"
35
+ "\"#{ENV["JAVA_HOME"]}/bin/jarsigner.exe\""
36
36
  else
37
- "#{ENV["JAVA_HOME"]}/bin/jarsigner"
37
+ "\"#{ENV["JAVA_HOME"]}/bin/jarsigner\""
38
38
  end
39
- end
39
+ end
40
+
41
+ def keytool_command
42
+ if is_windows?
43
+ "\"#{ENV["JAVA_HOME"]}/bin/keytool.exe\""
44
+ else
45
+ "\"#{ENV["JAVA_HOME"]}/bin/keytool\""
46
+ end
47
+ end
@@ -6,7 +6,7 @@ require 'colorize'
6
6
 
7
7
  def rebuild_selendroid(app)
8
8
  aut_base_package = get_app_base_package(app)
9
- log "Building selendroid-server for package #{aut_base_package.dump}".green
9
+ log "Building selendroid-server for package #{aut_base_package}".green
10
10
 
11
11
  test_server_file_name = selendroid_server_path(aut_base_package)
12
12
  FileUtils.mkdir_p File.dirname(test_server_file_name) unless File.exist? File.dirname(test_server_file_name)
@@ -45,17 +45,29 @@ def rebuild_selendroid(app)
45
45
  end
46
46
 
47
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
48
+ default_cmd = "#{aapt_command} dump badging #{app} "
49
+ windows_cmd = "#{default_cmd} | findSTR package "
50
+ x_cmd = "#{default_cmd} | grep package "
51
+ if is_windows?
52
+ manifest_package = %x[#{windows_cmd} ]
53
+ else
54
+ manifest_package = %x[ #{x_cmd} ]
55
+ end
56
+
57
+ manifest_package.match(/name=['"]([^'"]+)['"]/)[1]
52
58
  end
53
59
 
54
60
  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
61
+ default_cmd = "#{aapt_command} dump badging #{app} "
62
+ windows_cmd = "#{default_cmd} | findSTR launchable-activity "
63
+ x_cmd = "#{default_cmd} | grep launchable-activity "
64
+ if is_windows?
65
+ manifest_activity = %x[ #{windows_cmd}]
66
+ else
67
+ manifest_activity = %x[ #{x_cmd}]
68
+ end
69
+
70
+ manifest_activity.match(/name=['"]([^'"]+)['"]/)[1]
59
71
  end
60
72
 
61
73
  def is_app_installed_on_device(app_base_package, device_arg)
@@ -69,14 +81,25 @@ def is_app_installed_on_device(app_base_package, device_arg)
69
81
  end
70
82
 
71
83
  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}'"
84
+ windows_cmd = "#{adb_command} devices | more +1"
85
+ x_cmd = "#{adb_command} devices | head -2 | tail -1 "
86
+
87
+ if is_windows?
88
+ device = %x[ #{windows_cmd}]
89
+ else
90
+ device = %x[ #{x_cmd}]
91
+ end
92
+ message_no_device = "No running Android device was found. Is the device plugged in or the emulator started?"
93
+ if device.nil? || device.empty?
94
+ raise message_no_device
95
+ end
96
+
97
+ device = device.split[0]
76
98
  if device.nil? || device.empty?
77
- raise "No running Android device was found. Is the device plugged in or the emulator started?"
99
+ raise message_no_device
78
100
  end
79
- device
101
+
102
+ device.tr("\n","")
80
103
  end
81
104
 
82
105
  def prepare_device(app)
@@ -93,6 +116,7 @@ def prepare_device(app)
93
116
 
94
117
  aut_base_package = get_app_base_package(app)
95
118
  aut_main_activity = get_app_main_activity(app)
119
+
96
120
  if is_app_installed_on_device(aut_base_package,device_serial)
97
121
  uninstall_cmd = "#{adb_command} -s #{device_serial} uninstall #{aut_base_package}"
98
122
  %x[ #{uninstall_cmd}]
@@ -115,8 +139,13 @@ def resign_apk(app_path, dest_path)
115
139
  end
116
140
 
117
141
  def sign_apk(app_path, dest_path)
142
+ if !File.file?( Dir.home+"/.android/debug.keystore")
143
+ log "keystore missing - creating one"
144
+ cmd= "#{keytool_command} -genkey -v -keystore #{Dir.home}/.android/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname \"CN=Android Debug,O=Android,C=US\" -storetype JKS -sigalg MD5withRSA -keyalg RSA"
145
+ system(cmd)
146
+ end
118
147
 
119
- cmd = "#{jarsigner_command} -sigalg MD5withRSA -digestalg SHA1 -signedjar #{dest_path} -storepass android -keystore ~/.android/debug.keystore #{app_path} androiddebugkey"
148
+ cmd = "#{jarsigner_command} -sigalg MD5withRSA -digestalg SHA1 -signedjar #{dest_path} -storepass android -keystore #{Dir.home}/.android/debug.keystore #{app_path} androiddebugkey"
120
149
  unless system(cmd)
121
150
  raise "Could not sign app (#{app_path}"
122
151
  end
@@ -77,20 +77,20 @@ def start_selendroid_server(activity)
77
77
  main_activity =activity
78
78
  end
79
79
  log "Starting selendroid-server with main activity: #{main_activity}"
80
- selendroid_server_start_cmd = "#{adb_command} shell am instrument -e main_activity '#{main_activity}' org.openqa.selendroid/org.openqa.selendroid.ServerInstrumentation"
81
- `#{selendroid_server_start_cmd}`
80
+ selendroid_server_start_cmd = "#{adb_command} shell am instrument -e main_activity '#{main_activity}' org.openqa.selendroid/.ServerInstrumentation"
81
+ system(selendroid_server_start_cmd)
82
82
  unless ENV["SELENDROID_SERVER_PORT"]
83
83
  ENV["SELENDROID_SERVER_PORT"] = "8080"
84
84
  end
85
85
  forward_cmd = "#{adb_command} forward tcp:#{ENV["SELENDROID_SERVER_PORT"]} tcp:8080"
86
- `#{forward_cmd}`
86
+ system(forward_cmd)
87
87
  end
88
88
 
89
89
  def wait_for_selendroid_server
90
90
  unless ENV["SELENDROID_SERVER_PORT"]
91
91
  ENV["SELENDROID_SERVER_PORT"] = "8080"
92
92
  end
93
- retriable :tries => 5, :interval => 3 do
93
+ retriable :tries => 10, :interval => 3 do
94
94
  url = URI.parse("http://localhost:#{ENV["SELENDROID_SERVER_PORT"]}/wd/hub/status")
95
95
  the_request = Net::HTTP::Get.new("#{url.path}")
96
96
 
@@ -1,3 +1,3 @@
1
1
  module Selendroid
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -2,7 +2,7 @@
2
2
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
3
  package="org.openqa.selendroid"
4
4
  android:versionCode="1"
5
- android:versionName="0.2" >
5
+ android:versionName="0.3.0" >
6
6
  <uses-sdk android:minSdkVersion="10" />
7
7
 
8
8
  <instrumentation android:name="org.openqa.selendroid.ServerInstrumentation" android:targetPackage="org.openqa.selendroid.testapp" />
data/selendroid.gemspec CHANGED
@@ -11,8 +11,10 @@ Gem::Specification.new do |gem|
11
11
  gem.homepage = "http://dominikdary.github.com/selendroid/"
12
12
  gem.description = %q{"Selenium for Android Apps" (Test automate native or hybrid Android apps with Selendroid.)}
13
13
  gem.summary = %q{Utility so simplify usage of the selendroid-server.}
14
+ ignores = File.readlines('.gitignore').grep(/\S+/).map {|s| s.chomp }
15
+ dotfiles = [ '.gitignore']
16
+ gem.files = (Dir["**/*"].reject { |f| File.directory?(f) || ignores.any? { |i| File.fnmatch(i, f) } } + dotfiles+ Dir["selendroid-prebuild"]).sort
14
17
 
15
- gem.files = `git ls-files`.split("\n") + Dir["selendroid-prebuild"]
16
18
  gem.executables = "selendroid"
17
19
  gem.require_paths = ["lib"]
18
20
  gem.add_dependency( "rubyzip")
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.3
4
+ version: 0.3.0
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-23 00:00:00.000000000 Z
11
+ date: 2013-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -109,7 +109,6 @@ files:
109
109
  - README.md
110
110
  - Rakefile
111
111
  - bin/selendroid
112
- - bin/selendroid-shell.rb
113
112
  - irbrc
114
113
  - lib/selendroid.rb
115
114
  - lib/selendroid/commands.rb
@@ -1,17 +0,0 @@
1
- require 'selendroid/selendroid_driver'
2
-
3
- def selendroid_shell
4
- unless ENV["SELENDROID_SERVER_PORT"]
5
- ENV["SELENDROID_SERVER_PORT"] = "8080"
6
- end
7
-
8
- unless ENV["MAIN_ACTIVITY"]
9
- ENV["MAIN_ACTIVITY"] = "org.openqa.selendroid.testapp.HomeScreenActivity"
10
- end
11
- ENV["IRBRC"] = File.join(File.dirname(__FILE__), '..', 'irbrc')
12
-
13
- system "#{RbConfig.ruby} -S irb"
14
- end
15
-
16
-
17
-