Skip to content

Commit 706df5b

Browse files
committed
Merge branch 'master' of github.com:appium/ruby_lib_core
2 parents 01a0efb + 625f7a0 commit 706df5b

File tree

8 files changed

+146
-21
lines changed

8 files changed

+146
-21
lines changed

ci-jobs/functional_test.yml

+42
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ jobs:
149149
ANDROID_SDK_VERSION: ${{ parameters.androidSDK }}
150150
IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
151151
APPIUM_VERSION: ${{ parameters.appiumVersion }}
152+
strategy:
153+
matrix:
154+
uiautomator2:
155+
AUTOMATION_NAME_DROID: 'uiautomator2'
156+
espresso:
157+
AUTOMATION_NAME_DROID: 'espresso'
152158
steps:
153159
- template: ./functional/android_setup.yml
154160
- template: ./functional/run_appium.yml
@@ -166,6 +172,12 @@ jobs:
166172
ANDROID_SDK_VERSION: ${{ parameters.androidSDK }}
167173
IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
168174
APPIUM_VERSION: ${{ parameters.appiumVersion }}
175+
strategy:
176+
matrix:
177+
uiautomator2:
178+
AUTOMATION_NAME_DROID: 'uiautomator2'
179+
espresso:
180+
AUTOMATION_NAME_DROID: 'espresso'
169181
steps:
170182
- template: ./functional/android_setup.yml
171183
- template: ./functional/run_appium.yml
@@ -183,6 +195,12 @@ jobs:
183195
ANDROID_SDK_VERSION: ${{ parameters.androidSDK }}
184196
IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
185197
APPIUM_VERSION: ${{ parameters.appiumVersion }}
198+
strategy:
199+
matrix:
200+
uiautomator2:
201+
AUTOMATION_NAME_DROID: 'uiautomator2'
202+
espresso:
203+
AUTOMATION_NAME_DROID: 'espresso'
186204
steps:
187205
- template: ./functional/android_setup.yml
188206
- template: ./functional/run_appium.yml
@@ -200,6 +218,12 @@ jobs:
200218
ANDROID_SDK_VERSION: ${{ parameters.androidSDK }}
201219
IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
202220
APPIUM_VERSION: ${{ parameters.appiumVersion }}
221+
strategy:
222+
matrix:
223+
uiautomator2:
224+
AUTOMATION_NAME_DROID: 'uiautomator2'
225+
espresso:
226+
AUTOMATION_NAME_DROID: 'espresso'
203227
steps:
204228
- template: ./functional/android_setup.yml
205229
- template: ./functional/run_appium.yml
@@ -219,6 +243,12 @@ jobs:
219243
ANDROID_SDK_VERSION: ${{ parameters.androidSDK }}
220244
IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
221245
APPIUM_VERSION: ${{ parameters.appiumVersion }}
246+
strategy:
247+
matrix:
248+
uiautomator2:
249+
AUTOMATION_NAME_DROID: 'uiautomator2'
250+
espresso:
251+
AUTOMATION_NAME_DROID: 'espresso'
222252
steps:
223253
- template: ./functional/android_setup.yml
224254
- template: ./functional/run_appium.yml
@@ -236,6 +266,12 @@ jobs:
236266
ANDROID_SDK_VERSION: ${{ parameters.androidSDK }}
237267
IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
238268
APPIUM_VERSION: ${{ parameters.appiumVersion }}
269+
strategy:
270+
matrix:
271+
uiautomator2:
272+
AUTOMATION_NAME_DROID: 'uiautomator2'
273+
espresso:
274+
AUTOMATION_NAME_DROID: 'espresso'
239275
steps:
240276
- template: ./functional/android_setup.yml
241277
- template: ./functional/run_appium.yml
@@ -254,6 +290,12 @@ jobs:
254290
AUTOMATION_NAME_DROID: espresso
255291
IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
256292
APPIUM_VERSION: ${{ parameters.appiumVersion }}
293+
strategy:
294+
matrix:
295+
uiautomator2:
296+
AUTOMATION_NAME_DROID: 'uiautomator2'
297+
espresso:
298+
AUTOMATION_NAME_DROID: 'espresso'
257299
steps:
258300
- template: ./functional/android_setup.yml
259301
- template: ./functional/run_appium.yml

