appium_instrumenter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2675a0f42db37813b11315828f9ac55e5641561f
4
+ data.tar.gz: a9485751504d8e77772ca20740acd782321ae493
5
+ SHA512:
6
+ metadata.gz: 3a24910468decc5b8610033a69f817dae143c868533489e0a1171239bf1a245f7157db9d90067cd5e2f7edc5f5fb3e76cabcbdc9198117c84cf94e76c5532647
7
+ data.tar.gz: 8d474d8ea9d9d59b331353b758c919c817dd4317eebdfab89958b9b17818311b521fcd45584c5be833a6677b5cd9a24734579a7de9fddcee6572e4f8fcc229a9
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .idea
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ appium_instrumenter
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at mail.rajvarma@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in appium_instrumenter.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ appium_instrumenter (0.1.0)
5
+ escape (~> 0.0.4)
6
+ luffa
7
+ rubyzip (~> 1.1)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ awesome_print (1.8.0)
13
+ coderay (1.1.2)
14
+ diff-lcs (1.3)
15
+ escape (0.0.4)
16
+ json (1.8.6)
17
+ luffa (2.0.0)
18
+ awesome_print (~> 1.2)
19
+ json (~> 1.8)
20
+ retriable (>= 1.3.3.1, < 2.1)
21
+ thor (~> 0.19)
22
+ method_source (0.9.0)
23
+ pry (0.11.3)
24
+ coderay (~> 1.1.0)
25
+ method_source (~> 0.9.0)
26
+ rake (10.5.0)
27
+ retriable (2.0.2)
28
+ rspec (3.7.0)
29
+ rspec-core (~> 3.7.0)
30
+ rspec-expectations (~> 3.7.0)
31
+ rspec-mocks (~> 3.7.0)
32
+ rspec-core (3.7.1)
33
+ rspec-support (~> 3.7.0)
34
+ rspec-expectations (3.7.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.7.0)
37
+ rspec-mocks (3.7.0)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.7.0)
40
+ rspec-support (3.7.0)
41
+ rubyzip (1.2.1)
42
+ thor (0.20.0)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ appium_instrumenter!
49
+ bundler (~> 1.16)
50
+ pry
51
+ rake (~> 10.0)
52
+ rspec (~> 3.0)
53
+
54
+ BUNDLED WITH
55
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Rajdeep Varma
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # AppiumInstrumenter
2
+ Part of calabash-android ruby gem to instrument and resign apk.
3
+ This will modify appium uiautomator2 server apk so that it instruments app under test.
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'appium_instrumenter'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install appium_instrumenter
19
+
20
+ ## Usage
21
+
22
+ TODO: Write usage instructions here
23
+
24
+ ## Development
25
+
26
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
27
+
28
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
29
+
30
+ ## Contributing
31
+
32
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/appium_instrumenter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
37
+
38
+ ## Code of Conduct
39
+
40
+ Everyone interacting in the AppiumInstrumenter project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/appium_instrumenter/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,42 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "appium_instrumenter/version"
5
+
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "appium_instrumenter"
9
+ spec.version = AppiumInstrumenter::VERSION
10
+ spec.authors = ["Rajdeep Varma"]
11
+ spec.email = ["mail.rajvarma@gmail.com"]
12
+
13
+ spec.summary = %q{Part of calabash-android ruby gem to instrument and resign apk}
14
+ spec.description = %q{Part of calabash-android ruby gem to instrument and resign apk.
15
+ This will modify appium uiautomator2 server apk so that it instruments app under test.}
16
+ spec.homepage = "https://github.com/rajdeepv/appium_instrumenter"
17
+ spec.license = "MIT"
18
+
19
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
20
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
21
+ if spec.respond_to?(:metadata)
22
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
23
+ else
24
+ raise "RubyGems 2.0 or newer is required to protect against " \
25
+ "public gem pushes."
26
+ end
27
+
28
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
29
+ f.match(%r{^(test|spec|features)/})
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.16"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+ spec.add_development_dependency "pry"
39
+ spec.add_dependency( 'luffa' )
40
+ spec.add_dependency( "rubyzip", "~> 1.1" )
41
+ spec.add_dependency( 'escape', '~> 0.0.4')
42
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "appium_instrumenter"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "appium_instrumenter"
4
+
5
+
6
+ def print_usage
7
+ puts "appium_instrumenter instrument <appium-server-apk-path> <app_under_test_path>"
8
+ puts "OR"
9
+ puts "appium_instrumenter resign <apk-path>"
10
+ end
11
+
12
+ def is_apk_file?(file_path)
13
+ file_path.end_with? ".apk" and File.exist? file_path
14
+ end
15
+
16
+ def relative_to_full_path(file_path)
17
+ File.expand_path(file_path)
18
+ end
19
+
20
+ if ARGV.length == 0
21
+ print_usage
22
+ else
23
+ cmd = ARGV.shift
24
+ case cmd
25
+ when 'instrument'
26
+ app_to_instrument = ARGV[0]
27
+ app_under_test = ARGV[1]
28
+ if ARGV.size < 2
29
+ puts "Please see usage below. Specify two arguments"
30
+ print_usage
31
+ elsif !File.exist?(app_to_instrument)
32
+ puts "Could not find file '#{app_to_instrument}'"
33
+ exit 1
34
+ elsif !is_apk_file?(app_to_instrument)
35
+ puts "'#{app_to_instrument}' is not a valid android application"
36
+ exit 1
37
+ elsif !File.exist?(app_under_test)
38
+ puts "Could not find file '#{app_under_test}'"
39
+ exit 1
40
+ elsif !is_apk_file?(app_under_test)
41
+ puts "'#{app_under_test}' is not a valid android application"
42
+ exit 1
43
+ else
44
+ app_to_instrument_path = relative_to_full_path(app_to_instrument)
45
+ app_under_test_path = relative_to_full_path(app_under_test)
46
+ AppiumInstrumenter.instrument(app_to_instrument_path, app_under_test_path)
47
+ end
48
+
49
+ when 'resign'
50
+ app_to_resign = ARGV[0]
51
+ fail("Please specify app to sign") unless ARGV[0]
52
+ AppiumInstrumenter.unsign_and_resign_apk(relative_to_full_path(app_to_resign))
53
+ else
54
+ puts "Invalid command '#{cmd}'"
55
+ print_usage
56
+ end
57
+ end
@@ -0,0 +1,76 @@
1
+ require "appium_instrumenter/version"
2
+ require "appium_instrumenter/helpers"
3
+ require "appium_instrumenter/java_keystore"
4
+
5
+ module AppiumInstrumenter
6
+ def self.instrument(test_server_apk, app_under_test)
7
+ apk_fingerprint = fingerprint_from_apk(app_under_test)
8
+ log "#{app_under_test} was signed with a certificate with fingerprint #{apk_fingerprint}"
9
+
10
+ keystores = JavaKeystore.get_keystores
11
+ if keystores.empty?
12
+ puts "No keystores found."
13
+ exit 1
14
+ end
15
+ keystore = keystores.find { |k| k.fingerprint == apk_fingerprint}
16
+
17
+ unless keystore
18
+ puts "#{app_under_test} is not signed with any of the available keystores."
19
+ puts "Tried the following keystores:"
20
+ keystores.each do |k|
21
+ puts k.location
22
+ end
23
+ puts ""
24
+ puts "You can resign the app_under_test with #{keystores.first.location} by running:
25
+ appium_instrumenter resign #{app_under_test}"
26
+
27
+ puts ""
28
+ puts "Notice that resigning an app_under_test might break some functionality."
29
+ puts "Getting a copy of the certificate used when the app_under_test was built will in general be more reliable."
30
+
31
+ exit 1
32
+ end
33
+
34
+ test_server_file_name = 'test_servers/appium-uiautomator2-server-debug-androidTest.apk'
35
+ FileUtils.mkdir_p File.dirname(test_server_file_name) unless File.exist? File.dirname(test_server_file_name)
36
+
37
+ unsign_apk(test_server_apk)
38
+ test_server_manifest = File.join(File.dirname(__FILE__), 'appium_instrumenter/resources/AndroidManifest.xml')
39
+
40
+ Dir.mktmpdir do |workspace_dir|
41
+ Dir.chdir(workspace_dir) do
42
+ FileUtils.cp(test_server_apk, "TestServer.apk")
43
+ FileUtils.cp(test_server_manifest, "AndroidManifest.xml")
44
+
45
+ unless system %Q{"#{RbConfig.ruby}" -pi.bak -e "gsub(/#targetPackage#/, '#{package_name(app_under_test)}')" AndroidManifest.xml}
46
+ raise "Could not replace package name in manifest"
47
+ end
48
+
49
+ unless system %Q{"#{Calabash::Android::Dependencies.aapt_path}" package -M AndroidManifest.xml -I "#{Calabash::Android::Dependencies.android_jar_path}" -F dummy.apk}
50
+ raise "Could not create dummy.apk"
51
+ end
52
+
53
+ Calabash::Utils.with_silent_zip do
54
+ Zip::File.new("dummy.apk").extract("AndroidManifest.xml","customAndroidManifest.xml")
55
+ Zip::File.open("TestServer.apk") do |zip_file|
56
+
57
+ zip_file.remove("AndroidManifest.xml")
58
+ zip_file.add("AndroidManifest.xml", "customAndroidManifest.xml")
59
+ end
60
+ end
61
+ end
62
+ keystore.sign_apk("#{workspace_dir}/TestServer.apk", test_server_file_name)
63
+ begin
64
+
65
+ rescue => e
66
+ log e
67
+ raise "Could not sign test server"
68
+ end
69
+ end
70
+ puts "Done signing the test server. Moved it to #{test_server_file_name}"
71
+ end
72
+
73
+ def self.unsign_and_resign_apk(apk_path)
74
+ resign_apk(apk_path)
75
+ end
76
+ end