Sitelet https://github.com/appium/python-client/pull/674/files
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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ environment:
# Android environment
import unittest
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy

desired_caps = dict(
platformName='Android',
Expand All @@ -115,14 +116,15 @@ desired_caps = dict(
app=PATH('../../../apps/selendroid-test-app.apk')
)
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
el = self.driver.find_element_by_accessibility_id('item')
el = self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='item')
el.click()
```

```python
# iOS environment
import unittest
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy

desired_caps = dict(
platformName='iOS',
Expand All @@ -133,7 +135,7 @@ desired_caps = dict(
)

self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
el = self.driver.find_element_by_accessibility_id('item')
el = self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='item')
el.click()
```

Expand Down
2 changes: 1 addition & 1 deletion appium/webdriver/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def add_command(self):

driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps,
extensions=[YourCustomCommand])
element = driver.find_element_by_accessibility_id('id')
element = driver.find_elemeent(by=AppiumBy.ACCESSIBILITY_ID, value='id')

# Then, the driver calls a get request to `session/$sessionId/path/to/your/custom/$id/url`
# with replacing the `$id` with the given `element.id`
Expand Down
36 changes: 0 additions & 36 deletions docs/roadmap.md

This file was deleted.

3 changes: 2 additions & 1 deletion test/functional/android/chrome_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy

from .helper.desired_capabilities import get_desired_capabilities

Expand All @@ -28,6 +29,6 @@ def teardown_method(self) -> None:

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.driver.find_element(by=AppiumBy.LINK_TEXT, value='i am a link').click()

assert 'I am some other page content' in self.driver.page_source
6 changes: 3 additions & 3 deletions test/functional/android/common_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def test_open_notifications(self) -> None:
self.driver.open_notifications()
sleep(1)
with pytest.raises(NoSuchElementException):
self.driver.find_element_by_android_uiautomator, 'new UiSelector().text(":-|")'
self.driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value='new UiSelector().text(":-|")')

els = self.driver.find_elements_by_class_name('android.widget.TextView')
els = self.driver.find_element(by=AppiumBy.CLASS_NAME, value='android.widget.TextView')
# sometimes numbers shift
title = False
body = False
Expand All @@ -60,4 +60,4 @@ def test_open_notifications(self) -> None:

self.driver.keyevent(4)
sleep(1)
self.driver.find_element_by_android_uiautomator('new UiSelector().text(":-|")')
self.driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value='new UiSelector().text(":-|")')
7 changes: 4 additions & 3 deletions test/functional/android/context_switching_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from appium import webdriver
from appium.common.exceptions import NoSuchContextException
from appium.webdriver.common.appiumby import AppiumBy

from .helper import desired_capabilities

Expand All @@ -40,8 +41,8 @@ def test_move_to_correct_context(self) -> None:

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.driver.find_element(by=AppiumBy.CSS_SELECTOR, value='input[type=submit]').click()
el = self.driver.find_element(by=AppiumBy.XPATH, value="//h1[contains(., 'This is my way')]")
assert el is not None

def test_move_back_to_native_context(self) -> None:
Expand All @@ -54,6 +55,6 @@ def test_set_invalid_context(self) -> None:
self.driver.switch_to.context('invalid name')

def _enter_webview(self) -> None:
btn = self.driver.find_element_by_name('buttonStartWebviewCD')
btn = self.driver.find_element(by=AppiumBy.NAME, value='buttonStartWebviewCD')
btn.click()
self.driver.switch_to.context('WEBVIEW')
22 changes: 11 additions & 11 deletions test/functional/android/multi_action_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TestMultiAction(BaseTestCase):
def test_parallel_actions(self) -> None:
self._move_to_splitting_touches_accros_views()

els = self.driver.find_elements_by_class_name('android.widget.ListView')
els = self.driver.find_elements(by=AppiumBy.CLASS_NAME, value='android.widget.ListView')
a1 = TouchAction()
a1.press(els[0]).move_to(x=10, y=0).move_to(x=10, y=-75).move_to(x=10, y=-600).release()

Expand All @@ -42,7 +42,7 @@ def test_parallel_actions(self) -> None:
def test_actions_with_waits(self) -> None:
self._move_to_splitting_touches_accros_views()

els = self.driver.find_elements_by_class_name('android.widget.ListView')
els = self.driver.find_elements(by=AppiumBy.CLASS_NAME, value='android.widget.ListView')
a1 = TouchAction()
a1.press(els[0]).move_to(x=10, y=0).move_to(x=10, y=-75).wait(1000).move_to(x=10, y=-600).release()

Expand All @@ -54,40 +54,40 @@ def test_actions_with_waits(self) -> None:
ma.perform()

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')
el1 = self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='Content')
el2 = self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='Animation')
self.driver.scroll(el1, el2)

el = self.driver.find_element_by_accessibility_id('Views')
el = self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='Views')
action = TouchAction(self.driver)
action.tap(el).perform()

# simulate a swipe/scroll
el = wait_for_element(self.driver, AppiumBy.ACCESSIBILITY_ID, 'Expandable Lists')
action.press(el).move_to(x=100, y=-1000).release().perform()
el = self.driver.find_element_by_accessibility_id('Layouts')
el = self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='Layouts')
action.press(el).move_to(x=100, y=-1000).release().perform()

el = self.driver.find_element_by_accessibility_id('Splitting Touches across Views')
el = self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='Splitting Touches across Views')
action.tap(el).perform()

wait_for_element(self.driver, AppiumBy.ID, 'io.appium.android.apis:id/list1')

@pytest.mark.skipif(condition=is_ci(), reason='Skip since the test must be watched to check if it works')
def test_driver_multi_tap(self) -> None:
el = self.driver.find_element_by_accessibility_id('Graphics')
el = self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='Graphics')
action = TouchAction(self.driver)
action.tap(el).perform()

wait_for_element(self.driver, AppiumBy.CLASS_NAME, 'android.widget.TextView')
els = self.driver.find_elements_by_class_name('android.widget.TextView')
els = self.driver.find_elements(by=AppiumBy.CLASS_NAME, value='android.widget.TextView')
self.driver.scroll(els[len(els) - 1], els[0])

els = self.driver.find_elements_by_class_name('android.widget.TextView')
els = self.driver.find_elements(by=AppiumBy.CLASS_NAME, value='android.widget.TextView')
if els[len(els) - 1].get_attribute('name') != 'Xfermodes':
self.driver.scroll(els[len(els) - 1], els[0])

el = self.driver.find_element_by_accessibility_id('Touch Paint')
el = self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='Touch Paint')
action.tap(el).perform()

positions = [(100, 200), (100, 400)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import pytest

from appium.webdriver.common.appiumby import AppiumBy
from appium.webdriver.webelement import WebElement
from test.functional.android.helper.test_helper import BaseTestCase, is_ci
from test.functional.test_helper import wait_for_element

Expand All @@ -29,7 +30,7 @@ def test_find_single_element(self) -> None:
assert el is not None

def test_find_multiple_elements(self) -> None:
els = self.driver.find_elements_by_accessibility_id('Accessibility')
els = self.driver.find_elements(by=AppiumBy.ACCESSIBILITY_ID, value='Accessibility')
assert isinstance(els, list)

@pytest.mark.skipif(condition=is_ci(), reason='Need to fix flaky test during running on CI')
Expand All @@ -40,12 +41,11 @@ def test_element_find_single_element(self) -> None:
).click()
el = wait_for_element(self.driver, AppiumBy.CLASS_NAME, 'android.widget.ListView')

sub_el = el.find_element_by_accessibility_id('Task Take out Trash')
sub_el = el.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='Task Take out Trash') # type: WebElement
assert sub_el is not None

def test_element_find_multiple_elements(self) -> None:
wait_for_element(self.driver, AppiumBy.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')
el = self.driver.find_element(by=AppiumBy.CLASS_NAME, value='android.widget.ListView')
sub_els = el.find_elements(by=AppiumBy.ACCESSIBILITY_ID, value='Animation') # type: list
assert isinstance(sub_els, list)
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,41 @@

import pytest

from appium.webdriver.common.appiumby import AppiumBy
from appium.webdriver.webelement import WebElement
from test.functional.android.helper.test_helper import BaseTestCase


@pytest.mark.skip(reason="Need to fix flaky test")
class TestFindByUIAutomator(BaseTestCase):
def test_find_single_element(self) -> None:
el = self.driver.find_element_by_android_uiautomator('new UiSelector().text("Animation")')
el = self.driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value='new UiSelector().text("Animation")')
assert el is not None

def test_find_multiple_elements(self) -> None:
els = self.driver.find_elements_by_android_uiautomator('new UiSelector().clickable(true)')
els = self.driver.find_elements(by=AppiumBy.ANDROID_UIAUTOMATOR, value='new UiSelector().clickable(true)')
assert isinstance(els, list)

def test_element_find_single_element(self) -> None:
el = self.driver.find_element_by_class_name('android.widget.ListView')
el = self.driver.find_element(by=AppiumBy.CLASS_NAME, value='android.widget.ListView')

sub_el = el.find_element_by_android_uiautomator('new UiSelector().description("Animation")')
sub_el = el.find_element(
by=AppiumBy.ANDROID_UIAUTOMATOR, value='new UiSelector().description("Animation")'
) # type: WebElement
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')
el = self.driver.find_element(by=AppiumBy.CLASS_NAME, value='android.widget.ListView')

sub_els = el.find_elements_by_android_uiautomator('new UiSelector().clickable(true)')
sub_els = el.find_elements(
by=AppiumBy.ANDROID_UIAUTOMATOR, value='new UiSelector().clickable(true)'
) # type: 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 = self.driver.find_element(
by=AppiumBy.ANDROID_UIAUTOMATOR,
value='new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("Views").instance(0));',
)
el.click()
# TODO Add assert
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import unittest
import json

import pytest
from selenium.common.exceptions import WebDriverException
Expand All @@ -25,7 +24,6 @@


class TestFindByViewMatcher(BaseTestCase):

# Override
def setup_method(self, method) -> None: # type: ignore
desired_caps = desired_capabilities.get_desired_capabilities('ApiDemos-debug.apk.zip')
Expand All @@ -35,30 +33,39 @@ def setup_method(self, method) -> None: # type: ignore
self.driver.start_recording_screen()

def test_find_single_element(self) -> None:
el = self.driver.find_element_by_android_view_matcher(
name='withText', args=['Accessibility'], className='ViewMatchers'
el = self.driver.find_element(
by=AppiumBy.ANDROID_VIEW_MATCHER,
value=json.dumps({'name': 'withText', 'args': ['Accessibility'], 'class': 'ViewMatchers'}),
)
assert el.text == 'Accessibility'

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'
el = self.driver.find_element(
by=AppiumBy.ANDROID_VIEW_MATCHER,
value=json.dumps(
{'name': 'withText', 'args': ['Accessibility'], 'class': 'androidx.test.espresso.matcher.ViewMatchers'}
),
)
assert el.text == 'Accessibility'

def test_find_single_element_using_hamcrest_matcher(self) -> None:
el = self.driver.find_element_by_android_view_matcher(
name='withText',
args={'name': 'containsString', 'args': 'Animati', 'class': 'org.hamcrest.Matchers'},
className='ViewMatchers',
el = self.driver.find_element(
by=AppiumBy.ANDROID_VIEW_MATCHER,
value=json.dumps(
{
'name': 'withText',
'args': {'name': 'containsString', 'args': 'Animati', 'class': 'org.hamcrest.Matchers'},
'class': 'ViewMatchers',
}
),
)
assert el.text == 'Animation'

# androidx.test.espresso.AmbiguousViewMatcherException:
# 'with text: a string containing "Access"' matches multiple views in the hierarchy.
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=AppiumBy.ANDROID_VIEW_MATCHER, value=value)
self.driver.find_elements(
by=AppiumBy.ANDROID_VIEW_MATCHER,
value=json.dumps({'name': 'withSubstring', 'args': ['Access'], 'class': 'ViewMatchers'}),
)
Loading