lib/appium_lib_core/common/device/value.rb

+23-4
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,32 @@ class Base
1818
module Device
1919
module Value
2020
def set_immediate_value(element, *value)
21-
keys = ::Selenium::WebDriver::Keys.encode(value)
22-
execute :set_immediate_value, { id: element.ref }, value: Array(keys)
21+
execute :set_immediate_value, { id: element.ref }, generate_value_and_text(value)
2322
end
2423

2524
def replace_value(element, *value)
26-
keys = ::Selenium::WebDriver::Keys.encode(value)
27-
execute :replace_value, { id: element.ref }, value: Array(keys)
25+
execute :replace_value, { id: element.ref }, generate_value_and_text(value)
26+
end
27+
28+
private
29+
30+
def generate_value_and_text(*value)
31+
keys = ::Selenium::WebDriver::Keys.encode(*value)
32+
33+
if @file_detector
34+
local_files = keys.first.split("\n").map { |key| @file_detector.call(Array(key)) }.compact
35+
if local_files.any?
36+
keys = local_files.map { |local_file| upload(local_file) }
37+
keys = Array(keys.join("\n"))
38+
end
39+
end
40+
41+
# Keep .split(//) for backward compatibility for now
42+
text = keys.join('')
43+
44+
# FIXME: further work for W3C. Over appium 1.15.0 or later
45+
# { value: text.split(//), text: text }
46+
{ value: text.split(//) }
2847
end
2948
end # module Value
3049
end # module Device

test/functional/android/android/device_test.rb

+18-6
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,24 @@ def test_shake
4949
end
5050

5151
def test_close_and_launch_app
52-
@driver.close_app
53-
assert @driver.available_contexts.include?('NATIVE_APP')
52+
if @@core.automation_name == :espresso
53+
assert_raises ::Selenium::WebDriver::Error::UnsupportedOperationError do
54+
@driver.close_app
55+
end
56+
else
57+
@driver.close_app
58+
assert(@@core.wait { @driver.app_state('io.appium.android.apis') != :running_in_foreground })
59+
end
5460

55-
@driver.launch_app
56-
e = @@core.wait { @driver.find_element :accessibility_id, 'App' }
57-
assert_equal 'App', e.text
61+
if @@core.automation_name == :espresso
62+
assert_raises ::Selenium::WebDriver::Error::UnsupportedOperationError do
63+
@driver.launch_app
64+
end
65+
else
66+
@driver.launch_app
67+
e = @@core.wait { @driver.find_element :accessibility_id, 'App' }
68+
assert_equal 'App', e.text
69+
end
5870
end
5971

6072
def test_lock_unlock
@@ -265,7 +277,7 @@ def test_long_press_keycode
265277
end
266278

267279
def test_open_notifications
268-
skip unless @@core.automation_name == :espresso
280+
skip if @@core.automation_name == :espresso
269281

270282
# test & comments from https://github.com/appium/appium/blob/master/test/functional/android/apidemos/notifications-specs.js#L19
271283
# get to the notification page

test/functional/android/android/image_comparison_test.rb

+7
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ def test_image_comparison_get_images_result
8585
def test_image_element
8686
skip 'Requires `npm install -g appium opencv4nodejs`' unless `npm list -g opencv4nodejs`.include? 'opencv4nodejs'
8787
skip_as_appium_version '1.9.0'
88+
if @@core.automation_name == :espresso
89+
skip 'Espresso does not support find_element since it does not support settings API'
90+
end
8891

8992
@driver.rotation = :portrait
9093

@@ -124,6 +127,9 @@ def test_image_element
124127
def test_image_elements
125128
skip 'Requires `npm install -g appium opencv4nodejs`' unless `npm list -g opencv4nodejs`.include? 'opencv4nodejs'
126129
skip_as_appium_version '1.9.0'
130+
if @@core.automation_name == :espresso
131+
skip 'Espresso does not support find_element since it does not support settings API'
132+
end
127133

128134
@driver.rotation = :landscape
129135

@@ -165,6 +171,7 @@ def test_image_elements
165171
def test_template_scale_ratio
166172
skip 'Requires `npm install -g appium opencv4nodejs`' unless `npm list -g opencv4nodejs`.include? 'opencv4nodejs'
167173
skip_as_appium_version '1.9.0'
174+
skip 'Espresso does not support settings API' if @@core.automation_name == :espresso
168175

169176
@driver.rotation = :portrait
170177

test/functional/android/webdriver/device_test.rb

+8-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
require 'base64'
1516
require 'test_helper'
1617

1718
# $ rake test:func:android TEST=test/functional/android/webdriver/device_test.rb
@@ -38,18 +39,20 @@ def test_remote_status
3839
assert !status['build']['version'].nil?
3940
end
4041

41-
# TODO: replace_value
42-
43-
def test_set_immediate_value
42+
def test_set_immediate_value_and_replace_value
4443
@@core.wait { @driver.find_element :accessibility_id, 'App' }.click
4544
@@core.wait { @driver.find_element :accessibility_id, 'Activity' }.click
4645
@@core.wait { @driver.find_element :accessibility_id, 'Custom Title' }.click
4746

4847
e = @@core.wait { @driver.find_element :id, 'io.appium.android.apis:id/left_text_edit' }
49-
@driver.set_immediate_value e, 'hello'
48+
e.immediate_value 'hello'
5049

5150
text = @@core.wait { @driver.find_element :id, 'io.appium.android.apis:id/left_text_edit' }
52-
assert_equal 'Left is besthello', text.name
51+
assert_equal 'Left is besthello', text.text
52+
53+
text.replace_value %w(テスト hello)
54+
replaced_text = @@core.wait { @driver.find_element :id, 'io.appium.android.apis:id/left_text_edit' }
55+
assert_equal '44OG44K544OIaGVsbG/ugIA=', Base64.strict_encode64(replaced_text.text)
5356
end
5457

5558
def test_page_source

test/unit/android/device/mjsonwp/keyboard_test.rb

+23-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def test_long_press_keycode_with_flags_with_wrong_metastate
137137
## Immediate value
138138
def test_set_immediate_value
139139
stub_request(:post, "#{SESSION}/appium/element/id/value")
140-
.with(body: { value: ["abc\ue000"] }.to_json)
140+
.with(body: { value: %w(a b c ) }.to_json)
141141
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)
142142

143143
@driver.set_immediate_value ::Selenium::WebDriver::Element.new(@driver.send(:bridge), 'id'), %w(a b c)
@@ -147,13 +147,34 @@ def test_set_immediate_value
147147

148148
def test_replace_value
149149
stub_request(:post, "#{SESSION}/appium/element/id/replace_value")
150-
.with(body: { value: ["abc\ue000"] }.to_json)
150+
.with(body: { value: %w(a b c ) }.to_json)
151151
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)
152152

