From 47d505e23a94d48e5d683f7c906b716eeccd391b Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Wed, 27 Oct 2021 00:00:30 -0700 Subject: [PATCH 1/2] update TouchAction to W3C spec --- .../specs/common/device_touchaction.rb | 39 ++++++++++++++----- ios_tests/appium.txt | 2 +- ios_tests/lib/ios/specs/device/device.rb | 23 ++--------- .../lib/ios/specs/device/touch_actions.rb | 15 ++++--- ios_tests/lib/ios/specs/driver.rb | 2 +- 5 files changed, 45 insertions(+), 36 deletions(-) diff --git a/android_tests/lib/android/specs/common/device_touchaction.rb b/android_tests/lib/android/specs/common/device_touchaction.rb index 7d53c4f0..e49cbb47 100644 --- a/android_tests/lib/android/specs/common/device_touchaction.rb +++ b/android_tests/lib/android/specs/common/device_touchaction.rb @@ -25,9 +25,7 @@ def before_first t 'action_chain_press_release' do wait do e = text('Accessibility') - touch_action = Appium::TouchAction.new.press(element: e, x: 0.5, y: 0.5).release(element: e) - touch_action.perform - touch_action.actions.must_equal [] + action.click(e).perform end wait { text('Custom View') } back @@ -37,9 +35,7 @@ def before_first t 'action_chain_tap' do wait do e = text('Accessibility') - touch_action = Appium::TouchAction.new.tap(element: e) - touch_action.perform - touch_action.actions.must_equal [] + action.click(e).perform end wait { text('Custom View') } back @@ -49,7 +45,12 @@ def before_first t 'swipe' do wait { text('Animation').click } wait { text_exact('Bouncing Balls').click } - wait { Appium::TouchAction.new.swipe(start_x: 0.75, start_y: 0.25, end_x: 0.0, end_y: 49.75).perform } + + driver.action + .move_to_location(0.75, 0.25).pointer_down(:left) + .move_to_location(0.75, 50) + .release.perform + 2.times { back } wait { text_exact 'NFC' } end @@ -58,8 +59,28 @@ def before_first wait { text_exact 'NFC' } wait { text_exact('Graphics').click } wait { scroll_to('Touch Paint').click } - wait { zoom 200 } - wait { pinch 75 } + + # multiple action chains + f1 = driver.action.add_pointer_input(:touch, 'finger1') + f1.create_pointer_move(duration: 1, x: 200, y: 500, + origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT) + f1.create_pointer_down(:left) + f1.create_pause(0.5) + f1.create_pointer_move(duration: 1, x: 200, y: 200, + origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT) + f1.create_pointer_up(:left) + + f2 = driver.action.add_pointer_input(:touch, 'finger2') + f2.create_pointer_move(duration: 1, x: 200, y: 500, + origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT) + f2.create_pointer_down(:left) + f2.create_pause(0.5) + f2.create_pointer_move(duration: 1, x: 200, y: 800, + origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT) + f2.create_pointer_up(:left) + + driver.perform_actions [f1, f2] + wait { text('Graphics/Touch Paint') } 2.times { back } wait { text_exact 'NFC' } diff --git a/ios_tests/appium.txt b/ios_tests/appium.txt index fa6f710f..0cdf8593 100644 --- a/ios_tests/appium.txt +++ b/ios_tests/appium.txt @@ -1,6 +1,6 @@ [caps] platformName = "ios" -platformVersion = "14.5" +platformVersion = "15.0" deviceName ="iPhone 11" automationName = 'XCUITest' app = "../test_apps/UICatalog.app.zip" diff --git a/ios_tests/lib/ios/specs/device/device.rb b/ios_tests/lib/ios/specs/device/device.rb index 8733c465..e4457063 100644 --- a/ios_tests/lib/ios/specs/device/device.rb +++ b/ios_tests/lib/ios/specs/device/device.rb @@ -54,7 +54,7 @@ def go_back element = text('Buttons') one_finger_tap x: 0, y: 0, element: element else - Appium::TouchAction.new.press(element: text('Buttons')).perform + action.click(text('Buttons')).perform end wait { button 'UICatalog' } # successfully transitioned to buttons page @@ -62,24 +62,7 @@ def go_back end t 'swipe' do - touch_action = Appium::TouchAction.new.swipe(start_x: 75, start_y: 500, - end_x: 75, end_y: 20, duration: 500).perform - touch_action.actions.must_equal [] - - touch_action = Appium::TouchAction.new.swipe(start_x: 75, start_y: 500, end_x: 75, end_y: 20, duration: 500) - - touch_action.actions[0][:action].must_equal :press - touch_action.actions[0][:options].must_equal(x: 75, y: 500) - - touch_action.actions[1][:action].must_equal :wait, - touch_action.actions[1][:options].must_equal(ms: 500) - - touch_action.actions[2][:action].must_equal :moveTo - touch_action.actions[2][:options].must_equal(x: 75, y: 20) - - touch_action.actions[3][:action].must_equal :release - - touch_action.perform - touch_action.actions.must_equal [] + action.move_to_location(75, 500).pointer_down(:left). + move_to_location(75, 20).release.perform end end diff --git a/ios_tests/lib/ios/specs/device/touch_actions.rb b/ios_tests/lib/ios/specs/device/touch_actions.rb index 12a55a8e..1cae4a37 100644 --- a/ios_tests/lib/ios/specs/device/touch_actions.rb +++ b/ios_tests/lib/ios/specs/device/touch_actions.rb @@ -27,15 +27,20 @@ def after_last ele_index(ui_ios.picker_wheel, 1).text.must_equal '65' picker = ele_index(ui_ios.picker_wheel, 1) picker_rect = picker.rect - start_x = picker_rect.x + picker_rect.width / 2 - start_y = picker_rect.y + picker_rect.height / 2 + start_x = picker_rect.x + picker_rect.width / 2 + 50 + start_y = picker_rect.y + picker_rect.height / 2 + 60 args = { x: start_x, y: start_y } - args[:element] = element.id if element + args[:element] = picker.id if picker execute_script 'mobile: tap', args - Appium::TouchAction.new.swipe(start_x: start_x, start_y: start_y, end_x: 0, end_y: - 50).perform - ele_index(ui_ios.static_text, 1).text.must_equal '70' + puts window_rect + + action.move_to_location(start_x, start_y).pointer_down(:left).move_to_location(start_x, start_y - 10).pointer_up(:left).perform + + + ele_index(ui_ios.picker_wheel, 1).text.must_equal '70' + end t 'after_last' do diff --git a/ios_tests/lib/ios/specs/driver.rb b/ios_tests/lib/ios/specs/driver.rb index 1ae201f2..97641466 100644 --- a/ios_tests/lib/ios/specs/driver.rb +++ b/ios_tests/lib/ios/specs/driver.rb @@ -60,7 +60,7 @@ def before_first # actual[:caps].to_json send to Appium server caps_with_json = JSON.parse(actual[:caps].to_json) caps_with_json['platformName'].must_equal 'ios' - caps_with_json['platformVersion'].must_equal '14.5' + caps_with_json['platformVersion'].must_equal '15.0' caps_with_json['app'].must_equal expected_app caps_with_json['automationName'].must_equal 'XCUITest' caps_with_json['deviceName'].must_equal 'iPhone 11' From 0721cd49838f397653d92f3f5adb412d53ad9826 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Wed, 27 Oct 2021 00:36:11 -0700 Subject: [PATCH 2/2] fix rubocop --- .../specs/common/device_touchaction.rb | 24 +++++++++---------- ios_tests/lib/ios/specs/device/device.rb | 4 ++-- .../lib/ios/specs/device/touch_actions.rb | 5 ++-- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/android_tests/lib/android/specs/common/device_touchaction.rb b/android_tests/lib/android/specs/common/device_touchaction.rb index e49cbb47..51492785 100644 --- a/android_tests/lib/android/specs/common/device_touchaction.rb +++ b/android_tests/lib/android/specs/common/device_touchaction.rb @@ -47,9 +47,9 @@ def before_first wait { text_exact('Bouncing Balls').click } driver.action - .move_to_location(0.75, 0.25).pointer_down(:left) - .move_to_location(0.75, 50) - .release.perform + .move_to_location(0.75, 0.25).pointer_down(:left) + .move_to_location(0.75, 50) + .release.perform 2.times { back } wait { text_exact 'NFC' } @@ -62,21 +62,21 @@ def before_first # multiple action chains f1 = driver.action.add_pointer_input(:touch, 'finger1') - f1.create_pointer_move(duration: 1, x: 200, y: 500, - origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT) + f1.create_pointer_move(duration: 0.5, x: 500, y: 800, + origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT) f1.create_pointer_down(:left) f1.create_pause(0.5) - f1.create_pointer_move(duration: 1, x: 200, y: 200, - origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT) + f1.create_pointer_move(duration: 3, x: 500, y: 700, + origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT) f1.create_pointer_up(:left) f2 = driver.action.add_pointer_input(:touch, 'finger2') - f2.create_pointer_move(duration: 1, x: 200, y: 500, - origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT) + f2.create_pointer_move(duration: 0.5, x: 500, y: 800, + origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT) f2.create_pointer_down(:left) - f2.create_pause(0.5) - f2.create_pointer_move(duration: 1, x: 200, y: 800, - origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT) + f1.create_pause(0.5) + f2.create_pointer_move(duration: 3, x: 500, y: 900, + origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT) f2.create_pointer_up(:left) driver.perform_actions [f1, f2] diff --git a/ios_tests/lib/ios/specs/device/device.rb b/ios_tests/lib/ios/specs/device/device.rb index e4457063..dc2ec2e3 100644 --- a/ios_tests/lib/ios/specs/device/device.rb +++ b/ios_tests/lib/ios/specs/device/device.rb @@ -62,7 +62,7 @@ def go_back end t 'swipe' do - action.move_to_location(75, 500).pointer_down(:left). - move_to_location(75, 20).release.perform + action.move_to_location(75, 500).pointer_down(:left) + .move_to_location(75, 20).release.perform end end diff --git a/ios_tests/lib/ios/specs/device/touch_actions.rb b/ios_tests/lib/ios/specs/device/touch_actions.rb index 1cae4a37..2ee6c407 100644 --- a/ios_tests/lib/ios/specs/device/touch_actions.rb +++ b/ios_tests/lib/ios/specs/device/touch_actions.rb @@ -36,11 +36,10 @@ def after_last puts window_rect - action.move_to_location(start_x, start_y).pointer_down(:left).move_to_location(start_x, start_y - 10).pointer_up(:left).perform - + action.move_to_location(start_x, start_y).pointer_down(:left) + .move_to_location(start_x, start_y - 10).pointer_up(:left).perform ele_index(ui_ios.picker_wheel, 1).text.must_equal '70' - end t 'after_last' do