Skip to content

Commit

Permalink
ci: Add tests for espresso driver (#235)
Browse files Browse the repository at this point in the history
* Add espresso

* fix tests for espresso in test code layer

* skip some tests for espresso

* update set immediate value and replace text

* update set_immediate_value and replace_value

* expect raising an error for launch/close app

* Does not send text as backward compatibility

* fix unit tests
  • Loading branch information
KazuCocoa authored Aug 16, 2019
1 parent f739d27 commit 625f7a0
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 21 deletions.
42 changes: 42 additions & 0 deletions ci-jobs/functional_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ jobs:
ANDROID_SDK_VERSION: ${{ parameters.androidSDK }}
IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
APPIUM_VERSION: ${{ parameters.appiumVersion }}
strategy:
matrix:
uiautomator2:
AUTOMATION_NAME_DROID: 'uiautomator2'
espresso:
AUTOMATION_NAME_DROID: 'espresso'
steps:
- template: ./functional/android_setup.yml
- template: ./functional/run_appium.yml
Expand All @@ -166,6 +172,12 @@ jobs:
ANDROID_SDK_VERSION: ${{ parameters.androidSDK }}
IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
APPIUM_VERSION: ${{ parameters.appiumVersion }}
strategy:
matrix:
uiautomator2:
AUTOMATION_NAME_DROID: 'uiautomator2'
espresso:
AUTOMATION_NAME_DROID: 'espresso'
steps:
- template: ./functional/android_setup.yml
- template: ./functional/run_appium.yml
Expand All @@ -183,6 +195,12 @@ jobs:
ANDROID_SDK_VERSION: ${{ parameters.androidSDK }}
IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
APPIUM_VERSION: ${{ parameters.appiumVersion }}
strategy:
matrix:
uiautomator2:
AUTOMATION_NAME_DROID: 'uiautomator2'
espresso:
AUTOMATION_NAME_DROID: 'espresso'
steps:
- template: ./functional/android_setup.yml
- template: ./functional/run_appium.yml
Expand All @@ -200,6 +218,12 @@ jobs:
ANDROID_SDK_VERSION: ${{ parameters.androidSDK }}
IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
APPIUM_VERSION: ${{ parameters.appiumVersion }}
strategy:
matrix:
uiautomator2:
AUTOMATION_NAME_DROID: 'uiautomator2'
espresso:
AUTOMATION_NAME_DROID: 'espresso'
steps:
- template: ./functional/android_setup.yml
- template: ./functional/run_appium.yml
Expand All @@ -219,6 +243,12 @@ jobs:
ANDROID_SDK_VERSION: ${{ parameters.androidSDK }}
IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
APPIUM_VERSION: ${{ parameters.appiumVersion }}
strategy:
matrix:
uiautomator2:
AUTOMATION_NAME_DROID: 'uiautomator2'
espresso:
AUTOMATION_NAME_DROID: 'espresso'
steps:
- template: ./functional/android_setup.yml
- template: ./functional/run_appium.yml
Expand All @@ -236,6 +266,12 @@ jobs:
ANDROID_SDK_VERSION: ${{ parameters.androidSDK }}
IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
APPIUM_VERSION: ${{ parameters.appiumVersion }}
strategy:
matrix:
uiautomator2:
AUTOMATION_NAME_DROID: 'uiautomator2'
espresso:
AUTOMATION_NAME_DROID: 'espresso'
steps:
- template: ./functional/android_setup.yml
- template: ./functional/run_appium.yml
Expand All @@ -254,6 +290,12 @@ jobs:
AUTOMATION_NAME_DROID: espresso
IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
APPIUM_VERSION: ${{ parameters.appiumVersion }}
strategy:
matrix:
uiautomator2:
AUTOMATION_NAME_DROID: 'uiautomator2'
espresso:
AUTOMATION_NAME_DROID: 'espresso'
steps:
- template: ./functional/android_setup.yml
- template: ./functional/run_appium.yml
Expand Down
27 changes: 23 additions & 4 deletions lib/appium_lib_core/common/device/value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,32 @@ class Base
module Device
module Value
def set_immediate_value(element, *value)
keys = ::Selenium::WebDriver::Keys.encode(value)
execute :set_immediate_value, { id: element.ref }, value: Array(keys)
execute :set_immediate_value, { id: element.ref }, generate_value_and_text(value)
end

def replace_value(element, *value)
keys = ::Selenium::WebDriver::Keys.encode(value)
execute :replace_value, { id: element.ref }, value: Array(keys)
execute :replace_value, { id: element.ref }, generate_value_and_text(value)
end

private

def generate_value_and_text(*value)
keys = ::Selenium::WebDriver::Keys.encode(*value)

if @file_detector
local_files = keys.first.split("\n").map { |key| @file_detector.call(Array(key)) }.compact
if local_files.any?
keys = local_files.map { |local_file| upload(local_file) }
keys = Array(keys.join("\n"))
end
end

# Keep .split(//) for backward compatibility for now
text = keys.join('')

# FIXME: further work for W3C. Over appium 1.15.0 or later
# { value: text.split(//), text: text }
{ value: text.split(//) }
end
end # module Value
end # module Device
Expand Down
24 changes: 18 additions & 6 deletions test/functional/android/android/device_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,24 @@ def test_shake
end

def test_close_and_launch_app
@driver.close_app
assert @driver.available_contexts.include?('NATIVE_APP')
if @@core.automation_name == :espresso
assert_raises ::Selenium::WebDriver::Error::UnsupportedOperationError do
@driver.close_app
end
else
@driver.close_app
assert(@@core.wait { @driver.app_state('io.appium.android.apis') != :running_in_foreground })
end

@driver.launch_app
e = @@core.wait { @driver.find_element :accessibility_id, 'App' }
assert_equal 'App', e.text
if @@core.automation_name == :espresso
assert_raises ::Selenium::WebDriver::Error::UnsupportedOperationError do
@driver.launch_app
end
else
@driver.launch_app
e = @@core.wait { @driver.find_element :accessibility_id, 'App' }
assert_equal 'App', e.text
end
end

def test_lock_unlock
Expand Down Expand Up @@ -265,7 +277,7 @@ def test_long_press_keycode
end

def test_open_notifications
skip unless @@core.automation_name == :espresso
skip if @@core.automation_name == :espresso

# test & comments from https://github.com/appium/appium/blob/master/test/functional/android/apidemos/notifications-specs.js#L19
# get to the notification page
Expand Down
7 changes: 7 additions & 0 deletions test/functional/android/android/image_comparison_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def test_image_comparison_get_images_result
def test_image_element
skip 'Requires `npm install -g appium opencv4nodejs`' unless `npm list -g opencv4nodejs`.include? 'opencv4nodejs'
skip_as_appium_version '1.9.0'
if @@core.automation_name == :espresso
skip 'Espresso does not support find_element since it does not support settings API'
end

@driver.rotation = :portrait

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

@driver.rotation = :landscape

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

@driver.rotation = :portrait

Expand Down
13 changes: 8 additions & 5 deletions test/functional/android/webdriver/device_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require 'base64'
require 'test_helper'

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

# TODO: replace_value

def test_set_immediate_value
def test_set_immediate_value_and_replace_value
@@core.wait { @driver.find_element :accessibility_id, 'App' }.click
@@core.wait { @driver.find_element :accessibility_id, 'Activity' }.click
@@core.wait { @driver.find_element :accessibility_id, 'Custom Title' }.click

e = @@core.wait { @driver.find_element :id, 'io.appium.android.apis:id/left_text_edit' }
@driver.set_immediate_value e, 'hello'
e.immediate_value 'hello'

text = @@core.wait { @driver.find_element :id, 'io.appium.android.apis:id/left_text_edit' }
assert_equal 'Left is besthello', text.name
assert_equal 'Left is besthello', text.text

text.replace_value %w(テスト hello)
replaced_text = @@core.wait { @driver.find_element :id, 'io.appium.android.apis:id/left_text_edit' }
assert_equal '44OG44K544OIaGVsbG/ugIA=', Base64.strict_encode64(replaced_text.text)
end

def test_page_source
Expand Down
25 changes: 23 additions & 2 deletions test/unit/android/device/mjsonwp/keyboard_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_long_press_keycode_with_flags_with_wrong_metastate
## Immediate value
def test_set_immediate_value
stub_request(:post, "#{SESSION}/appium/element/id/value")
.with(body: { value: ["abc\ue000"] }.to_json)
.with(body: { value: %w(a b c ) }.to_json)
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)

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

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

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

assert_requested(:post, "#{SESSION}/appium/element/id/replace_value", times: 1)
end

## Immediate value
def test_set_immediate_value_text
stub_request(:post, "#{SESSION}/appium/element/id/value")
.with(body: { value: %w(a b c ) }.to_json)
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)

@driver.set_immediate_value ::Selenium::WebDriver::Element.new(@driver.send(:bridge), 'id'), 'abcテスト'

assert_requested(:post, "#{SESSION}/appium/element/id/value", times: 1)
end

def test_replace_value_text
stub_request(:post, "#{SESSION}/appium/element/id/replace_value")
.with(body: { value: %w(a b c ) }.to_json)
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)

