Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pre-commit = "~=1.13"
pre-commit = "~=1.21"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be interesting to know if Python has something similar to NodeJS's Greenkeeper, which monitors dependency versions

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @KazuCocoa


[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"
Expand Down
2 changes: 1 addition & 1 deletion appium/webdriver/errorhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion appium/webdriver/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 3 additions & 10 deletions test/functional/android/activities_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
43 changes: 18 additions & 25 deletions test/functional/android/applications_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,70 +13,63 @@
# 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)
sleep(3)
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)
15 changes: 4 additions & 11 deletions test/functional/android/chrome_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 10 additions & 16 deletions test/functional/android/common_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
24 changes: 9 additions & 15 deletions test/functional/android/context_switching_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
9 changes: 1 addition & 8 deletions test/functional/android/device_time_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
11 changes: 2 additions & 9 deletions test/functional/android/finger_print_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 4 additions & 5 deletions test/functional/android/helper/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import base64
import os
import unittest
from typing import TYPE_CHECKING

from selenium.webdriver.support import expected_conditions as EC
Expand Down Expand Up @@ -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()
Loading