mobmanager 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aef04bb70e5ad38e7e6b0e61999d5e1cd20eff19
4
+ data.tar.gz: 44ec61ad4b32c6008c6f839261f1e29b1e258e69
5
+ SHA512:
6
+ metadata.gz: 056abce902ace629d88e045c2022089e3791564cfe9151fa2ed671b9e3e38cd1889928da920b9e402c02304e781f2e4ab56e1b8f994a6b376e4374c5ef954e10
7
+ data.tar.gz: 1dab5c43178fafdea35829b211a14ec7de43265535623e5c6f45a1d269d84af2275b3b0d4a9fcec715a95c0175eb55da5b645e99f3bd5cf67a9a4cc00ffc21cd
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ .idea/
3
+ *.gem
4
+
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # MobManager
2
+ Manages calls to the Appium server and provides methods to manage interaction with emulators, simulators and devices for Android and iOS
@@ -0,0 +1,72 @@
1
+ require_relative '../../../../mobmanager/mobile/os/os'
2
+
3
+ module Mobile
4
+ module Appium
5
+ module Server
6
+ include OS
7
+
8
+ def start_appium_server
9
+ end_appium_server if node_running?
10
+ puts 'Starting Appium server...'
11
+
12
+ platform = ENV['PLATFORM']
13
+
14
+ if platform == 'android'
15
+ puts '-- Android Platform --'
16
+ if ENV['ANDROID_PHONE'] == 'emulator'
17
+ start_server
18
+ else
19
+ start_server ENV['DEVICE']
20
+ end
21
+ end
22
+
23
+ if platform == 'ios'
24
+ puts '-- IOS Platform --'
25
+ if ENV['IOS_PHONE'] == 'simulator'
26
+ start_server
27
+ else
28
+ start_server ENV['UIUD']
29
+ end
30
+ end
31
+
32
+ sleep 5
33
+ puts "Appium is listening...\n\n"
34
+ end
35
+
36
+ def end_appium_server
37
+ if node_running?
38
+ puts 'Terminating Appium server...'
39
+ if mac?
40
+ termination = system 'pkill node'
41
+ else
42
+ termination = system 'TASKKILL /F /IM node.exe'
43
+ end
44
+ return print_response(termination)
45
+ end
46
+ puts 'No Appium server found.'
47
+ end
48
+
49
+ def node_running?
50
+ if mac?
51
+ return true if %x[ps aux | grep -i node | grep -v grep | wc -l].to_i > 0
52
+ else
53
+ return true if %x[tasklist /FI "IMAGENAME eq node.exe"].to_s.include? 'node'
54
+ end
55
+ false
56
+ end
57
+
58
+ private
59
+ def print_response(success)
60
+ return puts "Appium server terminated successfully." if success
61
+ return puts "Appium server was not found." unless success
62
+ warn '[PANIC]: Something went wrong while terminating the appium server.'
63
+ end
64
+
65
+ def start_server(id=nil, log_level='--log-level error')
66
+ udid = "--udid #{id}" unless id.nil?
67
+ command = "appium #{udid} #{log_level}"
68
+ spawn command
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,18 @@
1
+ module OS
2
+ def mac?
3
+ begin
4
+ os = %x[sw_vers -productName]
5
+ rescue Exception
6
+ os = nil
7
+ end
8
+ if os.nil?
9
+ return false if %x[ver].to_s.downcase.include? 'windows'
10
+ elsif os
11
+ return true if %[sw_vers -productName].to_s.downcase.include? 'mac'
12
+ else
13
+ fail '[PANIC:] Failed to determine OS.'
14
+ return false
15
+ end
16
+ true
17
+ end
18
+ end
@@ -0,0 +1,32 @@
1
+ require_relative '../../../../mobmanager/mobile/platform/android/device'
2
+ require_relative '../../../../mobmanager/mobile/platform/android/emulator'
3
+
4
+ module Platform
5
+ module Android
6
+ module Common
7
+
8
+ include Platform::Android::Device
9
+ include Platform::Android::Emulator
10
+
11
+ def prepare_android_phone(settings = nil)
12
+ if ENV['ANDROID_PHONE'] == 'emulator'
13
+ if ENV['TARGET'] == 'sauce'
14
+ start_emulator(settings)
15
+ else
16
+ terminate_emulator
17
+ start_emulator
18
+ online = wait_for_emulator
19
+ retry_again unless online
20
+ end
21
+ else
22
+ start_android_device
23
+ end
24
+ end
25
+
26
+ def back_button
27
+ %x[adb shell input keyevent KEYCODE_BACK]
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,65 @@
1
+ require_relative '../../../../mobmanager/mobile/os/os'
2
+
3
+ module Platform
4
+ module Android
5
+ module Device
6
+
7
+ include OS
8
+
9
+ ANDROID_DEVICE ||= ENV['DEVICE']
10
+
11
+ def start_android_device
12
+ puts "Setting android device #{ANDROID_DEVICE}"
13
+ system 'adb start-server'
14
+ wait_for_android_device
15
+ end
16
+
17
+ def wait_for_android_device
18
+ max_wait = 5
19
+ counter = 0
20
+
21
+ found = false
22
+ while !found && counter <= max_wait
23
+ devices = %x[adb devices]
24
+ list = list_of_devices(devices)
25
+ begin
26
+ found = is_partial_string_in_array?(ANDROID_DEVICE, list)
27
+ rescue Exception => e
28
+ found = false
29
+ end
30
+ if found
31
+ return puts "Android device #{ANDROID_DEVICE} found."
32
+ end
33
+ counter += 1
34
+ end
35
+ end
36
+
37
+ def terminate_android_device
38
+ system 'adb kill-server'
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ #TODO - move to a helper module maybe adb?
45
+ def list_of_devices(text)
46
+ devices = []
47
+ lines = text.split("\n")
48
+
49
+ lines.each do |ele|
50
+ if ele.include?("\t")
51
+ devices << ele.split("\t")
52
+ else
53
+ devices << ele
54
+ end
55
+ end
56
+
57
+ devices.flatten!
58
+ end
59
+
60
+ def is_partial_string_in_array?(part_of_string, in_array)
61
+ in_array.each do |element|
62
+ return true if part_of_string.include? element
63
+ false
64
+ end
65
+ end
@@ -0,0 +1,134 @@
1
+ require_relative '../../../../mobmanager/mobile/os/os'
2
+ require 'fileutils'
3
+
4
+ module Platform
5
+ module Android
6
+ module Emulator
7
+
8
+ include OS
9
+
10
+ ANDROID_EMULATOR ||= ENV['DEVICE']
11
+ OFFLINE_CHECKS ||= 15
12
+
13
+ def start_emulator(settings = nil)
14
+ if ENV['TARGET'] == 'sauce'
15
+ caps = settings unless settings.nil?
16
+ caps = YAML.load_file(Dir.pwd + '/features/support/settings/android.yml') if settings.nil?
17
+ setup_for_android_sauce caps
18
+ else
19
+ spawn "emulator -avd #{ANDROID_EMULATOR} -no-audio"
20
+ end
21
+ end
22
+
23
+ def setup_for_android_sauce(settings)
24
+ sauce_user = %x[echo $SAUCE_USER].strip
25
+ sauce_key = %x[echo $SAUCE_KEY].strip
26
+ app_path = settings[:apk_path]
27
+ app = app_path.split('/').select{|item| item.include?('.apk')}.first
28
+ puts 'MobTest: Connecting to sauce server...'
29
+ system "curl https://#{sauce_user}:#{sauce_key}@saucelabs.com/rest/v1/users/#{sauce_user}"
30
+ puts 'MobTest: Sending apk to sauce storage'
31
+ system 'curl -u '+"#{sauce_user}:#{sauce_key}"+' -X POST "https://saucelabs.com/rest/v1/storage/'+sauce_user+'/'+app+'?overwrite=true" -H "Content-Type: application/octet-stream" --data-binary @'+app_path
32
+
33
+ end
34
+
35
+ # Wait until emulator is online
36
+ def wait_for_emulator
37
+ online = false
38
+ iterations = 0
39
+ while online == false && iterations < OFFLINE_CHECKS
40
+ iterations += 1
41
+ sleep 3
42
+ puts 'Emulator is offline...'
43
+ list_of_devices = %x[adb devices].to_s
44
+ if list_of_devices.include? 'emulator'
45
+ if list_of_devices.include? 'offline'
46
+ online = false
47
+ else
48
+ puts "Emulator is online...\n\n"
49
+ online = true
50
+ end
51
+ end
52
+ end
53
+
54
+ online
55
+ end
56
+
57
+ def retry_again
58
+ puts 'Something went wrong while getting the AVD. Retrying now...'
59
+ delete_locked_files
60
+ terminate_emulator
61
+ system 'adb kill-server'
62
+ system 'adb start-server'
63
+ start_emulator
64
+ online = wait_for_emulator
65
+ unless online
66
+ fail 'Something went wrong while getting the AVD. Verify the selected AVD exists.'
67
+ end
68
+ end
69
+
70
+ def terminate_emulator
71
+ if emulator_running?
72
+ puts 'Terminating Android emulator...'
73
+ if mac?
74
+ termination = system 'pkill -9 emulator'
75
+ else
76
+ termination = system 'TASKKILL /F /IM emulator-x86.exe'
77
+ cleanup_after_emulator
78
+ end
79
+ print_termination_response(termination)
80
+ end
81
+ end
82
+
83
+ def cleanup_after_emulator
84
+ if mac?
85
+ #remove /private/temp/android-<username>
86
+ path = '/private/tmp'
87
+ files = Dir["#{path}/**"]
88
+ files.each do |file|
89
+ if File.directory(file)
90
+ FileUtils.remove_dir(file) if ((file.include? 'android-'))
91
+ end
92
+ end
93
+ else
94
+ # Delete temp files from AppData/Local/Temp/AndroidEmulator
95
+ user_profile = %x[echo %USERPROFILE%].to_s.chomp!
96
+ Dir.glob(user_profile.gsub("\\", '/')+ '//AppData//Local//Temp//AndroidEmulator//*.tmp').each { |f| File.delete(f) }
97
+ end
98
+ end
99
+
100
+ def emulator_running?
101
+ if mac?
102
+ if %x[ps aux | grep -i emulator | grep -v grep | wc -l].to_i > 0
103
+ return true
104
+ end
105
+ else
106
+ if %x[tasklist /FI "IMAGENAME eq emulator-x86.exe"].to_s.include? 'emulator'
107
+ return true
108
+ end
109
+ end
110
+ false
111
+ end
112
+
113
+ private
114
+ def print_termination_response(success)
115
+ if success
116
+ puts 'Android emulator terminated successfully.'
117
+ elsif !success
118
+ puts 'Android emulator was not found.'
119
+ else
120
+ warn '[PANIC]: Something went wrong while terminating the Android emulator.'
121
+ end
122
+ end
123
+
124
+ def delete_locked_files
125
+ # Delete lock files from ./.android/avd
126
+ path = "#{Dir.home}/.android/avd"
127
+ locks = Dir["#{path}/**/*.lock"]
128
+ locks.each do |file|
129
+ File.delete(file)
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../../../../mobmanager/mobile/platform/ios/device'
2
+ require_relative '../../../../mobmanager/mobile/platform/ios/simulator'
3
+
4
+ module Platform
5
+ module IOS
6
+ module Common
7
+ include Platform::IOS::Device
8
+ include Platform::IOS::Simulator
9
+
10
+ def prepare_ios_phone(settings = nil)
11
+ if ENV['IOS_PHONE'] == 'simulator'
12
+ terminate_simulator
13
+ start_simulator(settings)
14
+ else
15
+ start_ios_device
16
+ end
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ require_relative '../../../../mobmanager/mobile/os/os'
2
+
3
+ module Platform
4
+ module IOS
5
+ module Device
6
+
7
+ def start_ios_device
8
+ #TODO
9
+ puts "start_ios_device place holder"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,74 @@
1
+ require 'yaml'
2
+ require_relative '../../../../mobmanager/mobile/os/os'
3
+
4
+ module Platform
5
+ module IOS
6
+ module Simulator
7
+
8
+ include OS
9
+
10
+ def start_simulator(settings = nil)
11
+ caps = settings unless settings.nil?
12
+ caps = YAML.load_file(Dir.pwd + '/features/support/settings/ios.yml') if settings.nil?
13
+
14
+ unless caps[:workspace_path].nil?
15
+ build_ios_app(caps)
16
+ end
17
+
18
+ if ENV['TARGET'] == 'sauce'
19
+ setup_for_sauce(caps)
20
+ end
21
+ end
22
+
23
+ def build_ios_app(settings)
24
+ puts 'Building ios app with xcodebuild tool...'
25
+ puts 'MobTest: Building ios app with xcodebuild tool...'
26
+ #TODO - Add to PATH?
27
+ puts "ENV['IOS_DERIVED_DATA_PATH'] #{ENV['IOS_DERIVED_DATA_PATH']}"
28
+ fail("MobTest: Failed to determine app_path. Please check your ios.yml settings") if settings[:app_path].nil?
29
+ app = settings[:app_path].split('/').select{|element| element.include?'.app'}.first
30
+ system "xcodebuild -workspace #{settings[:workspace_path]} -scheme \"#{app.gsub('.app', '')}\" -configuration Debug -sdk \"#{settings['sim_sdk']}\" -derivedDataPath \"~/\""
31
+ end
32
+
33
+ def setup_for_sauce(settings)
34
+ sauce_user = %x[echo $SAUCE_USER].strip
35
+ sauce_key = %x[echo $SAUCE_KEY].strip
36
+ app_path = settings[:app_path]
37
+ zipped_app_path = app_path.gsub('.app','.zip')
38
+ app = app_path.split('/').select{|item| item.include?('.app')}.first.gsub('.app','')
39
+ puts 'MobTest: Connecting to sauce server...'
40
+ system "curl https://#{sauce_user}:#{sauce_key}@saucelabs.com/rest/v1/users/#{sauce_user}"
41
+ puts 'MobTest: Zipping iOS app'
42
+ system "zip -r #{zipped_app_path} #{app_path}/"
43
+ zipped_app_path = zipped_app_path.gsub('~',Dir.home)
44
+ puts 'MobTest: Sending zipped app to sauce storage'
45
+ system 'curl -u '+"#{sauce_user}:#{sauce_key}"+' -X POST "https://saucelabs.com/rest/v1/storage/'+sauce_user+'/'+app+'.zip?overwrite=true" -H "Content-Type: application/octet-stream" --data-binary @'+zipped_app_path
46
+ end
47
+
48
+ def terminate_simulator
49
+ spawn 'killall "iOS Simulator"'
50
+ spawn 'killall -9 instruments'
51
+ end
52
+
53
+ def close_and_clean_simulator
54
+ terminate_simulator
55
+ remove_sim_temp_files
56
+ end
57
+
58
+ def remove_sim_temp_files
59
+ if mac?
60
+ #remove ios related files from /private/temp/
61
+ path = '/private/tmp'
62
+ files = Dir["#{path}/**"]
63
+ files.each do |file|
64
+ if File.directory?(file)
65
+ FileUtils.remove_dir(file) if ((file.include? 'com.apple.') || (file.include? 'appium-instruments'))
66
+ end
67
+ end
68
+ else
69
+ # TODO - research in Windows OS
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,3 @@
1
+ module Mobmanager
2
+ VERSION = "0.0.2"
3
+ end
data/lib/mobmanager.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'mobmanager/version'
2
+ require 'mobmanager/mobile/appium/server/server'
3
+ require 'mobmanager/mobile/os/os'
4
+ require 'mobmanager/mobile/platform/android/common'
5
+ require 'mobmanager/mobile/platform/android/device'
6
+ require 'mobmanager/mobile/platform/android/emulator'
7
+ require 'mobmanager/mobile/platform/ios/common'
8
+ require 'mobmanager/mobile/platform/ios/device'
9
+ require 'mobmanager/mobile/platform/ios/simulator'
@@ -0,0 +1,18 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mobmanager/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mobmanager"
8
+ spec.version = Mobmanager::VERSION
9
+ spec.authors = ['Milton Davalos']
10
+ spec.email = ['miltondavalos@gmail.com']
11
+ spec.summary = %q{Provides methods to manage Appium server}
12
+ spec.description = %q{Provides methods to start/end Appium server and management of apps in Android and iOS}
13
+ spec.homepage = 'https://github.com/miltondavalos/MobManager'
14
+ spec.license = 'MIT'
15
+ spec.files = `git ls-files`.split("\n")
16
+ spec.require_paths = ["lib"]
17
+ spec.add_dependency 'require_all'
18
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mobmanager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Milton Davalos
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: require_all
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Provides methods to start/end Appium server and management of apps in
28
+ Android and iOS
29
+ email:
30
+ - miltondavalos@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - .gitignore
36
+ - README.md
37
+ - lib/mobmanager.rb
38
+ - lib/mobmanager/mobile/appium/server/server.rb
39
+ - lib/mobmanager/mobile/os/os.rb
40
+ - lib/mobmanager/mobile/platform/android/common.rb
41
+ - lib/mobmanager/mobile/platform/android/device.rb
42
+ - lib/mobmanager/mobile/platform/android/emulator.rb
43
+ - lib/mobmanager/mobile/platform/ios/common.rb
44
+ - lib/mobmanager/mobile/platform/ios/device.rb
45
+ - lib/mobmanager/mobile/platform/ios/simulator.rb
46
+ - lib/mobmanager/version.rb
47
+ - mobmanager.gemspec
48
+ homepage: https://github.com/miltondavalos/MobManager
49
+ licenses:
50
+ - MIT
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.0.14
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Provides methods to manage Appium server
72
+ test_files: []