diff --git a/Pipfile b/Pipfile index d9795ba9..78bdce7b 100644 --- a/Pipfile +++ b/Pipfile @@ -4,18 +4,18 @@ url = "https://pypi.org/simple" verify_ssl = true [dev-packages] -pre-commit = "~=1.13" +pre-commit = "~=1.21" [packages] selenium = "~=3.141" -autopep8 = "~=1.4" +autopep8 = "~=1.5" -pytest = "~=4.0" -pytest-cov = "~=2.6" +pytest = "~=5.3" +pytest-cov = "~=2.8" -tox = "~=3.6" -tox-travis = "~=0.11" +tox = "~=3.14" +tox-travis = "~=0.12" httpretty = "~=0.9" python-dateutil = "~=2.8" diff --git a/appium/webdriver/errorhandler.py b/appium/webdriver/errorhandler.py index 38426992..11359e4d 100644 --- a/appium/webdriver/errorhandler.py +++ b/appium/webdriver/errorhandler.py @@ -23,7 +23,7 @@ class MobileErrorHandler(errorhandler.ErrorHandler): def check_response(self, response: Dict) -> None: try: - super(MobileErrorHandler, self).check_response(response) + super().check_response(response) except WebDriverException as wde: if wde.msg == 'No such context found.': raise NoSuchContextException(wde.msg, wde.screen, wde.stacktrace) diff --git a/appium/webdriver/webdriver.py b/appium/webdriver/webdriver.py index 3a0512bc..f35f6479 100644 --- a/appium/webdriver/webdriver.py +++ b/appium/webdriver/webdriver.py @@ -148,7 +148,7 @@ class WebDriver( def __init__(self, command_executor: str = 'http://127.0.0.1:4444/wd/hub', desired_capabilities: Optional[Dict] = None, browser_profile: str = None, proxy: str = None, keep_alive: bool = True, direct_connection: bool = False): - super(WebDriver, self).__init__( + super().__init__( AppiumConnection(command_executor, keep_alive=keep_alive), desired_capabilities, browser_profile, diff --git a/test/functional/android/activities_tests.py b/test/functional/android/activities_tests.py index d13f2d52..7f9978be 100644 --- a/test/functional/android/activities_tests.py +++ b/test/functional/android/activities_tests.py @@ -13,15 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest - from .helper.test_helper import APIDEMO_PKG_NAME, BaseTestCase -class ActivitiesTests(BaseTestCase): +class TestActivities(BaseTestCase): def test_current_activity(self) -> None: activity = self.driver.current_activity - self.assertEqual('.ApiDemos', activity) + assert '.ApiDemos' == activity def test_start_activity_this_app(self) -> None: self.driver.start_activity(APIDEMO_PKG_NAME, ".ApiDemos") @@ -39,9 +37,4 @@ def test_start_activity_other_app(self) -> None: def _assert_activity_contains(self, activity: str) -> None: current = self.driver.current_activity - self.assertTrue(activity in current) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(ActivitiesTests) - unittest.TextTestRunner(verbosity=2).run(suite) + assert activity in current diff --git a/test/functional/android/applications_tests.py b/test/functional/android/applications_tests.py index b8b98ffb..118af363 100644 --- a/test/functional/android/applications_tests.py +++ b/test/functional/android/applications_tests.py @@ -13,15 +13,16 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest from time import sleep +import pytest + from appium.webdriver.applicationstate import ApplicationState from .helper.test_helper import APIDEMO_PKG_NAME, BaseTestCase -class ApplicationsTests(BaseTestCase): +class TestApplications(BaseTestCase): def test_background_app(self) -> None: self.driver.background_app(1) @@ -29,54 +30,46 @@ def test_background_app(self) -> None: self.driver.launch_app() def test_is_app_installed(self) -> None: - self.assertFalse(self.driver.is_app_installed('sdfsdf')) - self.assertTrue(self.driver.is_app_installed(APIDEMO_PKG_NAME)) + assert not self.driver.is_app_installed('sdfsdf') + assert self.driver.is_app_installed(APIDEMO_PKG_NAME) + @pytest.mark.skip('This causes the server to crash. no idea why') def test_install_app(self) -> None: - self.skipTest('This causes the server to crash. no idea why') - self.assertFalse(self.driver.is_app_installed('io.selendroid.testapp')) + assert not 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')) + assert self.driver.is_app_installed('io.selendroid.testapp') def test_remove_app(self) -> None: - self.assertTrue(self.driver.is_app_installed(APIDEMO_PKG_NAME)) + assert self.driver.is_app_installed(APIDEMO_PKG_NAME) self.driver.remove_app(APIDEMO_PKG_NAME) - self.assertFalse(self.driver.is_app_installed(APIDEMO_PKG_NAME)) + assert not self.driver.is_app_installed(APIDEMO_PKG_NAME) def test_close_and_launch_app(self) -> None: self.driver.close_app() self.driver.launch_app() activity = self.driver.current_activity - self.assertEqual('.ApiDemos', activity) + assert '.ApiDemos' == activity def test_app_management(self) -> None: app_id = self.driver.current_package - self.assertEqual(self.driver.query_app_state(app_id), - ApplicationState.RUNNING_IN_FOREGROUND) + assert self.driver.query_app_state(app_id) == ApplicationState.RUNNING_IN_FOREGROUND self.driver.background_app(-1) - self.assertTrue(self.driver.query_app_state(app_id) < - ApplicationState.RUNNING_IN_FOREGROUND) + assert self.driver.query_app_state(app_id) < ApplicationState.RUNNING_IN_FOREGROUND self.driver.activate_app(app_id) - self.assertEqual(self.driver.query_app_state(app_id), - ApplicationState.RUNNING_IN_FOREGROUND) + assert self.driver.query_app_state(app_id) == ApplicationState.RUNNING_IN_FOREGROUND def test_app_strings(self) -> None: strings = self.driver.app_strings() - self.assertEqual(u'You can\'t wipe my data, you are a monkey!', strings[u'monkey_wipe_data']) + assert u'You can\'t wipe my data, you are a monkey!' == strings[u'monkey_wipe_data'] def test_app_strings_with_language(self) -> None: strings = self.driver.app_strings('en') - self.assertEqual(u'You can\'t wipe my data, you are a monkey!', strings[u'monkey_wipe_data']) + assert u'You can\'t wipe my data, you are a monkey!' == strings[u'monkey_wipe_data'] def test_app_strings_with_language_and_file(self) -> None: strings = self.driver.app_strings('en', 'some_file') - self.assertEqual(u'You can\'t wipe my data, you are a monkey!', strings[u'monkey_wipe_data']) + assert u'You can\'t wipe my data, you are a monkey!' == strings[u'monkey_wipe_data'] def test_reset(self) -> None: self.driver.reset() - self.assertTrue(self.driver.is_app_installed(APIDEMO_PKG_NAME)) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(ApplicationsTests) - unittest.TextTestRunner(verbosity=2).run(suite) + assert self.driver.is_app_installed(APIDEMO_PKG_NAME) diff --git a/test/functional/android/chrome_tests.py b/test/functional/android/chrome_tests.py index 971e4ebf..08767349 100644 --- a/test/functional/android/chrome_tests.py +++ b/test/functional/android/chrome_tests.py @@ -12,29 +12,22 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest - from appium import webdriver from .helper.desired_capabilities import get_desired_capabilities -class ChromeTests(unittest.TestCase): - def setUp(self) -> None: +class TestChrome(object): + def setup_method(self) -> None: caps = get_desired_capabilities() caps['browserName'] = 'Chrome' self.driver = webdriver.Remote('http://localhost:4723/wd/hub', caps) - def tearDown(self) -> None: + def teardown_method(self) -> None: self.driver.quit() def test_find_single_element(self) -> None: self.driver.get('http://10.0.2.2:4723/test/guinea-pig') self.driver.find_element_by_link_text('i am a link').click() - self.assertTrue('I am some other page content' in self.driver.page_source) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(ChromeTests) - unittest.TextTestRunner(verbosity=2).run(suite) + assert 'I am some other page content' in self.driver.page_source diff --git a/test/functional/android/common_tests.py b/test/functional/android/common_tests.py index 4da8f793..7768c376 100644 --- a/test/functional/android/common_tests.py +++ b/test/functional/android/common_tests.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest from time import sleep +import pytest from selenium.common.exceptions import NoSuchElementException from appium.webdriver.common.mobileby import MobileBy @@ -28,28 +28,27 @@ ) -class CommonTests(BaseTestCase): +class TestCommon(BaseTestCase): def test_current_package(self) -> None: - self.assertEqual(APIDEMO_PKG_NAME, self.driver.current_package) + assert APIDEMO_PKG_NAME == self.driver.current_package + @pytest.mark.skip('Not sure how to set this up to run') def test_end_test_coverage(self) -> None: - self.skipTest('Not sure how to set this up to run') self.driver.end_test_coverage(intent='android.intent.action.MAIN', path='') sleep(5) + # 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: - 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, f'new UiSelector().text("{word}")').click() self.driver.open_notifications() sleep(1) - self.assertRaises(NoSuchElementException, - self.driver.find_element_by_android_uiautomator, 'new UiSelector().text(":-|")') + with pytest.raises(NoSuchElementException): + self.driver.find_element_by_android_uiautomator, 'new UiSelector().text(":-|")' els = self.driver.find_elements_by_class_name('android.widget.TextView') # sometimes numbers shift @@ -61,14 +60,9 @@ def test_open_notifications(self) -> None: title = True elif text == 'I am ok': body = True - self.assertTrue(title) - self.assertTrue(body) + assert title + assert body self.driver.keyevent(4) sleep(1) self.driver.find_element_by_android_uiautomator('new UiSelector().text(":-|")') - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(CommonTests) - unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/functional/android/context_switching_tests.py b/test/functional/android/context_switching_tests.py index 2b42e55d..c358866a 100644 --- a/test/functional/android/context_switching_tests.py +++ b/test/functional/android/context_switching_tests.py @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest - import pytest from appium import webdriver @@ -23,43 +21,39 @@ @pytest.mark.skip(reason="Need to fix broken test") -class ContextSwitchingTests(unittest.TestCase): - def setUp(self) -> None: +class TestContextSwitching(object): + def setup_method(self) -> None: desired_caps = desired_capabilities.get_desired_capabilities('selendroid-test-app.apk') self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) - def tearDown(self) -> None: + def teardown_method(self) -> None: self.driver.quit() def test_contexts_list(self) -> None: self._enter_webview() contexts = self.driver.contexts - self.assertEqual(2, len(contexts)) + assert 2 == len(contexts) def test_move_to_correct_context(self) -> None: self._enter_webview() - self.assertEqual('WEBVIEW_io.selendroid.testapp', self.driver.current_context) + assert 'WEBVIEW_io.selendroid.testapp' == self.driver.current_context def test_actually_in_webview(self) -> None: 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) + assert el is not None def test_move_back_to_native_context(self) -> None: self._enter_webview() self.driver.switch_to.context(None) - self.assertEqual('NATIVE_APP', self.driver.current_context) + assert 'NATIVE_APP' == self.driver.current_context def test_set_invalid_context(self) -> None: - self.assertRaises(NoSuchContextException, self.driver.switch_to.context, 'invalid name') + with pytest.raises(NoSuchContextException): + self.driver.switch_to.context('invalid name') def _enter_webview(self) -> None: btn = self.driver.find_element_by_name('buttonStartWebviewCD') btn.click() self.driver.switch_to.context('WEBVIEW') - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(ContextSwitchingTests) - unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/functional/android/device_time_tests.py b/test/functional/android/device_time_tests.py index 736bf7c6..b5d576fb 100644 --- a/test/functional/android/device_time_tests.py +++ b/test/functional/android/device_time_tests.py @@ -13,20 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest - from dateutil.parser import parse from .helper.test_helper import BaseTestCase -class DeviceTimeTests(BaseTestCase): +class TestDeviceTime(BaseTestCase): def test_device_time(self) -> None: date_time = self.driver.device_time # convert to date ought to work parse(date_time) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(DeviceTimeTests) - unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/functional/android/finger_print_tests.py b/test/functional/android/finger_print_tests.py index cc0457c2..9b8871d9 100644 --- a/test/functional/android/finger_print_tests.py +++ b/test/functional/android/finger_print_tests.py @@ -13,17 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest - from .helper.test_helper import BaseTestCase -class FingerPrintTests(BaseTestCase): +class TestFingerPrint(BaseTestCase): def test_finger_print(self) -> None: result = self.driver.finger_print(1) - self.assertEqual(None, result) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(FingerPrintTests) - unittest.TextTestRunner(verbosity=2).run(suite) + assert result is None diff --git a/test/functional/android/helper/test_helper.py b/test/functional/android/helper/test_helper.py index c8b4af27..026ea9e3 100644 --- a/test/functional/android/helper/test_helper.py +++ b/test/functional/android/helper/test_helper.py @@ -15,7 +15,6 @@ import base64 import os -import unittest from typing import TYPE_CHECKING from selenium.webdriver.support import expected_conditions as EC @@ -58,18 +57,18 @@ def wait_for_element(driver: 'WebDriver', locator: str, value: str, timeout: int ) -class BaseTestCase(unittest.TestCase): +class BaseTestCase(): - def setUp(self) -> None: + def setup_method(self, method) -> None: # type: ignore desired_caps = desired_capabilities.get_desired_capabilities('ApiDemos-debug.apk.zip') self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) if is_ci(): self.driver.start_recording_screen() - def tearDown(self) -> None: + def teardown_method(self, method) -> None: # type: ignore if is_ci(): payload = self.driver.stop_recording_screen() - video_path = os.path.join(os.getcwd(), self._testMethodName + '.mp4') + video_path = os.path.join(os.getcwd(), method.__name__ + '.mp4') with open(video_path, "wb") as fd: fd.write(base64.b64decode(payload)) self.driver.quit() diff --git a/test/functional/android/hw_actions_tests.py b/test/functional/android/hw_actions_tests.py index 2a6b14e8..4646d254 100644 --- a/test/functional/android/hw_actions_tests.py +++ b/test/functional/android/hw_actions_tests.py @@ -13,23 +13,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest from time import sleep from .helper.test_helper import BaseTestCase -class HwActionsTests(BaseTestCase): +class TestHwActions(BaseTestCase): def test_lock(self) -> None: self.driver.lock(-1) sleep(10) try: - self.assertTrue(self.driver.is_locked()) + assert self.driver.is_locked() finally: self.driver.unlock() - self.assertFalse(self.driver.is_locked()) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(HwActionsTests) - unittest.TextTestRunner(verbosity=2).run(suite) + assert not self.driver.is_locked() diff --git a/test/functional/android/ime_tests.py b/test/functional/android/ime_tests.py index ade988c6..ea0f6ea0 100644 --- a/test/functional/android/ime_tests.py +++ b/test/functional/android/ime_tests.py @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest from time import sleep from .helper.test_helper import BaseTestCase @@ -22,36 +21,31 @@ GOOGLE_LATIN = 'com.google.android.inputmethod.latin/com.android.inputmethod.latin.LatinIME' # Android O/P -class IMETests(BaseTestCase): +class TestIME(BaseTestCase): def test_available_ime_engines(self) -> None: engines = self.driver.available_ime_engines - self.assertIsInstance(engines, list) - self.assertTrue(ANDROID_LATIN in engines or GOOGLE_LATIN in engines) + assert isinstance(engines, list) + assert ANDROID_LATIN in engines or GOOGLE_LATIN in engines def test_is_ime_active(self) -> None: - self.assertTrue(self.driver.is_ime_active()) + assert self.driver.is_ime_active() def test_active_ime_engine(self) -> None: engines = self.driver.available_ime_engines - self.assertTrue(self.driver.active_ime_engine in engines) + assert self.driver.active_ime_engine in engines def test_activate_ime_engine(self) -> None: engines = self.driver.available_ime_engines self.driver.activate_ime_engine(engines[-1]) - self.assertEqual(self.driver.active_ime_engine, engines[-1]) + assert self.driver.active_ime_engine == engines[-1] def test_deactivate_ime_engine(self) -> None: engines = self.driver.available_ime_engines self.driver.activate_ime_engine(engines[-1]) - self.assertEqual(self.driver.active_ime_engine, engines[-1]) + assert self.driver.active_ime_engine == engines[-1] self.driver.deactivate_ime_engine() sleep(1) - self.assertNotEqual(self.driver.active_ime_engine, engines[-1]) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(IMETests) - unittest.TextTestRunner(verbosity=2).run(suite) + assert self.driver.active_ime_engine != engines[-1] diff --git a/test/functional/android/keyboard_tests.py b/test/functional/android/keyboard_tests.py index 53a5d48c..5e1ebe6a 100644 --- a/test/functional/android/keyboard_tests.py +++ b/test/functional/android/keyboard_tests.py @@ -13,12 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest - from .helper.test_helper import BaseTestCase -class KeyboardTests(BaseTestCase): +class TestKeyboard(BaseTestCase): def test_press_keycode(self) -> None: # TODO not sure how to test this. self.driver.press_keycode(176) @@ -26,8 +24,3 @@ def test_press_keycode(self) -> None: def test_long_press_keycode(self) -> None: # TODO not sure how to test this. self.driver.long_press_keycode(176) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(KeyboardTests) - unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/functional/android/location_tests.py b/test/functional/android/location_tests.py index 68603385..30cd7880 100644 --- a/test/functional/android/location_tests.py +++ b/test/functional/android/location_tests.py @@ -13,16 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest - from .helper.test_helper import BaseTestCase -class LocationTests(BaseTestCase): +class TestLocation(BaseTestCase): def test_toggle_location_services(self) -> None: self.driver.toggle_location_services() # TODO Add assert - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(LocationTests) - unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/functional/android/log_event_tests.py b/test/functional/android/log_event_tests.py index cc3c2b62..9ad0b53d 100644 --- a/test/functional/android/log_event_tests.py +++ b/test/functional/android/log_event_tests.py @@ -13,19 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest - from .helper.test_helper import BaseTestCase -class LogEventTests(BaseTestCase): +class TestLogEvent(BaseTestCase): def test_log_event(self) -> None: vendor = 'appium' event = 'funEvent' self.driver.log_event(vendor, event) assert f'{vendor}:{event}' in self.driver.get_events().keys() - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(LogEventTests) - unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/functional/android/multi_action_tests.py b/test/functional/android/multi_action_tests.py index 9904ccbf..24b4b404 100644 --- a/test/functional/android/multi_action_tests.py +++ b/test/functional/android/multi_action_tests.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest from time import sleep from appium.webdriver.common.mobileby import MobileBy @@ -22,7 +21,7 @@ from .helper.test_helper import BaseTestCase, wait_for_element -class MultiActionTests(BaseTestCase): +class TestMultiAction(BaseTestCase): def test_parallel_actions(self) -> None: el1 = self.driver.find_element_by_accessibility_id('Content') el2 = self.driver.find_element_by_accessibility_id('Animation') @@ -117,8 +116,3 @@ def test_driver_multi_tap(self) -> None: # THE TEST MUST BE WATCHED TO CHECK IF IT WORKS self.driver.tap(positions) sleep(10) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(MultiActionTests) - unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/functional/android/network_connection_tests.py b/test/functional/android/network_connection_tests.py index 73d3816d..e0a5fb7d 100644 --- a/test/functional/android/network_connection_tests.py +++ b/test/functional/android/network_connection_tests.py @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest +import pytest from appium.webdriver.connectiontype import ConnectionType @@ -21,19 +21,13 @@ from .helper.test_helper import BaseTestCase -class NetworkConnectionTests(BaseTestCase): +class TestNetworkConnection(BaseTestCase): def test_get_network_connection(self) -> None: nc = self.driver.network_connection - self.assertIsInstance(nc, int) + 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: - 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) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(NetworkConnectionTests) - unittest.TextTestRunner(verbosity=2).run(suite) + assert isinstance(nc, int) + assert nc == ConnectionType.DATA_ONLY diff --git a/test/functional/android/remote_fs_tests.py b/test/functional/android/remote_fs_tests.py index db6f3f1e..a71fe30c 100644 --- a/test/functional/android/remote_fs_tests.py +++ b/test/functional/android/remote_fs_tests.py @@ -15,14 +15,13 @@ import base64 import os import random -import unittest from io import BytesIO from zipfile import ZipFile from .helper.test_helper import BaseTestCase -class RemoteFsTests(BaseTestCase): +class TestRemoteFs(BaseTestCase): def test_push_pull_file(self) -> None: dest_path = '/data/local/tmp/test_push_file.txt' data = bytes('This is the contents of the file to push to the device.', 'utf-8') @@ -30,7 +29,7 @@ def test_push_pull_file(self) -> None: self.driver.push_file(dest_path, base64.b64encode(data).decode('utf-8')) data_ret = base64.b64decode(self.driver.pull_file(dest_path)) - self.assertEqual(data, data_ret) + assert data == data_ret def test_pull_folder(self) -> None: data = bytes('random string data {}'.format(random.randint(0, 1000)), 'utf-8') @@ -43,7 +42,7 @@ def test_pull_folder(self) -> None: with ZipFile(BytesIO(base64.b64decode(folder))) as fzip: for filename in ['1.txt', '2.txt']: - self.assertTrue(filename in fzip.namelist()) + assert filename in fzip.namelist() def test_push_file_with_src_path(self) -> None: test_files = ['test_image.jpg', 'test_file.txt'] @@ -56,9 +55,4 @@ def test_push_file_with_src_path(self) -> None: self.driver.push_file(dest_path, source_path=src_path) new_data = base64.b64decode(self.driver.pull_file(dest_path)) - self.assertEqual(original_data, new_data) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(RemoteFsTests) - unittest.TextTestRunner(verbosity=2).run(suite) + assert original_data == new_data diff --git a/test/functional/android/screen_record_tests.py b/test/functional/android/screen_record_tests.py index cad3b72b..49618a89 100644 --- a/test/functional/android/screen_record_tests.py +++ b/test/functional/android/screen_record_tests.py @@ -13,20 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest from time import sleep from .helper.test_helper import BaseTestCase -class ScreenRecordTests(BaseTestCase): +class TestScreenRecord(BaseTestCase): def test_screen_record(self) -> None: self.driver.start_recording_screen(timeLimit=10, forcedRestart=True) sleep(10) result = self.driver.stop_recording_screen() - self.assertTrue(len(result) > 0) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(ScreenRecordTests) - unittest.TextTestRunner(verbosity=2).run(suite) + assert len(result) > 0 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 b3a64507..6932dba2 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 @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest +import pytest from appium.webdriver.common.mobileby import MobileBy from test.functional.android.helper.test_helper import ( @@ -22,37 +22,31 @@ from test.functional.test_helper import is_ci -class FindByAccessibilityIDTests(BaseTestCase): +class TestFindByAccessibilityID(BaseTestCase): def test_find_single_element(self) -> None: 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.ACCESSIBILITY_ID, 'Task Take out Trash') - self.assertIsNotNone(el) + assert el is not None def test_find_multiple_elements(self) -> None: els = self.driver.find_elements_by_accessibility_id('Accessibility') - self.assertIsInstance(els, list) + assert isinstance(els, list) + @pytest.mark.skipif(condition=is_ci(), reason='Need to fix flaky test during running on CI') def test_element_find_single_element(self) -> None: - 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() el = wait_for_element(self.driver, MobileBy.CLASS_NAME, 'android.widget.ListView') sub_el = el.find_element_by_accessibility_id('Task Take out Trash') - self.assertIsNotNone(sub_el) + assert sub_el is not None def test_element_find_multiple_elements(self) -> None: wait_for_element(self.driver, MobileBy.CLASS_NAME, 'android.widget.ListView') el = self.driver.find_element_by_class_name('android.widget.ListView') sub_els = el.find_elements_by_accessibility_id('Animation') - self.assertIsInstance(sub_els, list) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(FindByAccessibilityIDTests) - unittest.TextTestRunner(verbosity=2).run(suite) + assert isinstance(sub_els, list) 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 8d3440f5..03b552c2 100644 --- a/test/functional/android/search_context/find_by_image_tests.py +++ b/test/functional/android/search_context/find_by_image_tests.py @@ -13,7 +13,6 @@ # limitations under the License. import base64 -import unittest import pytest from selenium.common.exceptions import NoSuchElementException, TimeoutException @@ -26,9 +25,9 @@ @pytest.mark.skip(reason="Need to fix broken test") -class FindByImageTests(unittest.TestCase): +class TestFindByImage(object): - def setUp(self) -> None: + def setup_method(self) -> None: desired_caps = desired_capabilities.get_desired_capabilities('ApiDemos-debug.apk') self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) @@ -37,7 +36,7 @@ def setUp(self) -> None: "fixImageTemplateSize": True, "autoUpdateImageElementPosition": True}) - def tearDown(self) -> None: + def teardown_method(self) -> None: self.driver.quit() def test_find_based_on_image_template(self) -> None: @@ -50,17 +49,17 @@ def test_find_based_on_image_template(self) -> None: EC.presence_of_element_located((By.IMAGE, b64_data)) ) size = el.size - self.assertIsNotNone(size['width']) - self.assertIsNotNone(size['height']) + assert size['width'] is not None + assert size['height'] is not None loc = el.location - self.assertIsNotNone(loc['x']) - self.assertIsNotNone(loc['y']) + assert loc['x'] is not None + assert loc['y'] is not None rect = el.rect - self.assertIsNotNone(rect['width']) - self.assertIsNotNone(rect['height']) - self.assertIsNotNone(rect['x']) - self.assertIsNotNone(rect['y']) - self.assertTrue(el.is_displayed()) + assert rect['width'] is not None + assert rect['height'] is not None + assert rect['x'] is not None + assert rect['y'] is not None + assert el.is_displayed() el.click() self.driver.find_element_by_accessibility_id("Alarm") @@ -78,14 +77,9 @@ def test_find_throws_no_such_element(self) -> None: with open(image_path, 'rb') as png_file: b64_data = base64.b64encode(png_file.read()).decode('UTF-8') - with self.assertRaises(TimeoutException): + with pytest.raises(TimeoutException): WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.IMAGE, b64_data)) ) - with self.assertRaises(NoSuchElementException): + with pytest.raises(NoSuchElementException): self.driver.find_element_by_image(image_path) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(FindByImageTests) - unittest.TextTestRunner(verbosity=2).run(suite) 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 1e197e8e..2c23cfee 100644 --- a/test/functional/android/search_context/find_by_uiautomator_tests.py +++ b/test/functional/android/search_context/find_by_uiautomator_tests.py @@ -12,41 +12,35 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest - import pytest from test.functional.android.helper.test_helper import BaseTestCase @pytest.mark.skip(reason="Need to fix flaky test") -class FindByUIAutomatorTests(BaseTestCase): +class TestFindByUIAutomator(BaseTestCase): def test_find_single_element(self) -> None: el = self.driver.find_element_by_android_uiautomator('new UiSelector().text("Animation")') - self.assertIsNotNone(el) + assert el is not None def test_find_multiple_elements(self) -> None: els = self.driver.find_elements_by_android_uiautomator('new UiSelector().clickable(true)') - self.assertIsInstance(els, list) + assert isinstance(els, list) def test_element_find_single_element(self) -> None: el = self.driver.find_element_by_class_name('android.widget.ListView') sub_el = el.find_element_by_android_uiautomator('new UiSelector().description("Animation")') - self.assertIsNotNone(sub_el) + assert sub_el is not None def test_element_find_multiple_elements(self) -> None: el = self.driver.find_element_by_class_name('android.widget.ListView') sub_els = el.find_elements_by_android_uiautomator('new UiSelector().clickable(true)') - self.assertIsInstance(sub_els, list) + assert isinstance(sub_els, list) def test_scroll_into_view(self) -> None: el = self.driver.find_element_by_android_uiautomator( 'new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("Views").instance(0));') el.click() - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(FindByUIAutomatorTests) - unittest.TextTestRunner(verbosity=2).run(suite) + # TODO Add assert diff --git a/test/functional/android/settings_tests.py b/test/functional/android/settings_tests.py index 98f3d667..ac600a3c 100644 --- a/test/functional/android/settings_tests.py +++ b/test/functional/android/settings_tests.py @@ -13,22 +13,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest - from .helper.test_helper import BaseTestCase -class SettingsTests(BaseTestCase): +class TestSettings(BaseTestCase): def test_get_settings(self) -> None: settings = self.driver.get_settings() - self.assertIsNotNone(settings) + assert settings is not None def test_update_settings(self) -> None: self.driver.update_settings({"waitForIdleTimeout": 10001}) settings = self.driver.get_settings() - self.assertEqual(settings["waitForIdleTimeout"], 10001) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(SettingsTests) - unittest.TextTestRunner(verbosity=2).run(suite) + assert settings["waitForIdleTimeout"] == 10001 diff --git a/test/functional/android/touch_action_tests.py b/test/functional/android/touch_action_tests.py index 22c11bba..59ee65a4 100644 --- a/test/functional/android/touch_action_tests.py +++ b/test/functional/android/touch_action_tests.py @@ -12,8 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest - +import pytest from selenium.common.exceptions import NoSuchElementException from appium.webdriver.common.mobileby import MobileBy @@ -26,13 +25,13 @@ ) -class TouchActionTests(BaseTestCase): +class TestTouchAction(BaseTestCase): def test_tap(self) -> None: el = self.driver.find_element_by_accessibility_id('Animation') action = TouchAction(self.driver) action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Bouncing Balls') - self.assertIsNotNone(el) + assert el is not None def test_tap_x_y(self) -> None: el = self.driver.find_element_by_accessibility_id('Animation') @@ -40,7 +39,7 @@ def test_tap_x_y(self) -> None: action.tap(el, 100, 10).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Bouncing Balls') - self.assertIsNotNone(el) + assert el is not None def test_tap_twice(self) -> None: el = self.driver.find_element_by_accessibility_id('Text') @@ -54,7 +53,7 @@ def test_tap_twice(self) -> None: action.tap(el, count=2).perform() els = self.driver.find_elements_by_class_name('android.widget.TextView') - self.assertEqual('This is a test\nThis is a test\n', els[1].get_attribute("text")) + assert 'This is a test\nThis is a test\n' == els[1].get_attribute("text") def test_press_and_immediately_release(self) -> None: el = self.driver.find_element_by_accessibility_id('Animation') @@ -62,7 +61,7 @@ def test_press_and_immediately_release(self) -> None: action.press(el).release().perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Bouncing Balls') - self.assertIsNotNone(el) + assert el is not None def test_press_and_immediately_release_x_y(self) -> None: el = self.driver.find_element_by_accessibility_id('Animation') @@ -70,7 +69,7 @@ def test_press_and_immediately_release_x_y(self) -> None: action.press(el, 100, 10).release().perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Bouncing Balls') - self.assertIsNotNone(el) + assert el is not None def test_press_and_wait(self) -> None: el1 = self.driver.find_element_by_accessibility_id('Content') @@ -95,7 +94,7 @@ def test_press_and_wait(self) -> None: # 'Sample menu' only comes up with a long press, not a press el = wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("Sample menu")') - self.assertIsNotNone(el) + assert el is not None def test_press_and_moveto(self) -> None: el1 = self.driver.find_element_by_accessibility_id('Content') @@ -105,7 +104,7 @@ def test_press_and_moveto(self) -> None: action.press(el1).move_to(el2).release().perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Views') - self.assertIsNotNone(el) + assert el is not None def test_press_and_moveto_x_y(self) -> None: el1 = self.driver.find_element_by_accessibility_id('Content') @@ -115,7 +114,7 @@ def test_press_and_moveto_x_y(self) -> None: action.press(el1).move_to(el2, 100, 100).release().perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Views') - self.assertIsNotNone(el) + assert el is not None def test_long_press(self) -> None: el1 = self.driver.find_element_by_accessibility_id('Content') @@ -140,7 +139,7 @@ def test_long_press(self) -> None: # 'Sample menu' only comes up with a long press, not a tap el = wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("Sample menu")') - self.assertIsNotNone(el) + assert el is not None def test_long_press_x_y(self) -> None: el1 = self.driver.find_element_by_accessibility_id('Content') @@ -165,7 +164,7 @@ def test_long_press_x_y(self) -> None: # 'Sample menu' only comes up with a long press, not a tap el = wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("Sample menu")') - self.assertIsNotNone(el) + assert el is not None def test_drag_and_drop(self) -> None: el1 = self.driver.find_element_by_accessibility_id('Content') @@ -186,7 +185,7 @@ def test_drag_and_drop(self) -> None: 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) + assert 'drag_dot_3' in el.text def test_driver_drag_and_drop(self) -> None: el1 = self.driver.find_element_by_accessibility_id('Content') @@ -206,20 +205,16 @@ def test_driver_drag_and_drop(self) -> None: 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) + assert 'drag_dot_3' in el.text def test_driver_swipe(self) -> None: el = self.driver.find_element_by_accessibility_id('Views') action = TouchAction(self.driver) action.tap(el).perform() - self.assertRaises(NoSuchElementException, self.driver.find_element_by_accessibility_id, 'ImageView') + with pytest.raises(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') - self.assertIsNotNone(el) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(TouchActionTests) - unittest.TextTestRunner(verbosity=2).run(suite) + assert el is not None diff --git a/test/functional/android/webelement_tests.py b/test/functional/android/webelement_tests.py index bb28782f..d9c484c4 100644 --- a/test/functional/android/webelement_tests.py +++ b/test/functional/android/webelement_tests.py @@ -13,8 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest - from appium.webdriver.common.mobileby import MobileBy from .helper.test_helper import ( @@ -24,12 +22,12 @@ ) -class WebelementTests(BaseTestCase): +class TestWebelement(BaseTestCase): def test_element_location_in_view(self) -> None: el = self.driver.find_element_by_accessibility_id('Content') loc = el.location_in_view - self.assertIsNotNone(loc['x']) - self.assertIsNotNone(loc['y']) + assert loc['x'] is not None + assert loc['y'] is not None def test_set_text(self) -> None: self.driver.find_element_by_android_uiautomator( @@ -42,7 +40,7 @@ def test_set_text(self) -> None: el.send_keys('original text') el.set_text('new text') - self.assertEqual('new text', el.text) + assert 'new text' == el.text def test_send_keys(self) -> None: for text in ['App', 'Activity', 'Custom Title']: @@ -52,9 +50,4 @@ def test_send_keys(self) -> None: el = wait_for_element(self.driver, MobileBy.ID, '{}:id/left_text_edit'.format(APIDEMO_PKG_NAME)) el.send_keys(' text') - self.assertEqual('Left is best text', el.text) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(WebelementTests) - unittest.TextTestRunner(verbosity=2).run(suite) + assert 'Left is best text' == el.text diff --git a/test/functional/ios/applications_tests.py b/test/functional/ios/applications_tests.py index 362ab42e..c3b3ef1c 100644 --- a/test/functional/ios/applications_tests.py +++ b/test/functional/ios/applications_tests.py @@ -12,31 +12,21 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest - from appium.webdriver.applicationstate import ApplicationState from test.functional.ios.helper.test_helper import BaseTestCase from .helper import desired_capabilities -class WebDriverTests(BaseTestCase): +class TestWebDriver(BaseTestCase): def test_app_management(self) -> None: # this only works in Xcode9+ if float(desired_capabilities.get_desired_capabilities( desired_capabilities.BUNDLE_ID)['platformVersion']) < 11: return - self.assertEqual(self.driver.query_app_state(desired_capabilities.BUNDLE_ID), - ApplicationState.RUNNING_IN_FOREGROUND) + assert self.driver.query_app_state(desired_capabilities.BUNDLE_ID) == ApplicationState.RUNNING_IN_FOREGROUND self.driver.background_app(-1) - self.assertTrue(self.driver.query_app_state(desired_capabilities.BUNDLE_ID) < - ApplicationState.RUNNING_IN_FOREGROUND) + assert self.driver.query_app_state(desired_capabilities.BUNDLE_ID) < ApplicationState.RUNNING_IN_FOREGROUND self.driver.activate_app(desired_capabilities.BUNDLE_ID) - self.assertEqual(self.driver.query_app_state(desired_capabilities.BUNDLE_ID), - ApplicationState.RUNNING_IN_FOREGROUND) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(WebDriverTests) - unittest.TextTestRunner(verbosity=2).run(suite) + assert self.driver.query_app_state(desired_capabilities.BUNDLE_ID) == ApplicationState.RUNNING_IN_FOREGROUND diff --git a/test/functional/ios/execute_driver_tests.py b/test/functional/ios/execute_driver_tests.py index cf696675..8c3a64e8 100644 --- a/test/functional/ios/execute_driver_tests.py +++ b/test/functional/ios/execute_driver_tests.py @@ -13,12 +13,11 @@ # limitations under the License. import textwrap -import unittest from test.functional.ios.helper.test_helper import BaseTestCase -class ExecuteDriverTests(BaseTestCase): +class TestExecuteDriver(BaseTestCase): def test_batch(self) -> None: script = """ const status = await driver.status(); @@ -42,8 +41,3 @@ def test_batch_combination_python_script(self) -> None: r = response.result[0].rect assert(r == response.result[1]) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(ExecuteDriverTests) - unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/functional/ios/helper/test_helper.py b/test/functional/ios/helper/test_helper.py index 1e66e46d..f78912f6 100644 --- a/test/functional/ios/helper/test_helper.py +++ b/test/functional/ios/helper/test_helper.py @@ -15,7 +15,6 @@ import base64 import os -import unittest from appium import webdriver from test.functional.test_helper import is_ci @@ -23,18 +22,18 @@ from . import desired_capabilities -class BaseTestCase(unittest.TestCase): +class BaseTestCase(object): - def setUp(self) -> None: + def setup_method(self) -> None: desired_caps = desired_capabilities.get_desired_capabilities('UICatalog.app.zip') self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) if is_ci(): self.driver.start_recording_screen() - def tearDown(self) -> None: + def teardown_method(self, method) -> None: # type: ignore if is_ci(): payload = self.driver.stop_recording_screen() - video_path = os.path.join(os.getcwd(), self._testMethodName + '.mp4') + video_path = os.path.join(os.getcwd(), method.__name__ + '.mp4') with open(video_path, "wb") as fd: fd.write(base64.b64decode(payload)) self.driver.quit() diff --git a/test/functional/ios/hw_actions_tests.py b/test/functional/ios/hw_actions_tests.py index 9f43392f..86264b37 100644 --- a/test/functional/ios/hw_actions_tests.py +++ b/test/functional/ios/hw_actions_tests.py @@ -12,19 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest - from test.functional.ios.helper.test_helper import BaseTestCase -class HwActionsTests(BaseTestCase): +class TestHwActions(BaseTestCase): def test_lock(self) -> None: self.driver.lock(-1) try: - self.assertTrue(self.driver.is_locked()) + assert self.driver.is_locked() finally: self.driver.unlock() - self.assertFalse(self.driver.is_locked()) + assert not self.driver.is_locked() def test_shake(self) -> None: # TODO what can we assert about this? @@ -38,8 +36,3 @@ def test_touch_id(self) -> None: def test_toggle_touch_id_enrollment(self) -> None: # nothing to assert, just verify that it doesn't blow up self.driver.toggle_touch_id_enrollment() - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(HwActionsTests) - unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/functional/ios/keyboard_tests.py b/test/functional/ios/keyboard_tests.py index 08ecfdfa..0ee303e0 100644 --- a/test/functional/ios/keyboard_tests.py +++ b/test/functional/ios/keyboard_tests.py @@ -12,13 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest from time import sleep from test.functional.ios.helper.test_helper import BaseTestCase -class KeyboardTests(BaseTestCase): +class TestKeyboard(BaseTestCase): def test_hide_keyboard(self) -> None: self._move_to_textbox() @@ -27,11 +26,11 @@ def test_hide_keyboard(self) -> None: el.set_value('Testing') el = self.driver.find_element_by_class_name('UIAKeyboard') - self.assertTrue(el.is_displayed()) + assert el.is_displayed() self.driver.hide_keyboard(key_name='Done') - self.assertFalse(el.is_displayed()) + assert not el.is_displayed() def test_hide_keyboard_presskey_strategy(self) -> None: self._move_to_textbox() @@ -41,11 +40,11 @@ def test_hide_keyboard_presskey_strategy(self) -> None: el.set_value('Testing') el = self.driver.find_element_by_class_name('UIAKeyboard') - self.assertTrue(el.is_displayed()) + assert el.is_displayed() self.driver.hide_keyboard(strategy='pressKey', key='Done') - self.assertFalse(el.is_displayed()) + assert not el.is_displayed() def test_hide_keyboard_no_key_name(self) -> None: self._move_to_textbox() @@ -55,13 +54,13 @@ def test_hide_keyboard_no_key_name(self) -> None: el.set_value('Testing') el = self.driver.find_element_by_class_name('UIAKeyboard') - self.assertTrue(el.is_displayed()) + assert el.is_displayed() self.driver.hide_keyboard() sleep(10) # currently fails. - self.assertFalse(el.is_displayed()) + assert not el.is_displayed() def test_is_keyboard_shown(self) -> None: self._move_to_textbox() @@ -69,7 +68,7 @@ def test_is_keyboard_shown(self) -> None: el = self.driver.find_elements_by_class_name('XCUIElementTypeTextField')[0] el.click() el.set_value('Testing') - self.assertTrue(self.driver.is_keyboard_shown()) + assert self.driver.is_keyboard_shown() def _move_to_textbox(self) -> None: el1 = self.driver.find_element_by_accessibility_id('Sliders') @@ -78,8 +77,3 @@ def _move_to_textbox(self) -> None: # Click text fields self.driver.find_element_by_accessibility_id('Text Fields').click() - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(KeyboardTests) - unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/functional/ios/remote_fs_tests.py b/test/functional/ios/remote_fs_tests.py index 66cad40e..89b42568 100644 --- a/test/functional/ios/remote_fs_tests.py +++ b/test/functional/ios/remote_fs_tests.py @@ -13,12 +13,11 @@ # limitations under the License. import os -import unittest from test.functional.ios.helper.test_helper import BaseTestCase -class RemoteFsTests(BaseTestCase): +class TestRemoteFs(BaseTestCase): def test_push_file(self) -> None: file_name = 'test_image.jpg' @@ -26,8 +25,3 @@ def test_push_file(self) -> None: destination_path = file_name self.driver.push_file(destination_path, source_path=source_path) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(RemoteFsTests) - unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/functional/ios/safari_tests.py b/test/functional/ios/safari_tests.py index 08c73dd4..23d907fc 100644 --- a/test/functional/ios/safari_tests.py +++ b/test/functional/ios/safari_tests.py @@ -12,15 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest - from appium import webdriver from .helper.desired_capabilities import get_desired_capabilities -class SafariTests(unittest.TestCase): - def setUp(self) -> None: +class TestSafari(object): + def setup_method(self) -> None: desired_caps = get_desired_capabilities() desired_caps.update({ 'browserName': 'safari', @@ -30,19 +28,14 @@ def setUp(self) -> None: self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) - def tearDown(self) -> None: + def teardown_method(self) -> None: self.driver.quit() def test_context(self) -> None: - self.assertEqual('NATIVE_APP', self.driver.contexts[0]) - self.assertTrue(self.driver.contexts[1].startswith('WEBVIEW_')) - self.assertTrue('WEBVIEW_' in self.driver.current_context) + assert 'NATIVE_APP' == self.driver.contexts[0] + assert self.driver.contexts[1].startswith('WEBVIEW_') + assert 'WEBVIEW_' in self.driver.current_context def test_get(self) -> None: self.driver.get("http://google.com") - self.assertEqual('Google', self.driver.title) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(SafariTests) - unittest.TextTestRunner(verbosity=2).run(suite) + assert 'Google' == self.driver.title diff --git a/test/functional/ios/screen_record_tests.py b/test/functional/ios/screen_record_tests.py index 33a5e98a..b821f6d3 100644 --- a/test/functional/ios/screen_record_tests.py +++ b/test/functional/ios/screen_record_tests.py @@ -12,20 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest from time import sleep from test.functional.ios.helper.test_helper import BaseTestCase -class ScreenRecordTests(BaseTestCase): +class TestScreenRecord(BaseTestCase): def test_screen_record(self) -> None: self.driver.start_recording_screen() sleep(10) result = self.driver.stop_recording_screen() - self.assertTrue(len(result) > 0) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(ScreenRecordTests) - unittest.TextTestRunner(verbosity=2).run(suite) + assert len(result) > 0 diff --git a/test/functional/ios/search_context/find_by_element_webelement_tests.py b/test/functional/ios/search_context/find_by_element_webelement_tests.py index 2e81fec5..96d8ed91 100644 --- a/test/functional/ios/search_context/find_by_element_webelement_tests.py +++ b/test/functional/ios/search_context/find_by_element_webelement_tests.py @@ -12,27 +12,20 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest - from test.functional.ios.helper.test_helper import BaseTestCase -class FindByElementWebelementTests(BaseTestCase): +class TestFindByElementWebelement(BaseTestCase): def test_find_element_by_path(self) -> None: el = self.driver.find_element_by_ios_predicate('wdName == "UICatalog"') - self.assertEqual('UICatalog', el.get_attribute('name')) + assert 'UICatalog' == el.get_attribute('name') c_el = el.find_elements_by_ios_predicate('label == "Action Sheets"') - self.assertEqual('Action Sheets', c_el[0].get_attribute('name')) + assert 'Action Sheets' == c_el[0].get_attribute('name') c_el = el.find_elements_by_ios_class_chain('**/XCUIElementTypeStaticText') - self.assertEqual('UICatalog', c_el[0].get_attribute('name')) + assert 'UICatalog' == c_el[0].get_attribute('name') c_el = el.find_elements_by_accessibility_id('UICatalog') - self.assertEqual('UICatalog', c_el[0].get_attribute('name')) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(FindByElementWebelementTests) - unittest.TextTestRunner(verbosity=2).run(suite) + assert 'UICatalog' == c_el[0].get_attribute('name') diff --git a/test/functional/ios/search_context/find_by_ios_class_chain_tests.py b/test/functional/ios/search_context/find_by_ios_class_chain_tests.py index 3c02fb2b..7ff0a24d 100644 --- a/test/functional/ios/search_context/find_by_ios_class_chain_tests.py +++ b/test/functional/ios/search_context/find_by_ios_class_chain_tests.py @@ -12,24 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest - from test.functional.ios.helper.test_helper import BaseTestCase -class FindByIOClassChainTests(BaseTestCase): +class TestFindByIOClassChain(BaseTestCase): def test_find_element_by_path(self) -> None: els = self.driver.find_elements_by_ios_class_chain('XCUIElementTypeWindow/**/XCUIElementTypeStaticText') - self.assertEqual(35, len(els)) - self.assertEqual('UICatalog', els[0].get_attribute('name')) + assert 35 == len(els) + assert 'UICatalog' == els[0].get_attribute('name') def test_find_multiple_elements_by_path(self) -> None: el = self.driver.find_elements_by_ios_class_chain('XCUIElementTypeWindow/*/*/*') - self.assertEqual(2, len(el)) - self.assertEqual('UICatalog', el[0].get_attribute('name')) - self.assertEqual(None, el[1].get_attribute('name')) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(FindByIOClassChainTests) - unittest.TextTestRunner(verbosity=2).run(suite) + assert 2 == len(el) + assert 'UICatalog' == el[0].get_attribute('name') + assert el[1].get_attribute('name') is None diff --git a/test/functional/ios/search_context/find_by_ios_predicate_tests.py b/test/functional/ios/search_context/find_by_ios_predicate_tests.py index 6f5bc6d9..41908479 100644 --- a/test/functional/ios/search_context/find_by_ios_predicate_tests.py +++ b/test/functional/ios/search_context/find_by_ios_predicate_tests.py @@ -12,19 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest - from test.functional.ios.helper.test_helper import BaseTestCase -class FindByIOSPredicateTests(BaseTestCase): +class TestFindByIOSPredicate(BaseTestCase): def test_find_element_by_name(self) -> None: # Will throw exception if element is not found self.driver.find_element_by_ios_predicate('wdName == "Buttons"') def test_find_multiple_element_by_type(self) -> None: e = self.driver.find_elements_by_ios_predicate('wdType == "XCUIElementTypeStaticText"') - self.assertNotEqual(len(e), 0) + assert len(e) != 0 def test_find_element_by_label(self) -> None: # Will throw exception if element is not found @@ -40,7 +38,7 @@ def test_find_element_by_isvisible(self) -> None: # Should not find any elements e = self.driver.find_elements_by_ios_predicate('wdValue == "Buttons" AND visible == 0') - self.assertEqual(len(e), 0) + assert len(e) == 0 def test_find_element_by_isenabled(self) -> None: # Will throw exception if element is not found @@ -48,9 +46,4 @@ def test_find_element_by_isenabled(self) -> None: # Should not find any elements e = self.driver.find_elements_by_ios_predicate('wdValue == "Buttons" AND enabled == 0') - self.assertEqual(len(e), 0) - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(FindByIOSPredicateTests) - unittest.TextTestRunner(verbosity=2).run(suite) + assert len(e) == 0 diff --git a/test/functional/ios/webdriver_tests.py b/test/functional/ios/webdriver_tests.py index 7a7c5149..629190ef 100644 --- a/test/functional/ios/webdriver_tests.py +++ b/test/functional/ios/webdriver_tests.py @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest from typing import TYPE_CHECKING +import pytest from selenium.webdriver.support.ui import WebDriverWait from appium import webdriver @@ -29,12 +29,11 @@ from appium.webdriver.webdriver import WebDriver -class WebDriverTests(BaseTestCase): +class TestWebDriver(BaseTestCase): + # TODO Due to not created 2nd session somehow + @pytest.mark.skipif(condition=is_ci(), reason='Need to fix flaky test during running on CI.') def test_all_sessions(self) -> None: - if is_ci(): - # TODO Due to not created 2nd session somehow - self.skipTest('Need to fix flaky test during running on CI.') port = get_available_from_port_range(8200, 8300) desired_caps = desired_capabilities.get_desired_capabilities('UICatalog.app.zip') desired_caps['deviceName'] = 'iPhone Xs Max' @@ -51,7 +50,7 @@ def __call__(self, driver: 'WebDriver') -> bool: driver2 = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) WebDriverWait( driver2, session_counts_is_two.TIMEOUT).until(session_counts_is_two()) - self.assertEqual(2, len(self.driver.all_sessions)) + assert len(self.driver.all_sessions) == 2 finally: if driver2 is not None: driver2.quit() @@ -61,14 +60,11 @@ def test_app_management(self) -> None: if float(desired_capabilities.get_desired_capabilities( desired_capabilities.BUNDLE_ID)['platformVersion']) < 11: return - self.assertEqual(self.driver.query_app_state(desired_capabilities.BUNDLE_ID), - ApplicationState.RUNNING_IN_FOREGROUND) + assert self.driver.query_app_state(desired_capabilities.BUNDLE_ID) == ApplicationState.RUNNING_IN_FOREGROUND self.driver.background_app(-1) - self.assertTrue(self.driver.query_app_state(desired_capabilities.BUNDLE_ID) < - ApplicationState.RUNNING_IN_FOREGROUND) + assert self.driver.query_app_state(desired_capabilities.BUNDLE_ID) < ApplicationState.RUNNING_IN_FOREGROUND self.driver.activate_app(desired_capabilities.BUNDLE_ID) - self.assertEqual(self.driver.query_app_state(desired_capabilities.BUNDLE_ID), - ApplicationState.RUNNING_IN_FOREGROUND) + assert self.driver.query_app_state(desired_capabilities.BUNDLE_ID) == ApplicationState.RUNNING_IN_FOREGROUND def test_clear(self) -> None: self._move_to_textbox() @@ -78,7 +74,7 @@ def test_clear(self) -> None: # Verify default text def_text = 'Placeholder text' text = el.get_attribute('value') - self.assertEqual(text, def_text) + assert text == def_text # Input some text, verify input_text = 'blah' @@ -87,20 +83,19 @@ def test_clear(self) -> None: # TODO Needs to get the element again to update value in the element. Remove below one line when it's fixed. el = self.driver.find_elements_by_class_name('XCUIElementTypeTextField')[0] text = el.get_attribute('value') - self.assertEqual(text, input_text) + assert text == input_text # Clear text, verify el.clear() text = el.get_attribute('value') - self.assertEqual(text, def_text) + assert text == def_text def test_press_button(self) -> None: self.driver.press_button("Home") if float(desired_capabilities.get_desired_capabilities( desired_capabilities.BUNDLE_ID)['platformVersion']) < 11: return - self.assertEqual(self.driver.query_app_state(desired_capabilities.BUNDLE_ID), - ApplicationState.RUNNING_IN_FOREGROUND) + assert self.driver.query_app_state(desired_capabilities.BUNDLE_ID) == ApplicationState.RUNNING_IN_FOREGROUND def _move_to_textbox(self) -> None: el1 = self.driver.find_element_by_accessibility_id('Sliders') @@ -109,8 +104,3 @@ def _move_to_textbox(self) -> None: # Click text fields self.driver.find_element_by_accessibility_id('Text Fields').click() - - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(WebDriverTests) - unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/unit/webdriver/webdriver_test.py b/test/unit/webdriver/webdriver_test.py index 40e458d5..87e45d18 100644 --- a/test/unit/webdriver/webdriver_test.py +++ b/test/unit/webdriver/webdriver_test.py @@ -275,7 +275,7 @@ def exceptionCallback(request, uri, headers): class SubWebDriver(WebDriver): def __init__(self, command_executor, desired_capabilities, direct_connection=False): - super(SubWebDriver, self).__init__( + super().__init__( command_executor=command_executor, desired_capabilities=desired_capabilities, direct_connection=direct_connection @@ -284,7 +284,7 @@ def __init__(self, command_executor, desired_capabilities, direct_connection=Fal class SubSubWebDriver(SubWebDriver): def __init__(self, command_executor, desired_capabilities, direct_connection=False): - super(SubSubWebDriver, self).__init__( + super().__init__( command_executor=command_executor, desired_capabilities=desired_capabilities, direct_connection=direct_connection