appium_lib 0.16.0 → 0.17.0

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.
@@ -30,5 +30,5 @@ module Appium
30
30
 
31
31
  add_to_path __FILE__
32
32
 
33
- require 'appium_lib/driver'
33
+ require_relative 'appium_lib/driver'
34
34
  end
@@ -0,0 +1,76 @@
1
+ # encoding: utf-8
2
+ module Appium; end # fix module not defined
3
+ module Android; end
4
+ module Appium::Android::Webview
5
+ class << self
6
+ # firstEmailInput().value = 'example';
7
+ # firstPasswordInput().value = 'example'
8
+ # firstSubmitElement().click();
9
+
10
+ # todo: prevent namespace pollution
11
+ # AppiumWebview = { 'ok': function() { return 'ok'; }, 'ok2': function() { return self.ok(); } }
12
+
13
+ def javascript
14
+ @javascript_webview_helpers ||= <<-'JS'
15
+ function firstTagWithTypeOrName(targetTag, targetType, targetName) {
16
+ var inputs = document.getElementsByTagName(targetTag);
17
+ var inputsLength = inputs.length;
18
+ var target = null;
19
+
20
+ var targetNames = [];
21
+ if (targetName) targetNames = targetName.split(",");
22
+
23
+ for (var i = 0; i < inputsLength; i++) {
24
+ var input = inputs[i];
25
+
26
+ if (targetType) {
27
+ var type = input.type;
28
+ var hasType = typeof type !== "undefined";
29
+ if (hasType && type.trim().toLowerCase() === targetType) {
30
+ target = input;
31
+ break;
32
+ }
33
+ }
34
+
35
+ // type only search will have undefined targetName.
36
+ if (targetName) {
37
+ var name = input.name;
38
+ var hasName = typeof name !== "undefined";
39
+ if (hasName && targetNames.indexOf(name.trim().toLowerCase()) !== -1) {
40
+ target = input;
41
+ break;
42
+ }
43
+ }
44
+ }
45
+
46
+ return target;
47
+ }
48
+
49
+ function firstInputWithTypeOrName(targetType, targetName) {
50
+ return firstTagWithTypeOrName('input', targetType, targetName);
51
+ }
52
+
53
+ function firstEmailInput() {
54
+ return firstInputWithTypeOrName('email', 'id,username');
55
+ }
56
+
57
+ function firstPasswordInput() {
58
+ return firstInputWithTypeOrName('password', 'password');
59
+ }
60
+
61
+ // yahoo uses a submit button
62
+ function firstSubmitElement() {
63
+ return firstTagWithTypeOrName('button', 'submit', 'submit') ||
64
+ firstTagWithTypeOrName('input', 'submit', 'submit') ||
65
+ firstTagWithTypeOrName('a', 'submit', 'submit');
66
+ }
67
+
68
+ // yahoo authorize link
69
+ // <a type="submit"
70
+ function firstAuthElement() {
71
+ return firstTagWithTypeOrName('a', 'submit');
72
+ }
73
+ JS
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,105 @@
1
+ # encoding: utf-8
2
+ # system requires
3
+ require 'net/http'
4
+
5
+ # 3rd party gems
6
+ require 'rubygems'
7
+ require 'json'
8
+ require 'posix/spawn'
9
+ require 'webkit_remote' # https://github.com/pwnall/webkit_remote/
10
+
11
+ module Appium; end # fix module not defined
12
+ module Android; end
13
+ module Appium::Android::Webview
14
+ class << self
15
+ # @private
16
+ def adb_cmd cmd
17
+ _pid, _in, _out, _err = POSIX::Spawn::popen4 cmd, {:err => [:child, :out]}
18
+ _in.close
19
+
20
+ output = ''
21
+
22
+ begin
23
+ Process.waitpid _pid
24
+ output = _out.read
25
+ [_out, _err].each { |io| io.close unless io.nil? || io.closed? }
26
+ rescue # no such process
27
+ end
28
+
29
+ output
30
+ end
31
+
32
+ # @private
33
+ # returns nil if not found
34
+ def package_to_pid package
35
+ # USER PID PPID VSIZE RSS WCHAN PC NAME
36
+ # use detect to return the first match
37
+ ps = adb_cmd('adb shell ps').split("\r\n").detect { |l| l.split(' ').last == package }
38
+ ps ? ps.split(' ')[1].to_i : nil # return pid
39
+ end
40
+
41
+ # @private
42
+ # 1 pid may have many webviews. The path remains the same
43
+ #
44
+ #["00000000: 00000002 00000000 00010000 0001 01 4716 @webview_devtools_remote_1597",
45
+ # "00000000: 00000003 00000000 00000000 0001 03 55080 @webview_devtools_remote_1597",
46
+ # "00000000: 00000003 00000000 00000000 0001 03 55078 @webview_devtools_remote_1597"]
47
+ #
48
+ # returns nil if not found
49
+ def pid_to_webview pid
50
+ return nil if pid.nil?
51
+ # Num RefCount Protocol Flags Type St Inode Path
52
+ cat_proc = adb_cmd 'adb shell cat /proc/net/unix'
53
+ pid_webview = "@webview_devtools_remote_#{pid}"
54
+ found = cat_proc.split("\r\n").detect { |l| l.include?(pid_webview) }
55
+ # must remove '@' prefix for use with adb forward command
56
+ found ? found.split(' ').last.sub('@', '') : nil
57
+ end
58
+
59
+ # @private
60
+ # connect_to_webview package: 'com.example.Package'
61
+ def connect_to_webview opts={}
62
+ package = opts[:package]
63
+ raise 'Must provide package' unless package
64
+ port = opts.fetch :port, 9000
65
+
66
+ unix_socket = pid_to_webview package_to_pid 'com.litl.Woven'
67
+ raise 'No webview found' unless unix_socket
68
+ adb_cmd "adb forward tcp:#{port} localabstract:#{unix_socket}"
69
+ end
70
+
71
+ # @public
72
+ #
73
+ # ```ruby
74
+ # webview = Appium::Android::Webview.attach_to_tab package: 'com.example.Package', url: 'yahoo.com/'
75
+ # webview.location
76
+ # webview.client
77
+ # webview.client.remote_eval Appium::Android::Webview.javascript
78
+ # ```
79
+ #
80
+ # port: is optional.
81
+ #
82
+ # can't be called more than once.
83
+ #
84
+ # returns URL of connected tab.
85
+ def attach_to_tab opts={}
86
+ connect_to_webview package: opts[:package]
87
+ target_url = opts[:url]
88
+ raise 'Must provide :url' unless target_url
89
+ port = opts.fetch(:port, 9000)
90
+
91
+ # webkit_remote defaults to using the last tab.
92
+ # The browser may have many tabs and the last tab is not always correct.
93
+ # Detect the tab by inspecting the URL.
94
+ # https://github.com/pwnall/webkit_remote/blob/590bfd3ace098f2b75d1a07651f36f4392109a23/lib/webkit_remote/top_level.rb#L30
95
+ browser = WebkitRemote::Browser.new host: 'localhost', port: port
96
+ target_tab = browser.tabs.detect { |tab| tab.url.include?(target_url) }
97
+
98
+ client = WebkitRemote::Client.new tab: target_tab, close_browser: true
99
+ document_location = client.remote_eval 'document.location.toString()'
100
+ client.clear_all
101
+
102
+ OpenStruct.new( client: client, location: document_location )
103
+ end
104
+ end
105
+ end
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Appium
3
3
  # Version and Date are defined on the 'Appium' module, not 'Appium::Common'