@driver.replace_value ::Selenium::WebDriver::Element.new(@driver.send(:bridge), 'id'), 'abcテスト'

assert_requested(:post, "#{SESSION}/appium/element/id/replace_value", times: 1)
end
end # class Commands
end # module MJSONWP
end # module Device
Expand Down
25 changes: 23 additions & 2 deletions test/unit/android/device/w3c/keyboard_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_long_press_keycode_with_flags_with_wrong_metastate
## Immediate value
def test_set_immediate_value
stub_request(:post, "#{SESSION}/appium/element/id/value")
.with(body: { value: ["abc\ue000"] }.to_json)
.with(body: { value: %w(a b c ) }.to_json)
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)

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

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

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

assert_requested(:post, "#{SESSION}/appium/element/id/replace_value", times: 1)
end

## Immediate value
def test_set_immediate_value_text
stub_request(:post, "#{SESSION}/appium/element/id/value")
.with(body: { value: %w(a b c ) }.to_json)
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)

@driver.set_immediate_value ::Selenium::WebDriver::Element.new(@driver.send(:bridge), 'id'), 'abcテスト'

assert_requested(:post, "#{SESSION}/appium/element/id/value", times: 1)
end

def test_replace_value_text
stub_request(:post, "#{SESSION}/appium/element/id/replace_value")
.with(body: { value: %w(a b c ) }.to_json)
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)

@driver.replace_value ::Selenium::WebDriver::Element.new(@driver.send(:bridge), 'id'), 'abcテスト'

assert_requested(:post, "#{SESSION}/appium/element/id/replace_value", times: 1)
end
end # class CommandsTest
end # module W3C
end # module Device
Expand Down
4 changes: 2 additions & 2 deletions test/unit/common/element_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_location_rel

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

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

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

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

0 comments on commit 625f7a0

Please sign in to comment.