Skip to content

Rebase python3 branch with master #522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Apr 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6e1a2a7
Update pytest-cov requirement from ~=2.6 to ~=2.8 (#489)
dependabot-preview[bot] Jan 26, 2020
53dc75f
Update autopep8 requirement from ~=1.4 to ~=1.5 (#490)
dependabot-preview[bot] Jan 26, 2020
3359a44
Update tox-travis requirement from ~=0.11 to ~=0.12 (#491)
dependabot-preview[bot] Jan 26, 2020
4d269f8
Update tox requirement from ~=3.6 to ~=3.14 (#494)
dependabot-preview[bot] Jan 27, 2020
b95776d
chore: Fix find_by_images_tests.py (#495)
ki4070ma Jan 30, 2020
f2bf259
feat: Add viewmatcher (#480)
ki4070ma Feb 9, 2020
864b045
Bump 0.50
KazuCocoa Feb 10, 2020
f14291b
Update changelog for 0.50
KazuCocoa Feb 10, 2020
446b8c4
Fix flaky functional tests (#473)
ki4070ma Feb 10, 2020
4641b45
feat: Add idempotency key header to create session requests (#514)
mykola-mokhnach Apr 11, 2020
34427a1
feat: Override send_keys without file upload function (#515)
KazuCocoa Apr 12, 2020
5a545d7
Bump 0.51
KazuCocoa Apr 12, 2020
2141dbd
Update changelog for 0.51
KazuCocoa Apr 12, 2020
9bdf1f7
test: Fix test_clear flaky functional test (#519)
iamnrupesh Apr 15, 2020
ba64adf
test: Add unit test for set_value (setImmediateValue) (#518)
iamnrupesh Apr 15, 2020
9e1959c
chore: Fix int - str comparison error in ios desired capabilities (#517)
Akulavenkatesh Apr 19, 2020
a2e21d1
fix: Handling of dictionary-values in WebElement.get_attribute() (#521)
hanneshauer Apr 23, 2020
c702cef
Bump 0.52
KazuCocoa Apr 23, 2020
cfd99cf
Update changelog for 0.52
KazuCocoa Apr 23, 2020
569342e
Merge branch 'master' into rebase-master
ki4070ma Apr 25, 2020
c8d1af3
Fix mypy error
ki4070ma Apr 26, 2020
91a26e8
tweak
ki4070ma Apr 26, 2020
e800ce7
Add wait to test
ki4070ma Apr 26, 2020
efd0655
Skip tap_twice test
ki4070ma Apr 26, 2020
c378859
review comments
ki4070ma Apr 26, 2020
56e8e0c
Remove unnecessary import
ki4070ma Apr 26, 2020
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
7 changes: 5 additions & 2 deletions appium/webdriver/appium_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@
# limitations under the License.

import uuid
from typing import Any, Dict
from typing import TYPE_CHECKING, Any, Dict

from selenium.webdriver.remote.remote_connection import RemoteConnection

from appium.common.helper import library_version

if TYPE_CHECKING:
from urllib.parse import ParseResult


class AppiumConnection(RemoteConnection):

@classmethod
def get_remote_connection_headers(cls, parsed_url: str, keep_alive: bool = True) -> Dict[str, Any]:
def get_remote_connection_headers(cls, parsed_url: 'ParseResult', keep_alive: bool = True) -> Dict[str, Any]:
Copy link
Contributor

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.

I love mypy

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's nice catch by mypy.

"""Override get_remote_connection_headers in RemoteConnection"""
headers = RemoteConnection.get_remote_connection_headers(parsed_url, keep_alive=keep_alive)
headers['User-Agent'] = 'appium/python {} ({})'.format(library_version(), headers['User-Agent'])
Expand Down
2 changes: 1 addition & 1 deletion appium/webdriver/appium_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def start(self, **kwargs: Any) -> sp.Popen:
if not self.is_running or (timeout_ms > 0 and not poll_url(host, port, STATUS_URL, timeout_ms)):
error_msg = f'Appium has failed to start on {host}:{port} within {timeout_ms}ms timeout'
if error_msg is not None:
if stderr == sp.PIPE:
if stderr == sp.PIPE and self._process.stderr is not None:
Copy link
Collaborator Author

@ki4070ma ki4070ma Apr 26, 2020

Choose a reason for hiding this comment

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

[Notes] To fix mypy error

err_output = self._process.stderr.read()
if err_output:
error_msg += f'\nOriginal error: {str(err_output)}'
Expand Down
11 changes: 6 additions & 5 deletions appium/webdriver/extensions/search_context/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# pylint: disable=abstract-method

import json
from typing import TYPE_CHECKING, List, Optional
from typing import TYPE_CHECKING, Any, List, Optional

from appium.webdriver.common.mobileby import MobileBy

Expand All @@ -28,7 +28,8 @@
class AndroidSearchContext(BaseSearchContext):
"""Define search context for Android"""

def find_element_by_android_view_matcher(self, name=None, args=None, className=None):
def find_element_by_android_view_matcher(
self, name: Optional[str] = None, args: Any = None, className: Optional[str] = None) -> 'WebElement':
"""Finds element by [onView](https://developer.android.com/training/testing/espresso/basics) in Android

It works with [Espresso Driver](https://github.com/appium/appium-espresso-driver).
Expand Down Expand Up @@ -62,7 +63,7 @@ def find_element_by_android_view_matcher(self, name=None, args=None, className=N
)

def find_element_by_android_data_matcher(
self, name: Optional[str] = None, args: Optional[str] = None, className: Optional[str] = None) -> 'WebElement':
self, name: Optional[str] = None, args: Any = None, className: Optional[str] = None) -> 'WebElement':
"""Finds element by [onData](https://medium.com/androiddevelopers/adapterviews-and-espresso-f4172aa853cf) in Android

It works with [Espresso Driver](https://github.com/appium/appium-espresso-driver).
Expand Down Expand Up @@ -95,7 +96,7 @@ def find_element_by_android_data_matcher(
)

def find_elements_by_android_data_matcher(
self, name: Optional[str] = None, args: Optional[str] = None, className: Optional[str] = None) -> List['WebElement']:
self, name: Optional[str] = None, args: Any = None, className: Optional[str] = None) -> List['WebElement']:
"""Finds elements by [onData](https://medium.com/androiddevelopers/adapterviews-and-espresso-f4172aa853cf) in Android
It works with [Espresso Driver](https://github.com/appium/appium-espresso-driver).

Expand All @@ -122,7 +123,7 @@ def find_elements_by_android_data_matcher(
value=self._build_data_matcher(name=name, args=args, className=className)
)

def _build_data_matcher(self, name: Optional[str] = None, args: Optional[str]
def _build_data_matcher(self, name: Optional[str] = None, args: Any
= None, className: Optional[str] = None) -> str:
result = {}

Expand Down
4 changes: 2 additions & 2 deletions appium/webdriver/webelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


class WebElement(AppiumWebElementSearchContext):
def get_attribute(self, name: str) -> Optional[str]:
def get_attribute(self, name: str) -> Optional[Union[str, Dict]]:
"""Gets the given attribute or property of the element.

Override for Appium
Expand Down Expand Up @@ -211,7 +211,7 @@ def set_value(self, value: str) -> T:
return self

# Override
def send_keys(self, *value):
def send_keys(self, *value: str) -> T:
"""Simulates typing into the element.

Args:
Expand Down
2 changes: 1 addition & 1 deletion test/functional/android/multi_action_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_actions_with_waits(self) -> None:
ma.add(a1, a2)
ma.perform()

def _move_to_splitting_touches_accros_views(self):
def _move_to_splitting_touches_accros_views(self) -> None:
el1 = self.driver.find_element_by_accessibility_id('Content')
el2 = self.driver.find_element_by_accessibility_id('Animation')
self.driver.scroll(el1, el2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,33 @@
AndroidSearchContext
)
from test.functional.android.helper.test_helper import (
BaseTestCase,
desired_capabilities,
is_ci
)


class FindByViewMatcherTests(unittest.TestCase):
class TestFindByViewMatcher(BaseTestCase):

def setUp(self):
# Override
def setup_method(self, method) -> None: # type: ignore
desired_caps = desired_capabilities.get_desired_capabilities('ApiDemos-debug.apk.zip')
desired_caps['automationName'] = 'Espresso'
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

def tearDown(self):
if is_ci():
# Take the screenshot to investigate when tests failed only on CI
img_path = os.path.join(os.getcwd(), self._testMethodName + '.png')
self.driver.get_screenshot_as_file(img_path)
self.driver.quit()
self.driver.start_recording_screen()

def test_find_single_element(self):
def test_find_single_element(self) -> None:
el = self.driver.find_element_by_android_view_matcher(
name='withText', args=['Accessibility'], className='ViewMatchers')
assert el.text == 'Accessibility'

def test_find_single_element_ful_class_name(self):
def test_find_single_element_ful_class_name(self) -> None:
el = self.driver.find_element_by_android_view_matcher(
name='withText', args=['Accessibility'], className='androidx.test.espresso.matcher.ViewMatchers')
assert el.text == 'Accessibility'

def test_find_single_element_using_hamcrest_matcher(self):
def test_find_single_element_using_hamcrest_matcher(self) -> None:
el = self.driver.find_element_by_android_view_matcher(
name='withText',
args={
Expand All @@ -65,13 +62,8 @@ def test_find_single_element_using_hamcrest_matcher(self):

# androidx.test.espresso.AmbiguousViewMatcherException:
# 'with text: a string containing "Access"' matches multiple views in the hierarchy.
def test_find_multiple_elements(self):
def test_find_multiple_elements(self) -> None:
value = AndroidSearchContext()._build_data_matcher(
name='withSubstring', args=['Access'], className='ViewMatchers')
with pytest.raises(WebDriverException):
self.driver.find_elements(by=MobileBy.ANDROID_VIEW_MATCHER, value=value)


if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(FindByViewMatcherTests)
unittest.TextTestRunner(verbosity=2).run(suite)
8 changes: 4 additions & 4 deletions test/functional/android/touch_action_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,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_result_text'.format(APIDEMO_PKG_NAME))
self.assertTrue('Dropped!' in el.text)
assert 'Dropped!' in el.text

def test_driver_drag_and_drop(self) -> None:
self._move_to_views()
Expand All @@ -161,7 +161,7 @@ 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_result_text'.format(APIDEMO_PKG_NAME))
self.assertTrue('Dropped!' in el.text)
assert 'Dropped!' in el.text

def test_driver_swipe(self) -> None:
el = self.driver.find_element_by_accessibility_id('Views')
Expand All @@ -175,7 +175,7 @@ def test_driver_swipe(self) -> None:
el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'ImageView')
assert el is not None

def _move_to_views(self):
def _move_to_views(self) -> None:
el1 = self.driver.find_element_by_accessibility_id('Content')
el2 = self.driver.find_element_by_accessibility_id('Animation')
self.driver.scroll(el1, el2)
Expand All @@ -184,7 +184,7 @@ def _move_to_views(self):
action = TouchAction(self.driver)
action.tap(el).perform()

def _move_to_custom_adapter(self):
def _move_to_custom_adapter(self) -> None:
self._move_to_views()
action = TouchAction(self.driver)

Expand Down