4
- VERSION = '0.16.0' unless defined? ::Appium::VERSION
5
- DATE = '2014-01-09' unless defined? ::Appium::DATE
4
+ VERSION = '0.17.0' unless defined? ::Appium::VERSION
5
+ DATE = '2014-01-22' unless defined? ::Appium::DATE
6
6
  end
@@ -129,27 +129,29 @@ module Appium
129
129
  require 'selenium-webdriver'
130
130
 
131
131
  # common
132
- require 'common/helper'
133
- require 'common/patch'
134
- require 'common/version'
135
- require 'common/element/button'
136
- require 'common/element/text'
137
- require 'common/element/window'
132
+ require_relative 'common/helper'
133
+ require_relative 'common/patch'
134
+ require_relative 'common/version'
135
+ require_relative 'common/element/button'
136
+ require_relative 'common/element/text'
137
+ require_relative 'common/element/window'
138
138
 
139
139
  # ios
140
- require 'ios/helper'
141
- require 'ios/patch'
142
- require 'ios/element/alert'
143
- require 'ios/element/generic'
144
- require 'ios/element/textfield'
140
+ require_relative 'ios/helper'
141
+ require_relative 'ios/patch'
142
+ require_relative 'ios/element/alert'
143
+ require_relative 'ios/element/generic'
144
+ require_relative 'ios/element/textfield'
145
145
 
146
146
  # android
147
- require 'android/dynamic'
148
- require 'android/helper'
149
- require 'android/patch'
150
- require 'android/element/alert'
151
- require 'android/element/generic'
152
- require 'android/element/textfield'
147
+ require_relative 'android/dynamic'
148
+ require_relative 'android/helper'
149
+ require_relative 'android/patch'
150
+ require_relative 'android/element/alert'
151
+ require_relative 'android/element/generic'
152
+ require_relative 'android/element/textfield'
153
+ require_relative 'android/webview/javascript'
154
+ require_relative 'android/webview/webview'
153
155
 
154
156
  def self.promote_singleton_appium_methods main_module
155
157
  raise 'Driver is nil' if $driver.nil?
@@ -250,12 +252,16 @@ module Appium
250
252
  # quit last driver