153153
@driver.replace_value ::Selenium::WebDriver::Element.new(@driver.send(:bridge), 'id'), %w(a b c)
154154

155155
assert_requested(:post, "#{SESSION}/appium/element/id/replace_value", times: 1)
156156
end
157+
158+
## Immediate value
159+
def test_set_immediate_value_text
160+
stub_request(:post, "#{SESSION}/appium/element/id/value")
161+
.with(body: { value: %w(a b c ) }.to_json)
162+
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)
163+
164+
@driver.set_immediate_value ::Selenium::WebDriver::Element.new(@driver.send(:bridge), 'id'), 'abcテスト'
165+
166+
assert_requested(:post, "#{SESSION}/appium/element/id/value", times: 1)
167+
end
168+
169+
def test_replace_value_text
170+
stub_request(:post, "#{SESSION}/appium/element/id/replace_value")
171+
.with(body: { value: %w(a b c ) }.to_json)
172+
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)
173+
174+
@driver.replace_value ::Selenium::WebDriver::Element.new(@driver.send(:bridge), 'id'), 'abcテスト'
175+
176+
assert_requested(:post, "#{SESSION}/appium/element/id/replace_value", times: 1)
177+
end
157178
end # class Commands
158179
end # module MJSONWP
159180
end # module Device

