Skip to content

Commit 560e959

Browse files
authored
Divide functional appium tests into each module(android) (appium#378)
* Move non test files * Divide appium_tests into each module tests(android) * Skip contexts, find_by_image tests * Removed unnecessary codes
1 parent 6f6b26d commit 560e959

27 files changed

Lines changed: 541 additions & 279 deletions
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import unittest
17+
18+
from appium import webdriver
19+
20+
from helper import desired_capabilities
21+
22+
23+
class ActivitiesTests(unittest.TestCase):
24+
def setUp(self):
25+
desired_caps = desired_capabilities.get_desired_capabilities('ApiDemos-debug.apk')
26+
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
27+
28+
def tearDown(self):
29+
self.driver.quit()
30+
31+
def test_current_activity(self):
32+
activity = self.driver.current_activity
33+
self.assertEqual('.ApiDemos', activity)
34+
35+
def test_start_activity_this_app(self):
36+
self.driver.start_activity("com.example.android.apis", ".ApiDemos")
37+
self._assert_activity_contains('Demos')
38+
39+
self.driver.start_activity("com.example.android.apis", ".accessibility.AccessibilityNodeProviderActivity")
40+
self._assert_activity_contains('Node')
41+
42+
def test_start_activity_other_app(self):
43+
self.driver.start_activity("com.example.android.apis", ".ApiDemos")
44+
self._assert_activity_contains('Demos')
45+
46+
self.driver.start_activity("com.android.calculator2", ".Calculator")
47+
self._assert_activity_contains('Calculator')
48+
49+
def _assert_activity_contains(self, activity):
50+
current = self.driver.current_activity
51+
self.assertTrue(activity in current)
52+
53+
54+
if __name__ == '__main__':
55+
suite = unittest.TestLoader().loadTestsFromTestCase(ActivitiesTests)
56+
unittest.TextTestRunner(verbosity=2).run(suite)

test/functional/android/appium_tests.py

Lines changed: 0 additions & 226 deletions
This file was deleted.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import unittest
17+
from time import sleep
18+
19+
from appium import webdriver
20+
from appium.webdriver.applicationstate import ApplicationState
21+
22+
from helper import desired_capabilities
23+
24+
25+
class ApplicationsTests(unittest.TestCase):
26+
def setUp(self):
27+
desired_caps = desired_capabilities.get_desired_capabilities('ApiDemos-debug.apk')
28+
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
29+
30+
def tearDown(self):
31+
self.driver.quit()
32+
33+
def test_background_app(self):
34+
self.driver.background_app(1)
35+
sleep(3)
36+
self.driver.launch_app()
37+
38+
def test_is_app_installed(self):
39+
self.assertFalse(self.driver.is_app_installed('sdfsdf'))
40+
self.assertTrue(self.driver.is_app_installed('com.example.android.apis'))
41+
42+
def test_install_app(self):
43+
self.skipTest('This causes the server to crash. no idea why')
44+
self.assertFalse(self.driver.is_app_installed('io.selendroid.testapp'))
45+
self.driver.install_app('/Users/isaac/code/python-client/test/apps/selendroid-test-app.apk')
46+
self.assertTrue(self.driver.is_app_installed('io.selendroid.testapp'))
47+
48+
def test_remove_app(self):
49+
self.assertTrue(self.driver.is_app_installed('com.example.android.apis'))
50+
self.driver.remove_app('com.example.android.apis')
51+
self.assertFalse(self.driver.is_app_installed('com.example.android.apis'))
52+
53+
def test_close_and_launch_app(self):
54+
self.driver.close_app()
55+
self.driver.launch_app()
56+
activity = self.driver.current_activity
57+
self.assertEqual('.ApiDemos', activity)
58+
59+
def test_app_management(self):
60+
app_id = self.driver.current_package
61+
self.assertEqual(self.driver.query_app_state(app_id),
62+
ApplicationState.RUNNING_IN_FOREGROUND)
63+
self.driver.background_app(-1)
64+
self.assertTrue(self.driver.query_app_state(app_id) <
65+
ApplicationState.RUNNING_IN_FOREGROUND)
66+
self.driver.activate_app(app_id)
67+
self.assertEqual(self.driver.query_app_state(app_id),
68+
ApplicationState.RUNNING_IN_FOREGROUND)
69+
70+
def test_app_strings(self):
71+
strings = self.driver.app_strings()
72+
self.assertEqual(u'You can\'t wipe my data, you are a monkey!', strings[u'monkey_wipe_data'])
73+
74+
def test_app_strings_with_language(self):
75+
strings = self.driver.app_strings('en')
76+
self.assertEqual(u'You can\'t wipe my data, you are a monkey!', strings[u'monkey_wipe_data'])
77+
78+
def test_app_strings_with_language_and_file(self):
79+
strings = self.driver.app_strings('en', 'some_file')
80+
self.assertEqual(u'You can\'t wipe my data, you are a monkey!', strings[u'monkey_wipe_data'])
81+
82+
83+
if __name__ == '__main__':
84+
suite = unittest.TestLoader().loadTestsFromTestCase(ApplicationsTests)
85+
unittest.TextTestRunner(verbosity=2).run(suite)

test/functional/android/chrome_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ChromeTests(unittest.TestCase):
2121
def setUp(self):
2222
desired_caps = {
2323
'platformName': 'Android',
24-
'platformVersion': '4.2',
24+
'platformVersion': '9',
2525
'deviceName': 'Android Emulator',
2626
'browserName': 'Chrome'
2727
}

test/functional/android/context_switching_tests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import pytest
1516
import unittest
1617

1718
from appium import webdriver
1819
from appium.common.exceptions import NoSuchContextException
19-
import desired_capabilities
20+
from helper import desired_capabilities
2021

2122

23+
@pytest.mark.skip(reason="Need to fix broken test")
2224
class ContextSwitchingTests(unittest.TestCase):
2325
def setUp(self):
2426
desired_caps = desired_capabilities.get_desired_capabilities('selendroid-test-app.apk')

0 commit comments

Comments
 (0)