251
253
  $driver.driver_quit if $driver
252
254
  opts = {} if opts.nil?
255
+ tmp_opts = {}
256
+
253
257
  # convert to downcased symbols
254
- opts.each_pair { |k,v| opts[k.to_s.downcase.strip.intern] = v }
258
+ opts.each_pair { |k,v| tmp_opts[k.to_s.downcase.strip.intern] = v }
259
+ opts = tmp_opts
255
260
 
256
261
  @custom_url = opts.fetch :server_url, false
257
262
 
258
263
  @compress_xml = opts[:compress_xml] ? true : false
264
+ @fast_clear = opts[:fast_clear] ? true : false
259
265
 
260
266
  @export_session = opts.fetch :export_session, false
261
267
 
@@ -296,7 +302,7 @@ module Appium
296
302
 
297
303
  # :ios, :android, :selendroid
298
304
  @device = opts.fetch :device, ENV['DEVICE'] || :ios
299
- @device = @device.intern # device must be a symbol
305
+ @device = @device.to_s.downcase.intern # device must be a symbol
300
306
 
301
307
  # load common methods
302
308
  extend Appium::Common
@@ -377,7 +383,7 @@ module Appium
377
383
  :'app-package' => @app_package,
378
384
  :'app-activity' => @app_activity,
379
385
  :'app-wait-activity' => @app_wait_activity || @app_activity,
380
- fastClear: false # use adb uninstall/pm install not pm clear
386
+ fastClear: @fast_clear
381
387
  }
382
388
  end
383
389
 
@@ -627,4 +633,4 @@ end # end module Appium
627
633
  # Paging in Pry is annoying :q required to exit.
628
634
  # With pager disabled, the output is similar to IRB
629
635
  # Only set if Pry is defined.
630
- Pry.config.pager = false if defined?(Pry)
636
+ Pry.config.pager = false if defined?(Pry)
@@ -1,3 +1,9 @@
1
+ #### v0.16.0 2014-01-09
2
+
3
+ - [b9264f6](https://github.com/appium/ruby_lib/commit/b9264f66b9dd04eb5221c3a4c4ea17c4eb9ef8aa) Release 0.16.0
4
+ - [18466ea](https://github.com/appium/ruby_lib/commit/18466eae986647b27e3dbb041c591ce2dbc972a2) Hide invisible elements in iOS page output
5
+
6
+
1
7
  #### v0.15.2 2013-12-23
2
8
 
3
9
  - [35b84fd](https://github.com/appium/ruby_lib/commit/35b84fd4a0dcf37fe136451c9bcfa936e1017023) Release 0.15.2
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appium_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - code@bootstraponline.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-09 00:00:00.000000000 Z
11
+ date: 2014-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selenium-webdriver
@@ -67,47 +67,61 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.0.4
69
69
  - !ruby/object:Gem::Dependency
70
- name: rake
70
+ name: posix-spawn
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: 10.0.4
76
- type: :development
75
+ version: 0.3.8
76
+ type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ~>
81
81
  - !ruby/object:Gem::Version
82
- version: 10.0.4
82
+ version: 0.3.8
83
83
  - !ruby/object:Gem::Dependency
84
- name: yard
84
+ name: webkit_remote
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ~>
88
88
  - !ruby/object:Gem::Version
89
- version: 0.8.7.3
89
+ version: 0.4.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 0.4.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 10.0.4
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - ~>
95
109
  - !ruby/object:Gem::Version
96
- version: 0.8.7.3
110
+ version: 10.0.4
97
111
  - !ruby/object:Gem::Dependency
98
- name: posix-spawn
112
+ name: yard
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - ~>
102
116
  - !ruby/object:Gem::Version
103
- version: 0.3.8
117
+ version: 0.8.7.3
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - ~>
109
123
  - !ruby/object:Gem::Version
110
- version: 0.3.8
124
+ version: 0.8.7.3
111
125
  description: Ruby library for Appium.
112
126
  email:
113
127
  - code@bootstraponline.com
@@ -121,6 +135,7 @@ files:
121
135
  - Rakefile
122
136
  - appium_lib.gemspec
123
137
  - docs/android_docs.md
138
+ - docs/api_19_webview.md
124
139
  - docs/docs.md
125
140
  - docs/ios_docs.md
126
141
  - docs_gen/docs_from_js.md
@@ -132,6 +147,8 @@ files:
132
147
  - lib/appium_lib/android/element/textfield.rb
133
148
  - lib/appium_lib/android/helper.rb
134
149
  - lib/appium_lib/android/patch.rb
150
+ - lib/appium_lib/android/webview/javascript.rb
151
+ - lib/appium_lib/android/webview/webview.rb
135
152
  - lib/appium_lib/common/element/button.rb
136
153
  - lib/appium_lib/common/element/text.rb
137
154
  - lib/appium_lib/common/element/window.rb