test/unit/android/device/w3c/keyboard_test.rb

+23-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def test_long_press_keycode_with_flags_with_wrong_metastate
136136
## Immediate value
137137
def test_set_immediate_value
138138
stub_request(:post, "#{SESSION}/appium/element/id/value")
139-
.with(body: { value: ["abc\ue000"] }.to_json)
139+
.with(body: { value: %w(a b c ) }.to_json)
140140
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)
141141

142142
@driver.set_immediate_value ::Selenium::WebDriver::Element.new(@driver.send(:bridge), 'id'), %w(a b c)
@@ -146,13 +146,34 @@ def test_set_immediate_value
146146

147147
def test_replace_value
148148
stub_request(:post, "#{SESSION}/appium/element/id/replace_value")
149-
.with(body: { value: ["abc\ue000"] }.to_json)
149+
.with(body: { value: %w(a b c ) }.to_json)
150150
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)
151151

152152
@driver.replace_value ::Selenium::WebDriver::Element.new(@driver.send(:bridge), 'id'), %w(a b c)
153153

154154
assert_requested(:post, "#{SESSION}/appium/element/id/replace_value", times: 1)
155155
end
156+
157+
## Immediate value
158+
def test_set_immediate_value_text
159+
stub_request(:post, "#{SESSION}/appium/element/id/value")
160+
.with(body: { value: %w(a b c ) }.to_json)
161+
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)
162+
163+
@driver.set_immediate_value ::Selenium::WebDriver::Element.new(@driver.send(:bridge), 'id'), 'abcテスト'
164+
165+
assert_requested(:post, "#{SESSION}/appium/element/id/value", times: 1)
166+
end
167+
168+
def test_replace_value_text
169+
stub_request(:post, "#{SESSION}/appium/element/id/replace_value")
170+
.with(body: { value: %w(a b c ) }.to_json)
171+
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)
172+
173+
@driver.replace_value ::Selenium::WebDriver::Element.new(@driver.send(:bridge), 'id'), 'abcテスト'
174+
175+
assert_requested(:post, "#{SESSION}/appium/element/id/replace_value", times: 1)
176+
end
156177
end # class CommandsTest
157178
end # module W3C
158179
end # module Device

test/unit/common/element_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_location_rel
5656

5757
def test_immediate_value
5858
stub_request(:post, "#{SESSION}/appium/element/id/value")
59-
.with(body: { value: ['hello'] }.to_json)
59+
.with(body: { value: %w(h e l l o) }.to_json)
6060
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)
6161

6262
e = ::Selenium::WebDriver::Element.new(@driver.send(:bridge), 'id')
@@ -67,7 +67,7 @@ def test_immediate_value
6767

6868
def test_replace
6969
stub_request(:post, "#{SESSION}/appium/element/id/replace_value")
70-
.with(body: { value: ['hello'] }.to_json)
70+
.with(body: { value: %w(h e l l o) }.to_json)
7171
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)
7272

7373
e = ::Selenium::WebDriver::Element.new(@driver.send(:bridge), 'id')

0 commit comments

Comments
 (0)