Skip to content

Commit 3f90a6f

Browse files
authored
Replace apk for functional test (appium#470)
* Replace apk for functional test https://github.com/appium/android-apidemos/releases/tag/v3.1.0 * Use sdkVer 27 * Update app package name * Fix: can't find android device * review comments * tweak
1 parent b797254 commit 3f90a6f

14 files changed

Lines changed: 56 additions & 44 deletions

ci-jobs/functional_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
parameters:
22
vmImage: 'macOS-10.14'
33
pytestOpt: '--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html'
4-
androidSdkVer: 28
4+
androidSdkVer: 27
55
xcodeForIOS: 10.3
66
CI: true
77

test/apps/ApiDemos-debug.apk

-2.94 MB
Binary file not shown.

test/apps/ApiDemos-debug.apk.zip

3.36 MB
Binary file not shown.

test/functional/android/activities_tests.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import unittest
1717

18-
from .helper.test_helper import BaseTestCase
18+
from .helper.test_helper import APIDEMO_PKG_NAME, BaseTestCase
1919

2020

2121
class ActivitiesTests(BaseTestCase):
@@ -24,14 +24,14 @@ def test_current_activity(self):
2424
self.assertEqual('.ApiDemos', activity)
2525

2626
def test_start_activity_this_app(self):
27-
self.driver.start_activity("com.example.android.apis", ".ApiDemos")
27+
self.driver.start_activity(APIDEMO_PKG_NAME, ".ApiDemos")
2828
self._assert_activity_contains('Demos')
2929

30-
self.driver.start_activity("com.example.android.apis", ".accessibility.AccessibilityNodeProviderActivity")
30+
self.driver.start_activity(APIDEMO_PKG_NAME, ".accessibility.AccessibilityNodeProviderActivity")
3131
self._assert_activity_contains('Node')
3232

3333
def test_start_activity_other_app(self):
34-
self.driver.start_activity("com.example.android.apis", ".ApiDemos")
34+
self.driver.start_activity(APIDEMO_PKG_NAME, ".ApiDemos")
3535
self._assert_activity_contains('Demos')
3636

3737
self.driver.start_activity("com.android.calculator2", ".Calculator")

test/functional/android/applications_tests.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from appium.webdriver.applicationstate import ApplicationState
2020

21-
from .helper.test_helper import BaseTestCase
21+
from .helper.test_helper import APIDEMO_PKG_NAME, BaseTestCase
2222

2323

2424
class ApplicationsTests(BaseTestCase):
@@ -30,7 +30,7 @@ def test_background_app(self):
3030

3131
def test_is_app_installed(self):
3232
self.assertFalse(self.driver.is_app_installed('sdfsdf'))
33-
self.assertTrue(self.driver.is_app_installed('com.example.android.apis'))
33+
self.assertTrue(self.driver.is_app_installed(APIDEMO_PKG_NAME))
3434

3535
def test_install_app(self):
3636
self.skipTest('This causes the server to crash. no idea why')
@@ -39,9 +39,9 @@ def test_install_app(self):
3939
self.assertTrue(self.driver.is_app_installed('io.selendroid.testapp'))
4040

4141
def test_remove_app(self):
42-
self.assertTrue(self.driver.is_app_installed('com.example.android.apis'))
43-
self.driver.remove_app('com.example.android.apis')
44-
self.assertFalse(self.driver.is_app_installed('com.example.android.apis'))
42+
self.assertTrue(self.driver.is_app_installed(APIDEMO_PKG_NAME))
43+
self.driver.remove_app(APIDEMO_PKG_NAME)
44+
self.assertFalse(self.driver.is_app_installed(APIDEMO_PKG_NAME))
4545

4646
def test_close_and_launch_app(self):
4747
self.driver.close_app()
@@ -74,7 +74,7 @@ def test_app_strings_with_language_and_file(self):
7474

7575
def test_reset(self):
7676
self.driver.reset()
77-
self.assertTrue(self.driver.is_app_installed('com.example.android.apis'))
77+
self.assertTrue(self.driver.is_app_installed(APIDEMO_PKG_NAME))
7878

7979

8080
if __name__ == '__main__':

test/functional/android/chrome_tests.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,14 @@
1616

1717
from appium import webdriver
1818

19+
from .helper.desired_capabilities import get_desired_capabilities
20+
1921

2022
class ChromeTests(unittest.TestCase):
2123
def setUp(self):
22-
desired_caps = {
23-
'platformName': 'Android',
24-
'platformVersion': '9',
25-
'deviceName': 'Android Emulator',
26-
'browserName': 'Chrome',
27-
'uiautomator2ServerInstallTimeout': 120000,
28-
'adbExecTimeout': 120000
29-
}
30-
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
24+
caps = get_desired_capabilities()
25+
caps['browserName'] = 'Chrome'
26+
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', caps)
3127

3228
def tearDown(self):
3329
self.driver.quit()

test/functional/android/common_tests.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@
2121
from appium.webdriver.common.mobileby import MobileBy
2222

2323
from ..test_helper import is_ci
24-
from .helper.test_helper import BaseTestCase, wait_for_element
24+
from .helper.test_helper import (
25+
APIDEMO_PKG_NAME,
26+
BaseTestCase,
27+
wait_for_element
28+
)
2529

2630

2731
class CommonTests(BaseTestCase):
2832

2933
def test_current_package(self):
30-
package = self.driver.current_package
31-
self.assertEqual('com.example.android.apis', package)
34+
self.assertEqual(APIDEMO_PKG_NAME, self.driver.current_package)
3235

3336
def test_end_test_coverage(self):
3437
self.skipTest('Not sure how to set this up to run')

test/functional/android/helper/desired_capabilities.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ def PATH(p):
2222
)
2323

