From bda07898a7a520abe6e8670dbe968906615e92a0 Mon Sep 17 00:00:00 2001 From: Atsushi Mori Date: Fri, 6 Dec 2019 23:50:13 +0900 Subject: [PATCH 01/14] Run all tests --- ci-jobs/functional_test.yml | 6 +++--- test/functional/android/applications_tests.py | 1 - test/functional/android/common_tests.py | 3 --- test/functional/android/context_switching_tests.py | 1 - test/functional/android/network_connection_tests.py | 2 -- .../search_context/find_by_accessibility_id_tests.py | 2 -- .../android/search_context/find_by_uiautomator_tests.py | 1 - 7 files changed, 3 insertions(+), 13 deletions(-) diff --git a/ci-jobs/functional_test.yml b/ci-jobs/functional_test.yml index f1455f64..2acdcca4 100644 --- a/ci-jobs/functional_test.yml +++ b/ci-jobs/functional_test.yml @@ -5,7 +5,7 @@ parameters: xcodeForIOS: 11.3 CI: true -# [Android] Need to fix and add flaky tests for activities_tests, find_by_uiautomator_tests +# [Android] Need to fix and add flaky tests for , jobs: - template: ./functional/run_ios_test.yml @@ -70,7 +70,7 @@ jobs: name: 'func_test_android6' vmImage: ${{ parameters.vmImage }} pytestOpt: ${{ parameters.pytestOpt }} - testFiles: 'common_tests.py' + testFiles: 'common_tests.py multi_action_tests.py webelement_tests.py' sdkVer: ${{ parameters.androidSdkVer }} CI: ${{ parameters.ci }} - template: ./functional/run_android_test.yml @@ -86,6 +86,6 @@ jobs: name: 'func_test_android8' vmImage: ${{ parameters.vmImage }} pytestOpt: ${{ parameters.pytestOpt }} - testFiles: 'network_connection_tests.py log_event_tests.py' + testFiles: 'network_connection_tests.py log_event_tests.py activities_tests.py hw_actions_tests.py touch_action_tests.py' sdkVer: ${{ parameters.androidSdkVer }} CI: ${{ parameters.ci }} diff --git a/test/functional/android/applications_tests.py b/test/functional/android/applications_tests.py index 45ea52ca..2cdb0c1d 100644 --- a/test/functional/android/applications_tests.py +++ b/test/functional/android/applications_tests.py @@ -33,7 +33,6 @@ def test_is_app_installed(self): self.assertTrue(self.driver.is_app_installed(APIDEMO_PKG_NAME)) def test_install_app(self): - self.skipTest('This causes the server to crash. no idea why') self.assertFalse(self.driver.is_app_installed('io.selendroid.testapp')) self.driver.install_app('/Users/isaac/code/python-client/test/apps/selendroid-test-app.apk') self.assertTrue(self.driver.is_app_installed('io.selendroid.testapp')) diff --git a/test/functional/android/common_tests.py b/test/functional/android/common_tests.py index cf5ea791..7c50150c 100644 --- a/test/functional/android/common_tests.py +++ b/test/functional/android/common_tests.py @@ -39,9 +39,6 @@ def test_end_test_coverage(self): sleep(5) def test_open_notifications(self): - if is_ci(): - # TODO Due to unexpected dialog, "System UI isn't responding" - self.skipTest('Need to fix flaky test during running on CI.') for word in ['App', 'Notification', 'Status Bar', ':-|']: wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("{}")'.format(word)).click() diff --git a/test/functional/android/context_switching_tests.py b/test/functional/android/context_switching_tests.py index ed4dcef9..f2829ab9 100644 --- a/test/functional/android/context_switching_tests.py +++ b/test/functional/android/context_switching_tests.py @@ -22,7 +22,6 @@ from .helper import desired_capabilities -@pytest.mark.skip(reason="Need to fix broken test") class ContextSwitchingTests(unittest.TestCase): def setUp(self): desired_caps = desired_capabilities.get_desired_capabilities('selendroid-test-app.apk') diff --git a/test/functional/android/network_connection_tests.py b/test/functional/android/network_connection_tests.py index 5727e1d6..74616891 100644 --- a/test/functional/android/network_connection_tests.py +++ b/test/functional/android/network_connection_tests.py @@ -27,8 +27,6 @@ def test_get_network_connection(self): self.assertIsInstance(nc, int) def test_set_network_connection(self): - if is_ci(): - self.skipTest('Need to fix flaky test during running on CI') nc = self.driver.set_network_connection(ConnectionType.DATA_ONLY) self.assertIsInstance(nc, int) self.assertEqual(nc, ConnectionType.DATA_ONLY) diff --git a/test/functional/android/search_context/find_by_accessibility_id_tests.py b/test/functional/android/search_context/find_by_accessibility_id_tests.py index 508edc21..c12ceb93 100644 --- a/test/functional/android/search_context/find_by_accessibility_id_tests.py +++ b/test/functional/android/search_context/find_by_accessibility_id_tests.py @@ -35,8 +35,6 @@ def test_find_multiple_elements(self): self.assertIsInstance(els, list) def test_element_find_single_element(self): - if is_ci(): - self.skipTest('Need to fix flaky test during running on CI') wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("Accessibility")').click() wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("Accessibility Node Querying")').click() diff --git a/test/functional/android/search_context/find_by_uiautomator_tests.py b/test/functional/android/search_context/find_by_uiautomator_tests.py index 47430356..b602a591 100644 --- a/test/functional/android/search_context/find_by_uiautomator_tests.py +++ b/test/functional/android/search_context/find_by_uiautomator_tests.py @@ -19,7 +19,6 @@ from test.functional.android.helper.test_helper import BaseTestCase -@pytest.mark.skip(reason="Need to fix flaky test") class FindByUIAutomatorTests(BaseTestCase): def test_find_single_element(self): el = self.driver.find_element_by_android_uiautomator('new UiSelector().text("Animation")') From d0357ad1ae2805c0d058064c2394e7edc6fe033e Mon Sep 17 00:00:00 2001 From: Atsushi Mori Date: Sun, 15 Dec 2019 14:25:12 +0900 Subject: [PATCH 02/14] Fix apk file path --- test/functional/android/applications_tests.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/functional/android/applications_tests.py b/test/functional/android/applications_tests.py index 2cdb0c1d..53d86c9a 100644 --- a/test/functional/android/applications_tests.py +++ b/test/functional/android/applications_tests.py @@ -13,11 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os import unittest from time import sleep from appium.webdriver.applicationstate import ApplicationState +from .helper.desired_capabilities import PATH from .helper.test_helper import APIDEMO_PKG_NAME, BaseTestCase @@ -34,7 +36,7 @@ def test_is_app_installed(self): def test_install_app(self): self.assertFalse(self.driver.is_app_installed('io.selendroid.testapp')) - self.driver.install_app('/Users/isaac/code/python-client/test/apps/selendroid-test-app.apk') + self.driver.install_app(os.path.join('../..', 'apps', 'selendroid-test-app.apk')) self.assertTrue(self.driver.is_app_installed('io.selendroid.testapp')) def test_remove_app(self): From 10e5088505e71bce4e0561033bf369174f39dff6 Mon Sep 17 00:00:00 2001 From: Atsushi Mori Date: Sun, 15 Dec 2019 15:44:40 +0900 Subject: [PATCH 03/14] Skip find_element_by_image test cases --- test/functional/android/applications_tests.py | 1 - .../android/search_context/find_by_image_tests.py | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/test/functional/android/applications_tests.py b/test/functional/android/applications_tests.py index 53d86c9a..288421f6 100644 --- a/test/functional/android/applications_tests.py +++ b/test/functional/android/applications_tests.py @@ -19,7 +19,6 @@ from appium.webdriver.applicationstate import ApplicationState -from .helper.desired_capabilities import PATH from .helper.test_helper import APIDEMO_PKG_NAME, BaseTestCase diff --git a/test/functional/android/search_context/find_by_image_tests.py b/test/functional/android/search_context/find_by_image_tests.py index 0ba6f8a9..5aa71f20 100644 --- a/test/functional/android/search_context/find_by_image_tests.py +++ b/test/functional/android/search_context/find_by_image_tests.py @@ -22,6 +22,7 @@ from appium import webdriver from appium.webdriver.common.mobileby import MobileBy from test.functional.android.helper import desired_capabilities +from test.functional.test_helper import is_ci from ..helper.test_helper import wait_for_element @@ -41,11 +42,15 @@ def tearDown(self): self.driver.quit() def test_find_based_on_image_template(self): + if is_ci(): + self.skipTest('Skip since opencv4nodejs fails to install on the macOS instance') image_path = desired_capabilities.PATH('file/find_by_image_success.png') with open(image_path, 'rb') as png_file: b64_data = base64.b64encode(png_file.read()).decode('UTF-8') - el = wait_for_element(self.driver, MobileBy.IMAGE, b64_data) + el = WebDriverWait(self.driver, 3).until( + EC.presence_of_element_located((MobileBy.IMAGE, b64_data)) + ) size = el.size self.assertIsNotNone(size['width']) self.assertIsNotNone(size['height']) @@ -62,13 +67,19 @@ def test_find_based_on_image_template(self): wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, "Alarm") def test_find_multiple_elements_by_image_just_returns_one(self): - wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, "App") + if is_ci(): + self.skipTest('Skip since opencv4nodejs fails to install on the macOS instance') + WebDriverWait(self.driver, 3).until( + EC.presence_of_element_located((MobileBy.ACCESSIBILITY_ID, "App")) + ) image_path = desired_capabilities.PATH('file/find_by_image_success.png') els = self.driver.find_elements_by_image(image_path) els[0].click() wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, "Alarm") def test_find_throws_no_such_element(self): + if is_ci(): + self.skipTest('Skip since opencv4nodejs fails to install on the macOS instance') image_path = desired_capabilities.PATH('file/find_by_image_failure.png') with open(image_path, 'rb') as png_file: b64_data = base64.b64encode(png_file.read()).decode('UTF-8') From 8d2ed8ddc998327ced7474c4992e0a2c5e57ce51 Mon Sep 17 00:00:00 2001 From: Atsushi Mori Date: Sun, 15 Dec 2019 17:23:02 +0900 Subject: [PATCH 04/14] Skip context switching test --- test/functional/android/context_switching_tests.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/functional/android/context_switching_tests.py b/test/functional/android/context_switching_tests.py index f2829ab9..2bc6d092 100644 --- a/test/functional/android/context_switching_tests.py +++ b/test/functional/android/context_switching_tests.py @@ -28,21 +28,25 @@ def setUp(self): self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) def test_contexts_list(self): + self.skipTest('Need to replace with apk which has WEBVIEW as context') self._enter_webview() contexts = self.driver.contexts self.assertEqual(2, len(contexts)) def test_move_to_correct_context(self): + self.skipTest('Need to replace with apk which has WEBVIEW as context') self._enter_webview() self.assertEqual('WEBVIEW_io.selendroid.testapp', self.driver.current_context) def test_actually_in_webview(self): + self.skipTest('Need to replace with apk which has WEBVIEW as context') self._enter_webview() self.driver.find_element_by_css_selector('input[type=submit]').click() el = self.driver.find_element_by_xpath("//h1[contains(., 'This is my way')]") self.assertIsNot(None, el) def test_move_back_to_native_context(self): + self.skipTest('Need to replace with apk which has WEBVIEW as context') self._enter_webview() self.driver.switch_to.context(None) self.assertEqual('NATIVE_APP', self.driver.current_context) @@ -54,7 +58,7 @@ def tearDown(self): self.driver.quit() def _enter_webview(self): - btn = self.driver.find_element_by_name('buttonStartWebviewCD') + btn = self.driver.find_element_by_accessibility_id('buttonStartWebviewCD') btn.click() self.driver.switch_to.context('WEBVIEW') From 93aaa6f5262c21db11979ca0dc6e43e75d6c5555 Mon Sep 17 00:00:00 2001 From: Atsushi Mori Date: Sun, 15 Dec 2019 19:26:44 +0900 Subject: [PATCH 05/14] Skip multi tap test on CI --- test/functional/android/applications_tests.py | 2 +- test/functional/android/multi_action_tests.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/functional/android/applications_tests.py b/test/functional/android/applications_tests.py index 288421f6..e00b73f5 100644 --- a/test/functional/android/applications_tests.py +++ b/test/functional/android/applications_tests.py @@ -35,7 +35,7 @@ def test_is_app_installed(self): def test_install_app(self): self.assertFalse(self.driver.is_app_installed('io.selendroid.testapp')) - self.driver.install_app(os.path.join('../..', 'apps', 'selendroid-test-app.apk')) + self.driver.install_app(os.path.join('..', 'apps', 'selendroid-test-app.apk')) self.assertTrue(self.driver.is_app_installed('io.selendroid.testapp')) def test_remove_app(self): diff --git a/test/functional/android/multi_action_tests.py b/test/functional/android/multi_action_tests.py index 3d0be2b0..aa7d3bbd 100644 --- a/test/functional/android/multi_action_tests.py +++ b/test/functional/android/multi_action_tests.py @@ -19,7 +19,7 @@ from appium.webdriver.common.multi_action import MultiAction from appium.webdriver.common.touch_action import TouchAction -from .helper.test_helper import BaseTestCase, wait_for_element +from .helper.test_helper import BaseTestCase, is_ci, wait_for_element class MultiActionTests(BaseTestCase): @@ -96,6 +96,8 @@ def test_actions_with_waits(self): ma.perform() def test_driver_multi_tap(self): + if is_ci(): + self.skipTest('Skip since the test must be watched to check if it works') el = self.driver.find_element_by_accessibility_id('Graphics') action = TouchAction(self.driver) action.tap(el).perform() From 16093571829787cafec22e7a56ee945fb464d3dc Mon Sep 17 00:00:00 2001 From: Atsushi Mori Date: Sun, 15 Dec 2019 20:14:41 +0900 Subject: [PATCH 06/14] Change strategy for waiting element --- test/functional/android/applications_tests.py | 3 ++- .../android/search_context/find_by_accessibility_id_tests.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/functional/android/applications_tests.py b/test/functional/android/applications_tests.py index e00b73f5..9703fbc7 100644 --- a/test/functional/android/applications_tests.py +++ b/test/functional/android/applications_tests.py @@ -19,6 +19,7 @@ from appium.webdriver.applicationstate import ApplicationState +from .helper.desired_capabilities import PATH from .helper.test_helper import APIDEMO_PKG_NAME, BaseTestCase @@ -35,7 +36,7 @@ def test_is_app_installed(self): def test_install_app(self): self.assertFalse(self.driver.is_app_installed('io.selendroid.testapp')) - self.driver.install_app(os.path.join('..', 'apps', 'selendroid-test-app.apk')) + self.driver.install_app(PATH(os.path.join('../..', 'apps', 'selendroid-test-app.apk'))) self.assertTrue(self.driver.is_app_installed('io.selendroid.testapp')) def test_remove_app(self): diff --git a/test/functional/android/search_context/find_by_accessibility_id_tests.py b/test/functional/android/search_context/find_by_accessibility_id_tests.py index c12ceb93..da63975c 100644 --- a/test/functional/android/search_context/find_by_accessibility_id_tests.py +++ b/test/functional/android/search_context/find_by_accessibility_id_tests.py @@ -38,7 +38,7 @@ def test_element_find_single_element(self): wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("Accessibility")').click() wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("Accessibility Node Querying")').click() - el = wait_for_element(self.driver, MobileBy.CLASS_NAME, 'android.widget.ListView') + el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Task Take out Trash') sub_el = el.find_element_by_accessibility_id('Task Take out Trash') self.assertIsNotNone(sub_el) From 01d7d308c32ac8e5ab28d89316a1f225c0741fb0 Mon Sep 17 00:00:00 2001 From: Atsushi Mori Date: Sun, 15 Dec 2019 22:49:22 +0900 Subject: [PATCH 07/14] Add functions for same steps --- ci-jobs/functional_test.yml | 2 - .../android/network_connection_tests.py | 1 - .../find_by_accessibility_id_tests.py | 1 - test/functional/android/touch_action_tests.py | 75 ++++++------------- 4 files changed, 24 insertions(+), 55 deletions(-) diff --git a/ci-jobs/functional_test.yml b/ci-jobs/functional_test.yml index 2acdcca4..200b7f20 100644 --- a/ci-jobs/functional_test.yml +++ b/ci-jobs/functional_test.yml @@ -5,8 +5,6 @@ parameters: xcodeForIOS: 11.3 CI: true -# [Android] Need to fix and add flaky tests for , - jobs: - template: ./functional/run_ios_test.yml parameters: diff --git a/test/functional/android/network_connection_tests.py b/test/functional/android/network_connection_tests.py index 74616891..34267345 100644 --- a/test/functional/android/network_connection_tests.py +++ b/test/functional/android/network_connection_tests.py @@ -17,7 +17,6 @@ from appium.webdriver.connectiontype import ConnectionType -from ..test_helper import is_ci from .helper.test_helper import BaseTestCase diff --git a/test/functional/android/search_context/find_by_accessibility_id_tests.py b/test/functional/android/search_context/find_by_accessibility_id_tests.py index da63975c..b5e8a878 100644 --- a/test/functional/android/search_context/find_by_accessibility_id_tests.py +++ b/test/functional/android/search_context/find_by_accessibility_id_tests.py @@ -19,7 +19,6 @@ BaseTestCase, wait_for_element ) -from test.functional.test_helper import is_ci class FindByAccessibilityIDTests(BaseTestCase): diff --git a/test/functional/android/touch_action_tests.py b/test/functional/android/touch_action_tests.py index 7bf7e30f..c95238f7 100644 --- a/test/functional/android/touch_action_tests.py +++ b/test/functional/android/touch_action_tests.py @@ -73,20 +73,8 @@ def test_press_and_immediately_release_x_y(self): self.assertIsNotNone(el) def test_press_and_wait(self): - el1 = self.driver.find_element_by_accessibility_id('Content') - el2 = self.driver.find_element_by_accessibility_id('Animation') - + self._move_to_custom_adapter() action = TouchAction(self.driver) - action.press(el1).move_to(el2).perform() - - el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Views') - action.tap(el).perform() - - el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Expandable Lists') - action.tap(el).perform() - - el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, '1. Custom Adapter') - action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("People Names")') @@ -118,20 +106,8 @@ def test_press_and_moveto_x_y(self): self.assertIsNotNone(el) def test_long_press(self): - el1 = self.driver.find_element_by_accessibility_id('Content') - el2 = self.driver.find_element_by_accessibility_id('Animation') - + self._move_to_custom_adapter() action = TouchAction(self.driver) - action.press(el1).move_to(el2).perform() - - el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Views') - action.tap(el).perform() - - el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Expandable Lists') - action.tap(el).perform() - - el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, '1. Custom Adapter') - action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("People Names")') @@ -143,20 +119,8 @@ def test_long_press(self): self.assertIsNotNone(el) def test_long_press_x_y(self): - el1 = self.driver.find_element_by_accessibility_id('Content') - el2 = self.driver.find_element_by_accessibility_id('Animation') - + self._move_to_custom_adapter() action = TouchAction(self.driver) - action.press(el1).move_to(el2).perform() - - el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Views') - action.tap(el).perform() - - el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Expandable Lists') - action.tap(el).perform() - - el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, '1. Custom Adapter') - action.tap(el).perform() # the element "People Names" is located at 430:310 (top left corner) # location can be changed by phone resolusion, OS version @@ -168,13 +132,8 @@ def test_long_press_x_y(self): self.assertIsNotNone(el) def test_drag_and_drop(self): - el1 = self.driver.find_element_by_accessibility_id('Content') - el2 = self.driver.find_element_by_accessibility_id('Animation') - self.driver.scroll(el1, el2) - - el = self.driver.find_element_by_accessibility_id('Views') + self._move_to_views() action = TouchAction(self.driver) - action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Drag and Drop') action.tap(el).perform() @@ -189,13 +148,8 @@ def test_drag_and_drop(self): self.assertTrue('drag_dot_3' in el.text) def test_driver_drag_and_drop(self): - el1 = self.driver.find_element_by_accessibility_id('Content') - el2 = self.driver.find_element_by_accessibility_id('Animation') - self.driver.scroll(el1, el2) - - el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Views') + self._move_to_views() action = TouchAction(self.driver) - action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Drag and Drop') action.tap(el).perform() @@ -219,6 +173,25 @@ def test_driver_swipe(self): el = self.driver.find_element_by_accessibility_id('ImageView') self.assertIsNotNone(el) + def _move_to_views(self): + el1 = self.driver.find_element_by_accessibility_id('Content') + el2 = self.driver.find_element_by_accessibility_id('Animation') + self.driver.scroll(el1, el2) + + el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Views') + action = TouchAction(self.driver) + action.tap(el).perform() + + def _move_to_custom_adapter(self): + self._move_to_views() + action = TouchAction(self.driver) + + el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Expandable Lists') + action.tap(el).perform() + + el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, '1. Custom Adapter') + action.tap(el).perform() + if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromTestCase(TouchActionTests) From e151c695cdbeed25671c51ed3bd235d1b9ffd386 Mon Sep 17 00:00:00 2001 From: Atsushi Mori Date: Sun, 9 Feb 2020 15:16:14 +0900 Subject: [PATCH 08/14] Restore unexpected changes --- .../android/search_context/find_by_image_tests.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/test/functional/android/search_context/find_by_image_tests.py b/test/functional/android/search_context/find_by_image_tests.py index 5aa71f20..62b6e7b4 100644 --- a/test/functional/android/search_context/find_by_image_tests.py +++ b/test/functional/android/search_context/find_by_image_tests.py @@ -42,15 +42,11 @@ def tearDown(self): self.driver.quit() def test_find_based_on_image_template(self): - if is_ci(): - self.skipTest('Skip since opencv4nodejs fails to install on the macOS instance') image_path = desired_capabilities.PATH('file/find_by_image_success.png') with open(image_path, 'rb') as png_file: b64_data = base64.b64encode(png_file.read()).decode('UTF-8') - el = WebDriverWait(self.driver, 3).until( - EC.presence_of_element_located((MobileBy.IMAGE, b64_data)) - ) + el = wait_for_element(self.driver, MobileBy.IMAGE, b64_data) size = el.size self.assertIsNotNone(size['width']) self.assertIsNotNone(size['height']) @@ -67,19 +63,13 @@ def test_find_based_on_image_template(self): wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, "Alarm") def test_find_multiple_elements_by_image_just_returns_one(self): - if is_ci(): - self.skipTest('Skip since opencv4nodejs fails to install on the macOS instance') - WebDriverWait(self.driver, 3).until( - EC.presence_of_element_located((MobileBy.ACCESSIBILITY_ID, "App")) - ) + wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, "App") image_path = desired_capabilities.PATH('file/find_by_image_success.png') els = self.driver.find_elements_by_image(image_path) els[0].click() wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, "Alarm") def test_find_throws_no_such_element(self): - if is_ci(): - self.skipTest('Skip since opencv4nodejs fails to install on the macOS instance') image_path = desired_capabilities.PATH('file/find_by_image_failure.png') with open(image_path, 'rb') as png_file: b64_data = base64.b64encode(png_file.read()).decode('UTF-8') From f0f44f04f8e216348045c722dd3f6e894e6aeb99 Mon Sep 17 00:00:00 2001 From: Atsushi Mori Date: Sun, 9 Feb 2020 16:18:31 +0900 Subject: [PATCH 09/14] Fix touch_action_tests --- .../android/search_context/find_by_image_tests.py | 1 - test/functional/android/touch_action_tests.py | 11 +++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/test/functional/android/search_context/find_by_image_tests.py b/test/functional/android/search_context/find_by_image_tests.py index 62b6e7b4..0ba6f8a9 100644 --- a/test/functional/android/search_context/find_by_image_tests.py +++ b/test/functional/android/search_context/find_by_image_tests.py @@ -22,7 +22,6 @@ from appium import webdriver from appium.webdriver.common.mobileby import MobileBy from test.functional.android.helper import desired_capabilities -from test.functional.test_helper import is_ci from ..helper.test_helper import wait_for_element diff --git a/test/functional/android/touch_action_tests.py b/test/functional/android/touch_action_tests.py index c95238f7..6358ddc2 100644 --- a/test/functional/android/touch_action_tests.py +++ b/test/functional/android/touch_action_tests.py @@ -22,6 +22,7 @@ from .helper.test_helper import ( APIDEMO_PKG_NAME, BaseTestCase, + is_ci, wait_for_element ) @@ -119,6 +120,8 @@ def test_long_press(self): self.assertIsNotNone(el) def test_long_press_x_y(self): + if is_ci(): + self.skipTest("Skip since this check is low robust due to hard-coded position.") self._move_to_custom_adapter() action = TouchAction(self.driver) @@ -144,8 +147,8 @@ def test_drag_and_drop(self): # dnd is stimulated by longpress-move_to-release action.long_press(dd3).move_to(dd2).release().perform() - el = wait_for_element(self.driver, MobileBy.ID, '{}:id/drag_text'.format(APIDEMO_PKG_NAME)) - self.assertTrue('drag_dot_3' in el.text) + el = wait_for_element(self.driver, MobileBy.ID, '{}:id/drag_result_text'.format(APIDEMO_PKG_NAME)) + self.assertTrue('Dropped!' in el.text) def test_driver_drag_and_drop(self): self._move_to_views() @@ -159,8 +162,8 @@ def test_driver_drag_and_drop(self): self.driver.drag_and_drop(dd3, dd2) - el = wait_for_element(self.driver, MobileBy.ID, '{}:id/drag_text'.format(APIDEMO_PKG_NAME)) - self.assertTrue('drag_dot_3' in el.text) + el = wait_for_element(self.driver, MobileBy.ID, '{}:id/drag_result_text'.format(APIDEMO_PKG_NAME)) + self.assertTrue('Dropped!' in el.text) def test_driver_swipe(self): el = self.driver.find_element_by_accessibility_id('Views') From ecc038bdf01385a1dba01b2844b0d26656c9d801 Mon Sep 17 00:00:00 2001 From: Atsushi Mori Date: Sun, 9 Feb 2020 16:41:59 +0900 Subject: [PATCH 10/14] Fix --- test/functional/android/multi_action_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/android/multi_action_tests.py b/test/functional/android/multi_action_tests.py index aa7d3bbd..33b80074 100644 --- a/test/functional/android/multi_action_tests.py +++ b/test/functional/android/multi_action_tests.py @@ -73,7 +73,7 @@ def test_actions_with_waits(self): el = self.driver.find_element_by_accessibility_id('Splitting Touches across Views') action.tap(el).perform() - wait_for_element(self.driver, MobileBy.CLASS_NAME, 'android.widget.ListView') + wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Acorn') els = self.driver.find_elements_by_class_name('android.widget.ListView') a1 = TouchAction() a1.press(els[0]) \ From 6097fa2b3e94da168316552b192122e145121395 Mon Sep 17 00:00:00 2001 From: Atsushi Mori Date: Sun, 9 Feb 2020 16:44:46 +0900 Subject: [PATCH 11/14] Fix Fix test_driver_swipe --- test/functional/android/touch_action_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/android/touch_action_tests.py b/test/functional/android/touch_action_tests.py index 6358ddc2..e2223ff2 100644 --- a/test/functional/android/touch_action_tests.py +++ b/test/functional/android/touch_action_tests.py @@ -173,7 +173,7 @@ def test_driver_swipe(self): self.assertRaises(NoSuchElementException, self.driver.find_element_by_accessibility_id, 'ImageView') self.driver.swipe(100, 1000, 100, 100, 800) - el = self.driver.find_element_by_accessibility_id('ImageView') + el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'ImageView') self.assertIsNotNone(el) def _move_to_views(self): From 9bb82f7e69cef00d75cdf5db1470c1f602928dbb Mon Sep 17 00:00:00 2001 From: Atsushi Mori Date: Sun, 9 Feb 2020 20:01:20 +0900 Subject: [PATCH 12/14] fix --- test/functional/android/multi_action_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/android/multi_action_tests.py b/test/functional/android/multi_action_tests.py index 33b80074..ae387b8f 100644 --- a/test/functional/android/multi_action_tests.py +++ b/test/functional/android/multi_action_tests.py @@ -73,7 +73,7 @@ def test_actions_with_waits(self): el = self.driver.find_element_by_accessibility_id('Splitting Touches across Views') action.tap(el).perform() - wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Acorn') + wait_for_element(self.driver, MobileBy.ID, 'io.appium.android.apis:id/list1') els = self.driver.find_elements_by_class_name('android.widget.ListView') a1 = TouchAction() a1.press(els[0]) \ From 3f5107322065e347adf13eaea7edce62c6164115 Mon Sep 17 00:00:00 2001 From: Atsushi Mori Date: Sun, 9 Feb 2020 20:59:04 +0900 Subject: [PATCH 13/14] Create _move_to_[target_view] --- test/functional/android/multi_action_tests.py | 56 ++++++++----------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/test/functional/android/multi_action_tests.py b/test/functional/android/multi_action_tests.py index ae387b8f..7ed47708 100644 --- a/test/functional/android/multi_action_tests.py +++ b/test/functional/android/multi_action_tests.py @@ -24,24 +24,8 @@ class MultiActionTests(BaseTestCase): def test_parallel_actions(self): - el1 = self.driver.find_element_by_accessibility_id('Content') - el2 = self.driver.find_element_by_accessibility_id('Animation') - self.driver.scroll(el1, el2) - - el = self.driver.find_element_by_accessibility_id('Views') - action = TouchAction(self.driver) - action.tap(el).perform() - - # simulate a swipe/scroll - el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Expandable Lists') - action.press(el).move_to(x=100, y=-1000).release().perform() - el = self.driver.find_element_by_accessibility_id('Layouts') - action.press(el).move_to(x=100, y=-1000).release().perform() + self._move_to_splitting_touches_accros_views() - el = self.driver.find_element_by_accessibility_id('Splitting Touches across Views') - action.tap(el).perform() - - wait_for_element(self.driver, MobileBy.CLASS_NAME, 'android.widget.ListView') els = self.driver.find_elements_by_class_name('android.widget.ListView') a1 = TouchAction() a1.press(els[0]) \ @@ -56,24 +40,8 @@ def test_parallel_actions(self): ma.perform() def test_actions_with_waits(self): - el1 = self.driver.find_element_by_accessibility_id('Content') - el2 = self.driver.find_element_by_accessibility_id('Animation') - self.driver.scroll(el1, el2) - - el = self.driver.find_element_by_accessibility_id('Views') - action = TouchAction(self.driver) - action.tap(el).perform() - - # simulate a swipe/scroll - el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Expandable Lists') - action.press(el).move_to(x=100, y=-1000).release().perform() - el = self.driver.find_element_by_accessibility_id('Layouts') - action.press(el).move_to(x=100, y=-1000).release().perform() + self._move_to_splitting_touches_accros_views() - el = self.driver.find_element_by_accessibility_id('Splitting Touches across Views') - action.tap(el).perform() - - wait_for_element(self.driver, MobileBy.ID, 'io.appium.android.apis:id/list1') els = self.driver.find_elements_by_class_name('android.widget.ListView') a1 = TouchAction() a1.press(els[0]) \ @@ -95,6 +63,26 @@ def test_actions_with_waits(self): ma.add(a1, a2) ma.perform() + def _move_to_splitting_touches_accros_views(self): + el1 = self.driver.find_element_by_accessibility_id('Content') + el2 = self.driver.find_element_by_accessibility_id('Animation') + self.driver.scroll(el1, el2) + + el = self.driver.find_element_by_accessibility_id('Views') + action = TouchAction(self.driver) + action.tap(el).perform() + + # simulate a swipe/scroll + el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Expandable Lists') + action.press(el).move_to(x=100, y=-1000).release().perform() + el = self.driver.find_element_by_accessibility_id('Layouts') + action.press(el).move_to(x=100, y=-1000).release().perform() + + el = self.driver.find_element_by_accessibility_id('Splitting Touches across Views') + action.tap(el).perform() + + wait_for_element(self.driver, MobileBy.ID, 'io.appium.android.apis:id/list1') + def test_driver_multi_tap(self): if is_ci(): self.skipTest('Skip since the test must be watched to check if it works') From 8fad9e949b9cd33464b637645cc04d51a5b1396f Mon Sep 17 00:00:00 2001 From: Atsushi Mori Date: Sun, 9 Feb 2020 23:14:45 +0900 Subject: [PATCH 14/14] [test_driver_swipe] Add wait --- test/functional/android/touch_action_tests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/functional/android/touch_action_tests.py b/test/functional/android/touch_action_tests.py index e2223ff2..5fb5dca5 100644 --- a/test/functional/android/touch_action_tests.py +++ b/test/functional/android/touch_action_tests.py @@ -170,6 +170,7 @@ def test_driver_swipe(self): action = TouchAction(self.driver) action.tap(el).perform() + wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Animation') self.assertRaises(NoSuchElementException, self.driver.find_element_by_accessibility_id, 'ImageView') self.driver.swipe(100, 1000, 100, 100, 800)