mirror of
https://github.com/appium/appium.git
synced 2026-01-14 06:10:01 -06:00
* add initial python sample
* add all of ios and android tests
* apply formatter
* add >=0.28 to avoid version error
* tweak versions of default OS
* convert some tests to unittest based ones
* use single quote mainly
* use {} format style for string
* use format syntax
* apply format and tweak assertions
* use is None
* use assert raise
* speficy a number of elements
* tweak exception
* move app path to helper
* tweak assertion conditions
* remove .close since with open() close file automatically
65 lines
2.3 KiB
Python
65 lines
2.3 KiB
Python
import pytest
|
|
import os
|
|
import textwrap
|
|
|
|
from appium import webdriver
|
|
from helpers import take_screenhot_and_logcat, ANDROID_APP_PATH, EXECUTOR
|
|
|
|
|
|
class TestAndroidBasicInteractions():
|
|
PACKAGE = 'io.appium.android.apis'
|
|
SEARCH_ACTIVITY = '.app.SearchInvoke'
|
|
ALERT_DIALOG_ACTIVITY = '.app.AlertDialogSamples'
|
|
|
|
@pytest.fixture(scope='function')
|
|
def driver(self, request, device_logger):
|
|
calling_request = request._pyfuncitem.name
|
|
driver = webdriver.Remote(
|
|
command_executor=EXECUTOR,
|
|
desired_capabilities={
|
|
'app': ANDROID_APP_PATH,
|
|
'platformName': 'Android',
|
|
'automationName': 'UIAutomator2',
|
|
'platformVersion': os.getenv('ANDROID_PLATFORM_VERSION') or '7.1',
|
|
'deviceName': os.getenv('ANDROID_DEVICE_VERSION') or 'Android',
|
|
'appActivity': self.SEARCH_ACTIVITY
|
|
}
|
|
)
|
|
|
|
def fin():
|
|
take_screenhot_and_logcat(driver, device_logger, calling_request)
|
|
driver.quit()
|
|
|
|
request.addfinalizer(fin)
|
|
|
|
driver.implicitly_wait(10)
|
|
return driver
|
|
|
|
def test_should_send_keys_to_search_box_and_then_check_the_value(self, driver):
|
|
search_box_element = driver.find_element_by_id('txt_query_prefill')
|
|
search_box_element.send_keys('Hello world!')
|
|
|
|
on_search_requested_button = driver.find_element_by_id('btn_start_search')
|
|
on_search_requested_button.click()
|
|
|
|
search_text = driver.find_element_by_id('android:id/search_src_text')
|
|
search_text_value = search_text.text
|
|
|
|
assert 'Hello world!' == search_text_value
|
|
|
|
def test_should_click_a_button_that_opens_an_alert_and_then_dismisses_it(self, driver):
|
|
driver.start_activity(self.PACKAGE, self.ALERT_DIALOG_ACTIVITY)
|
|
|
|
open_dialog_button = driver.find_element_by_id('io.appium.android.apis:id/two_buttons')
|
|
open_dialog_button.click()
|
|
|
|
alert_element = driver.find_element_by_id('android:id/alertTitle')
|
|
alert_text = alert_element.text
|
|
|
|
assert textwrap.dedent('''\
|
|
Lorem ipsum dolor sit aie consectetur adipiscing
|
|
Plloaso mako nuto siwuf cakso dodtos anr koop.''') == alert_text
|
|
|
|
close_dialog_button = driver.find_element_by_id('android:id/button1')
|
|
close_dialog_button.click()
|