2424

25-
def get_desired_capabilities(app):
25+
def get_desired_capabilities(app=None):
2626
desired_caps = {
2727
'platformName': 'Android',
2828
'deviceName': 'Android Emulator',
29-
'app': PATH('../../apps/{}'.format(app)),
3029
'newCommandTimeout': 240,
3130
'automationName': 'UIAutomator2',
3231
'uiautomator2ServerInstallTimeout': 120000,
3332
'adbExecTimeout': 120000
3433
}
3534

35+
if app is not None:
36+
desired_caps['app'] = PATH(os.path.join('../..', 'apps', app))
37+
3638
return desired_caps

test/functional/android/helper/test_helper.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
# the emulator is sometimes slow and needs time to think
2828
SLEEPY_TIME = 10
2929

30+
# The package name of ApiDemos-debug.apk.zip
31+
APIDEMO_PKG_NAME = 'io.appium.android.apis'
32+
3033

3134
def wait_for_element(driver, locator, value, timeout=SLEEPY_TIME):
3235
"""Wait until the element located
@@ -52,7 +55,7 @@ def wait_for_element(driver, locator, value, timeout=SLEEPY_TIME):
5255
class BaseTestCase(unittest.TestCase):
5356

5457
def setUp(self):
55-
desired_caps = desired_capabilities.get_desired_capabilities('ApiDemos-debug.apk')
58+
desired_caps = desired_capabilities.get_desired_capabilities('ApiDemos-debug.apk.zip')
5659
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
5760

5861
def tearDown(self):

test/functional/android/touch_action_tests.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
from appium.webdriver.common.mobileby import MobileBy
2020
from appium.webdriver.common.touch_action import TouchAction
2121

22-
from .helper.test_helper import BaseTestCase, wait_for_element
22+
from .helper.test_helper import (
23+
APIDEMO_PKG_NAME,
24+
BaseTestCase,
25+
wait_for_element
26+
)
2327

2428

2529
class TouchActionTests(BaseTestCase):
@@ -175,13 +179,13 @@ def test_drag_and_drop(self):
175179
el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Drag and Drop')
176180
action.tap(el).perform()
177181

178-
dd3 = wait_for_element(self.driver, MobileBy.ID, 'com.example.android.apis:id/drag_dot_3')
179-
dd2 = self.driver.find_element_by_id('com.example.android.apis:id/drag_dot_2')
182+
dd3 = wait_for_element(self.driver, MobileBy.ID, '{}:id/drag_dot_3'.format(APIDEMO_PKG_NAME))
183+
dd2 = self.driver.find_element_by_id('{}:id/drag_dot_2'.format(APIDEMO_PKG_NAME))
180184

181185
# dnd is stimulated by longpress-move_to-release
182186
action.long_press(dd3).move_to(dd2).release().perform()
183187

184-
el = wait_for_element(self.driver, MobileBy.ID, 'com.example.android.apis:id/drag_text')
188+
el = wait_for_element(self.driver, MobileBy.ID, '{}:id/drag_text'.format(APIDEMO_PKG_NAME))
185189
self.assertTrue('drag_dot_3' in el.text)
186190

187191
def test_driver_drag_and_drop(self):
@@ -196,12 +200,12 @@ def test_driver_drag_and_drop(self):
196200
el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Drag and Drop')
197201
action.tap(el).perform()
198202

199-
dd3 = wait_for_element(self.driver, MobileBy.ID, 'com.example.android.apis:id/drag_dot_3')
200-
dd2 = self.driver.find_element_by_id('com.example.android.apis:id/drag_dot_2')
203+
dd3 = wait_for_element(self.driver, MobileBy.ID, '{}:id/drag_dot_3'.format(APIDEMO_PKG_NAME))
204+
dd2 = self.driver.find_element_by_id('{}:id/drag_dot_2'.format(APIDEMO_PKG_NAME))
201205

202206
self.driver.drag_and_drop(dd3, dd2)
203207

204-
el = wait_for_element(self.driver, MobileBy.ID, 'com.example.android.apis:id/drag_text')
208+
el = wait_for_element(self.driver, MobileBy.ID, '{}:id/drag_text'.format(APIDEMO_PKG_NAME))
205209
self.assertTrue('drag_dot_3' in el.text)
206210

207211
def test_driver_swipe(self):

0 commit comments

Comments
 (0)