|
| 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) |
0 commit comments