diff --git a/.github/workflows/functional-test.yml b/.github/workflows/functional-test.yml index b77088fb..ada561b9 100644 --- a/.github/workflows/functional-test.yml +++ b/.github/workflows/functional-test.yml @@ -95,16 +95,12 @@ jobs: name: func_test_android1 - target: test/functional/android/keyboard_tests.py test/functional/android/location_tests.py name: func_test_android2 - - target: test/functional/android/appium_service_tests.py + - target: test/functional/android/appium_service_tests.py test/functional/android/chrome_tests.py name: func_test_android3 - - target: test/functional/android/finger_print_tests.py test/functional/android/screen_record_tests.py test/functional/android/settings_tests.py test/functional/android/chrome_tests.py + - target: test/functional/android/finger_print_tests.py test/functional/android/screen_record_tests.py test/functional/android/settings_tests.py name: func_test_android4 - - target: test/functional/android/remote_fs_tests.py + - target: test/functional/android/remote_fs_tests.py test/functional/android/log_event_tests.py name: func_test_android5 - - target: test/functional/android/common_tests.py test/functional/android/webelement_tests.py - name: func_test_android6 - - target: test/functional/android/network_connection_tests.py test/functional/android/log_event_tests.py test/functional/android/hw_actions_tests.py - name: func_test_android8 runs-on: ubuntu-latest @@ -234,7 +230,7 @@ jobs: echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules sudo udevadm control --reload-rules sudo udevadm trigger --name-match=kvm - + - name: Set up Python 3.12 uses: actions/setup-python@v3 with: @@ -247,7 +243,7 @@ jobs: - name: Install Appium run: npm install --location=global appium - + - name: Install Android drivers and Run Appium if: matrix.e2e-tests == 'flutter-android' run: | diff --git a/test/functional/android/common_tests.py b/test/functional/android/common_tests.py deleted file mode 100644 index 66aea810..00000000 --- a/test/functional/android/common_tests.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from time import sleep - -import pytest -from selenium.common.exceptions import NoSuchElementException - -from appium.webdriver.common.appiumby import AppiumBy -from test.functional.test_helper import wait_for_element - -from ..test_helper import is_ci -from .helper.test_helper import APIDEMO_PKG_NAME, BaseTestCase - - -class TestCommon(BaseTestCase): - def test_current_package(self) -> None: - assert APIDEMO_PKG_NAME == self.driver.current_package - - # TODO Due to unexpected dialog, "System UI isn't responding" - @pytest.mark.skipif(condition=is_ci(), reason='Need to fix flaky test during running on CI.') - def test_open_notifications(self) -> None: - for word in ['App', 'Notification', 'Status Bar', ':-|']: - wait_for_element(self.driver, AppiumBy.ANDROID_UIAUTOMATOR, f'new UiSelector().text("{word}")').click() - - self.driver.open_notifications() - sleep(1) - with pytest.raises(NoSuchElementException): - self.driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value='new UiSelector().text(":-|")') - - els = self.driver.find_element(by=AppiumBy.CLASS_NAME, value='android.widget.TextView') - # sometimes numbers shift - title = False - body = False - for el in els: - text = el.text - if text == 'Mood ring': - title = True - elif text == 'I am ok': - body = True - assert title - assert body - - self.driver.keyevent(4) - sleep(1) - self.driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value='new UiSelector().text(":-|")') diff --git a/test/functional/android/hw_actions_tests.py b/test/functional/android/hw_actions_tests.py deleted file mode 100644 index 4646d254..00000000 --- a/test/functional/android/hw_actions_tests.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from time import sleep - -from .helper.test_helper import BaseTestCase - - -class TestHwActions(BaseTestCase): - def test_lock(self) -> None: - self.driver.lock(-1) - sleep(10) - try: - assert self.driver.is_locked() - finally: - self.driver.unlock() - assert not self.driver.is_locked() diff --git a/test/functional/android/network_connection_tests.py b/test/functional/android/network_connection_tests.py deleted file mode 100644 index db1ce63b..00000000 --- a/test/functional/android/network_connection_tests.py +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import pytest - -from appium.webdriver.connectiontype import ConnectionType - -from ..test_helper import is_ci -from .helper.test_helper import BaseTestCase - - -class TestNetworkConnection(BaseTestCase): - def test_get_network_connection(self) -> None: - nc = self.driver.network_connection - assert isinstance(nc, int) - - @pytest.mark.skipif(condition=is_ci(), reason='Need to fix flaky test during running on CI') - def test_set_network_connection(self) -> None: - try: - self.driver.set_network_connection(ConnectionType.DATA_ONLY) - except Exception: - assert False, "Should not raise any exceptions" diff --git a/test/functional/android/webelement_tests.py b/test/functional/android/webelement_tests.py deleted file mode 100644 index 9a8ba1fd..00000000 --- a/test/functional/android/webelement_tests.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from appium.webdriver.common.appiumby import AppiumBy -from test.functional.test_helper import wait_for_element - -from .helper.test_helper import APIDEMO_PKG_NAME, BaseTestCase - - -class TestWebelement(BaseTestCase): - def test_element_location_in_view(self) -> None: - el = self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='Content') - loc = el.location_in_view - assert loc['x'] is not None - assert loc['y'] is not None - - def test_set_text(self) -> None: - self.driver.find_element( - by=AppiumBy.ANDROID_UIAUTOMATOR, - value='new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("Views").instance(0));', - ).click() - - wait_for_element(self.driver, AppiumBy.ACCESSIBILITY_ID, 'Controls').click() - wait_for_element(self.driver, AppiumBy.ACCESSIBILITY_ID, '1. Light Theme').click() - - el = wait_for_element(self.driver, AppiumBy.CLASS_NAME, 'android.widget.EditText') - el.send_keys('original text') - el.clear() - el.send_keys('new text') - - assert 'new text' == el.text - - def test_send_keys(self) -> None: - for text in ['App', 'Activity', 'Custom Title']: - wait_for_element(self.driver, AppiumBy.XPATH, f'//android.widget.TextView[@text=\'{text}\']').click() - - el = wait_for_element(self.driver, AppiumBy.ID, '{}:id/left_text_edit'.format(APIDEMO_PKG_NAME)) - el.send_keys(' text') - - assert 'Left is best text' == el.text diff --git a/test/unit/webdriver/device/common_test.py b/test/unit/webdriver/device/common_test.py index c4065e47..7bf99153 100644 --- a/test/unit/webdriver/device/common_test.py +++ b/test/unit/webdriver/device/common_test.py @@ -15,16 +15,18 @@ import httpretty from appium.webdriver.webdriver import WebDriver -from test.unit.helper.test_helper import android_w3c_driver, appium_command +from test.unit.helper.test_helper import android_w3c_driver, appium_command, get_httpretty_request_body class TestWebDriverCommon(object): @httpretty.activate def test_open_notifications(self): driver = android_w3c_driver() - httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/appium/device/open_notifications')) httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync')) assert isinstance(driver.open_notifications(), WebDriver) + assert {'args': [], 'script': 'mobile: openNotifications'} == get_httpretty_request_body( + httpretty.last_request() + ) @httpretty.activate def test_current_package(self): diff --git a/test/unit/webdriver/webelement_test.py b/test/unit/webdriver/webelement_test.py index 57cb317f..14b6abb6 100644 --- a/test/unit/webdriver/webelement_test.py +++ b/test/unit/webdriver/webelement_test.py @@ -62,6 +62,14 @@ def test_send_key_with_file(self): d = get_httpretty_request_body(httpretty.last_request()) assert d['text'] == ''.join(d['value']) + @httpretty.activate + def test_clear(self): + driver = android_w3c_driver() + httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/element/element_id/clear')) + + element = MobileWebElement(driver, 'element_id') + element.clear() + @httpretty.activate def test_get_attribute_with_dict(self): driver = android_w3c_driver() @@ -79,3 +87,20 @@ def test_get_attribute_with_dict(self): assert isinstance(ef, dict) assert ef == rect_dict + + @httpretty.activate + def test_element_location_in_view(self): + driver = android_w3c_driver() + location_in_view = {'y': 200, 'x': 100} + httpretty.register_uri( + httpretty.GET, + appium_command('/session/1234567890/element/element_id/location_in_view'), + body=json.dumps({"value": location_in_view}), + ) + + element = MobileWebElement(driver, 'element_id') + loc = element.location_in_view + + httpretty.last_request() + + assert loc == location_in_view