Skip to content

Commit

Permalink
ci: use gha instead of Azure for iOS in Azure (appium#987)
Browse files Browse the repository at this point in the history
ci: use gha instead of Azure for iOS in Azure
  • Loading branch information
KazuCocoa authored May 7, 2024
1 parent 67a561d commit 5442e60
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 40 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/functional-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ jobs:
fail-fast: false
matrix:
test_targets:
- target: search_context/find_by_*.py remote_fs_tests.py safari_tests.py execute_driver_tests.py
- target: test/functional/ios/search_context/find_by_*.py test/functional/ios/remote_fs_tests.py test/functional/ios/safari_tests.py test/functional/ios/execute_driver_tests.py
name: func_test_ios1
- target: test/functional/ios/applications_tests.py test/functional/ios/hw_actions_tests.py test/functional/ios/keyboard_tests.py
name: func_test_ios2
- target: test/functional/ios/screen_record_tests.py test/functional/ios/webdriver_tests.py
name: func_test_ios3

runs-on: macos-14

Expand All @@ -43,21 +47,29 @@ jobs:
model: 'iPhone 15 Plus'
os_version: '17.4'

# needed?
- run: brew install ffmpeg

# Start Appium
- run: npm install -g appium
- run: |
appium driver install xcuitest
appium plugin install images
appium plugin install execute-driver
nohup appium --use-plugins=images,execute-driver --relaxed-security --log-timestamp --log-no-colors --base-path=/wd/hub > appium.log &
nohup appium --use-plugins=images,execute-driver --relaxed-security --log-timestamp --log-no-colors > appium.log &
- name: Set up Python 3.9
uses: actions/setup-python@v3
with:
python-version: 3.9

- run: python -m pytest ${{ test_targets.target}} --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
working-directory: test/functional/ios
- run: |
# Separate 'run' creates differnet pipenv env. Does them in one run for now.
pip install --upgrade pip
pip install --upgrade pipenv
pipenv lock --clear
pipenv install -d --system
pytest ${{ matrix.test_targets.target}} --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
- name: Save server output
if: ${{ always() }}
Expand Down
16 changes: 0 additions & 16 deletions ci-jobs/functional_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,6 @@ parameters:
CI: true

jobs:
- template: ./functional/run_ios_test.yml
parameters:
name: 'func_test_ios1'
vmImage: ${{ parameters.vmImage }}
pytestOpt: ${{ parameters.pytestOpt }}
testFiles: 'search_context/find_by_*.py remote_fs_tests.py safari_tests.py execute_driver_tests.py'
CI: ${{ parameters.ci }}
xcodeForIOS: ${{ parameters.xcodeForIOS }}
- template: ./functional/run_ios_test.yml
parameters:
name: 'func_test_ios2'
vmImage: ${{ parameters.vmImage }}
pytestOpt: ${{ parameters.pytestOpt }}
testFiles: 'applications_tests.py hw_actions_tests.py keyboard_tests.py screen_record_tests.py webdriver_tests.py'
CI: ${{ parameters.ci }}
xcodeForIOS: ${{ parameters.xcodeForIOS }}
- template: ./functional/run_android_test.yml
parameters:
name: 'func_test_android1'
Expand Down
Binary file modified test/apps/UICatalog.app.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions test/functional/ios/helper/desired_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_desired_capabilities(app: Optional[str] = None) -> Dict[str, Any]:
desired_caps: Dict[str, Any] = {
'deviceName': iphone_device_name(),
'platformName': 'iOS',
'platformVersion': '15.5',
'platformVersion': '17.4',
'automationName': 'XCUITest',
'allowTouchIdEnroll': True,
'wdaLocalPort': wda_port(),
Expand Down Expand Up @@ -70,7 +70,7 @@ def wda_port() -> int:


def iphone_device_name() -> str:
prefix = 'iPhone 12'
prefix = 'iPhone 15 Plus'
if PytestXdistWorker.NUMBER == PytestXdistWorker.gw(0):
return f'{prefix} - 8100'
elif PytestXdistWorker.NUMBER == PytestXdistWorker.gw(1):
Expand Down
2 changes: 2 additions & 0 deletions test/functional/ios/helper/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@


class BaseTestCase(object):
IOS_UICATALOG_APP_NAME = 'UIKitCatalog'

def setup_method(self) -> None:
desired_caps = desired_capabilities.get_desired_capabilities('UICatalog.app.zip')
self.driver = webdriver.Remote(SERVER_URL_BASE, options=XCUITestOptions().load_capabilities(desired_caps))
Expand Down
32 changes: 29 additions & 3 deletions test/functional/ios/safari_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,44 @@
class TestSafari:
def setup_method(self) -> None:
caps = get_desired_capabilities()
caps.update({'browserName': 'safari', 'nativeWebTap': True, 'safariIgnoreFraudWarning': True})
caps.update(
{
'bundleId': 'com.apple.mobilesafari',
'nativeWebTap': True,
'safariIgnoreFraudWarning': True,
'webviewConnectTimeout': 100000,
}
)
self.driver = webdriver.Remote(SERVER_URL_BASE, options=AppiumOptions().load_capabilities(caps))

# Fresh iOS 17.4 simulator may not show up the webview context with "safari"
# after a fresh simlator instance creation.
# Re-launch the process could be a workaround in my debugging.
self.driver.terminate_app('com.apple.mobilesafari')
self.driver.activate_app('com.apple.mobilesafari')

def teardown_method(self) -> None:
self.driver.quit()

def test_context(self) -> None:
assert 'NATIVE_APP' == self.driver.contexts[0]
assert self.driver.contexts[1].startswith('WEBVIEW_')
contexts = self.driver.contexts
assert 'NATIVE_APP' == contexts[0]
assert contexts[1].startswith('WEBVIEW_')
self.driver.switch_to.context(contexts[1])
assert 'WEBVIEW_' in self.driver.current_context

def test_get(self) -> None:
ok = False
contexts = self.driver.contexts
for context in contexts:
if context.startswith('WEBVIEW_'):
self.driver.switch_to.context(context)
ok = True
break

if ok is False:
assert False, 'Could not set WEBVIEW context'

self.driver.get('http://google.com')
for _ in range(5):
time.sleep(0.5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

class TestFindByElementWebelement(BaseTestCase):
def test_find_element_by_path(self) -> None:
el = self.driver.find_element(by=AppiumBy.IOS_PREDICATE, value='wdName == "UICatalog"')
assert 'UICatalog' == el.get_attribute('name')
el = self.driver.find_element(by=AppiumBy.IOS_PREDICATE, value='wdName == "UIKitCatalog"')
assert self.IOS_UICATALOG_APP_NAME == el.get_attribute('name')

c_el = el.find_elements(by=AppiumBy.IOS_PREDICATE, value='label == "Action Sheets"') # type: list
assert 'Action Sheets' == c_el[0].get_attribute('name')
c_el = el.find_elements(by=AppiumBy.IOS_PREDICATE, value='label == "UIKitCatalog"') # type: list
assert self.IOS_UICATALOG_APP_NAME == c_el[0].get_attribute('name')

c_el = el.find_elements(by=AppiumBy.IOS_CLASS_CHAIN, value='**/XCUIElementTypeStaticText')
assert 'UICatalog' == c_el[0].get_attribute('name')
assert self.IOS_UICATALOG_APP_NAME == c_el[0].get_attribute('name')

c_el = el.find_elements(by=AppiumBy.ACCESSIBILITY_ID, value='UICatalog')
assert 'UICatalog' == c_el[0].get_attribute('name')
c_el = el.find_elements(by=AppiumBy.ACCESSIBILITY_ID, value='UIKitCatalog')
assert self.IOS_UICATALOG_APP_NAME == c_el[0].get_attribute('name')
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@

class TestFindByIOClassChain(BaseTestCase):
def test_find_element_by_path(self) -> None:
el = self.driver.find_element(by=AppiumBy.IOS_CLASS_CHAIN, value='**/XCUIElementTypeNavigationBar')
assert self.IOS_UICATALOG_APP_NAME == el.get_attribute('name')

def test_find_multiple_elements_by_path(self) -> None:
els = self.driver.find_elements(
by=AppiumBy.IOS_CLASS_CHAIN, value='XCUIElementTypeWindow/**/XCUIElementTypeStaticText'
)
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=AppiumBy.IOS_CLASS_CHAIN, value='XCUIElementTypeWindow/*/*/*')
assert 2 == len(el)
assert 'UICatalog' == el[0].get_attribute('name')
assert el[1].get_attribute('name') is None
assert 37 == len(els)
assert self.IOS_UICATALOG_APP_NAME == els[0].get_attribute('name')

0 comments on commit 5442e60

Please sign in to comment.