rwda 0.1.1

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.
Files changed (8) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +5 -0
  4. data/Gemfile +6 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +41 -0
  7. data/lib/rwda.rb +181 -0
  8. metadata +92 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8fa64e5e4f10359dc3b9117c41885b6ff174ccbc
4
+ data.tar.gz: 801e052f3a3b73c5aa6dbe34644336c2e10fafbf
5
+ SHA512:
6
+ metadata.gz: 67668b713794e7a89bebf6ac5a46554c9b6543a287f7889b291bafbf6e20e0fc8927db61cca50b78f89634b7c642cb8d4d40cbb301d16221c5bbfa6f66e7516c
7
+ data.tar.gz: bfa2aa96a0f18fcfede50bc253c88fdfdd0e89485fe621f33b65d87bd73ba3dbd9ce197f23ef4c6236045f5145dccb4d473adbf4e74b99a2c67d30cfb2011d28
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.2
5
+ before_install: gem install bundler -v 1.14.4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rwda.gemspec
4
+ gem 'httparty'
5
+ gem 'json'
6
+ gem 'test/unit'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 phoebusliang
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,41 @@
1
+ # Rwda
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rwda`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rwda'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rwda
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/phoebusliang/rwda. 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.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/lib/rwda.rb ADDED
@@ -0,0 +1,181 @@
1
+ require "rwda/version"
2
+ require "httparty"
3
+ require "json"
4
+ require "test/unit"
5
+
6
+ class Browser
7
+ include Test::Unit::Assertions
8
+
9
+ def initialize (enable_debugger = false)
10
+ @enable_debugger = enable_debugger
11
+ end
12
+
13
+ def wait_for_response(request_route, request_type, body, lamb, timeout=10)
14
+ start = Time.now
15
+ while Time.now - start < timeout
16
+ case request_type
17
+ when 'post'
18
+ val = HTTParty.post(request_route, :body => body.to_json)
19
+ when 'get'
20
+ val = HTTParty.get(request_route)
21
+ when 'delete'
22
+ val = HTTParty.delete(request_route, :body => body.to_json)
23
+ end
24
+ if lamb.call(val.to_json)
25
+ return val.to_json
26
+ end
27
+ sleep 1
28
+ end
29
+ end
30
+
31
+ def wait_for_network_connection_done(timeout=30)
32
+ request_route = @url+'/'+@session_id+'/elements'
33
+ body = {:using => 'xpath', :value => "XCUIElementTypeOther[@label='Network connection in progress']"}
34
+ sleep 1
35
+ start = Time.now
36
+ while Time.now - start < timeout
37
+ val = HTTParty.post(request_route, :body => body.to_json)
38
+ if JSON.parse(val.to_json)['value'].size == 0
39
+ return
40
+ end
41
+ sleep 1
42
+ end
43
+ sleep 1
44
+ end
45
+
46
+ def send_request(request_route, request_type, body)
47
+ case request_type
48
+ when 'post'
49
+ val = HTTParty.post(request_route, :body => body.to_json)
50
+ when 'get'
51
+ val = HTTParty.get(request_route)
52
+ when 'delete'
53
+ val = HTTParty.delete(request_route, :body => body.to_json)
54
+ end
55
+ p "The sending request is #{val}" if @enable_debugger
56
+ return val.to_json
57
+ end
58
+
59
+ def wait_element_enable(element)
60
+ request_route = @url+'/'+@session_id+'/element/'+element+'/enabled'
61
+ wait_for_response(request_route, 'get', '', lambda { |val| return val.to_json.include? 'true' })
62
+ end
63
+
64
+ def wait_element_display(element)
65
+ request_route = @url+'/'+@session_id+'/element/'+element+'/displayed'
66
+ wait_for_response(request_route, 'get', '', lambda { |val| return val.to_json.include? 'true' })
67
+ end
68
+
69
+ def open_app(device, bundle_id = 'com.rea-group.reapa.internal')
70
+ app_body = {:desiredCapabilities => {:bundleId => bundle_id}}
71
+ response = HTTParty.post(DEVICE_URL[device], :body => app_body.to_json)
72
+ @url = DEVICE_URL[device]
73
+ @session_id = response['sessionId']
74
+ end
75
+
76
+ def clean_keychain(device)
77
+ system(COMMAND_PATH + ' ' + DEVICE_INFO[device] +' clear_keychain ' + BUNDLE_ID)
78
+ end
79
+
80
+ def install_app(device)
81
+ system(COMMAND_PATH + ' ' + DEVICE_INFO[device] +' install ' + APP_PATH)
82
+ end
83
+
84
+ def uninstall_app(device)
85
+ system(COMMAND_PATH + ' ' + DEVICE_INFO[device] +' uninstall ' + BUNDLE_ID)
86
+ end
87
+
88
+ def find_elements_by_class(class_val, label='null', recall=false, exception='Element was not found!')
89
+ wait_for_network_connection_done
90
+ body = {:using => 'class name', :value => class_val}
91
+ request_route = @url+'/'+@session_id+'/elements'
92
+ if recall
93
+ response = wait_for_response(request_route, 'post', body, lambda { |val| return (val.include? class_val) && (val.include? label) })
94
+ else
95
+ response = send_request(request_route, 'post', body)
96
+ end
97
+
98
+ response = JSON.parse(response)
99
+ p "Finding elements by class. The response is #{response}" if @enable_debugger
100
+
101
+ if label == 'null'
102
+ response = response['value'].find_all { |item| item['label'] == nil }
103
+ else
104
+ response = response['value'].find_all { |item| item['label'] == label }
105
+ end
106
+
107
+ response
108
+ end
109
+
110
+ def find_elements_by_xpath(xpath, recall=false, exception='Element was not found!')
111
+ wait_for_network_connection_done
112
+ body = {:using => 'xpath', :value => xpath}
113
+ request_route = @url+'/'+@session_id+'/elements'
114
+ if recall
115
+ response = wait_for_response(request_route, 'post', body, lambda { |val| return (JSON.parse(val)['value'].length > 0) && !(val.include? 'Cannot evaluate results for XPath expression') })
116
+ else
117
+ response = send_request(request_route, 'post', body)
118
+ end
119
+ response = JSON.parse(response)
120
+ p "Finding elements by xpath. The response is #{response}" if @enable_debugger
121
+ response = response['value']
122
+ raise exception if response == nil
123
+ response
124
+ end
125
+
126
+ def tap_element(element_id)
127
+ request_route = @url+'/'+@session_id+'/element/'+element_id+'/click'
128
+ send_request(request_route, 'post', '')
129
+ end
130
+
131
+ def type_text(element_id, val)
132
+ request_route_clear = @url+'/'+@session_id+'/element/'+element_id+'/clear'
133
+ send_request(request_route_clear, 'post', '')
134
+ request_route_type = @url+'/'+@session_id+'/element/'+element_id+'/value'
135
+ body = {:value => val}
136
+ send_request(request_route_type, 'post', body)
137
+ end
138
+
139
+ def type_text_without_clear(element_id, val)
140
+ request_route_type = @url+'/'+@session_id+'/element/'+element_id+'/value'
141
+ body = {:value => val}
142
+ send_request(request_route_type, 'post', body)
143
+ end
144
+
145
+ def scroll_to_element(name, element_id)
146
+ request_route = @url+'/'+@session_id+'/wda/Element/'+element_id+'/scroll'
147
+ body = {:name => name}
148
+ send_request(request_route, 'post', body)
149
+ end
150
+
151
+ def take_screenshot(to_file: './screenshot.png')
152
+ request_route = @url+'/screenshot'
153
+ response = wait_for_response(request_route, 'get', '', lambda { |val| return val.to_s.include? @session_id })
154
+ File.write to_file, Base64.decode64(response['value'])
155
+ response['output'] = to_file
156
+ response
157
+ end
158
+
159
+ def swipe_element_with_direction(element_id, direction)
160
+ request_route = @url+'/'+@session_id+'/wda/element/'+element_id+'/swipe'
161
+ body = {:direction => direction}
162
+ send_request(request_route, 'post', body)
163
+ end
164
+
165
+ def get_element_value(element_id)
166
+ request_route = @url+'/'+@session_id+'/element/'+element_id+'/attribute/value'
167
+ wait_for_response(request_route, 'get', '', lambda { |val| return val.to_s.include? @session_id })
168
+ end
169
+
170
+ def get_element_rect(element_id)
171
+ request_route = @url+'/'+@session_id+'/element/'+element_id+'/attribute/rect'
172
+ wait_for_response(request_route, 'get', '', lambda { |val| return val.to_s.include? @session_id })
173
+ end
174
+
175
+ def background_app
176
+ url = @url.gsub('/session', '')
177
+ request_route = url+'/wda/homescreen'
178
+ wait_for_response(request_route, 'post', '', lambda { |val| return val.to_s.include? @session_id })
179
+ end
180
+
181
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rwda
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - phoebusliang
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: Ruby client for Facebook WebDriverAgent
56
+ email:
57
+ - phoebusliang@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .travis.yml
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - lib/rwda.rb
68
+ homepage: https://github.com/phoebusliang/rwda
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.6.1
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: wda
92
+ test_files: []