|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import os |
| 16 | +from time import sleep |
| 17 | + |
| 18 | +from appium import webdriver |
| 19 | +from appium.common.exceptions import NoSuchContextException |
| 20 | + |
| 21 | +import unittest |
| 22 | + |
| 23 | +# Returns abs path relative to this file and not cwd |
| 24 | +PATH = lambda p: os.path.abspath( |
| 25 | + os.path.join(os.path.dirname(__file__), p) |
| 26 | +) |
| 27 | + |
| 28 | +class FindByUIAutomatorTests(unittest.TestCase): |
| 29 | + def setUp(self): |
| 30 | + desired_caps = {} |
| 31 | + desired_caps['device'] = 'Android' |
| 32 | + desired_caps['browserName'] = '' |
| 33 | + desired_caps['version'] = '4.2' |
| 34 | + desired_caps['app'] = PATH('../../apps/ApiDemos-debug.apk') |
| 35 | + desired_caps['app-package'] = 'com.example.android.apis' |
| 36 | + desired_caps['app-activity'] = '.ApiDemos' |
| 37 | + |
| 38 | + self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) |
| 39 | + |
| 40 | + def tearDown(self): |
| 41 | + self.driver.quit() |
| 42 | + |
| 43 | + def test_find_single_element(self): |
| 44 | + el = self.driver.find_element_by_android_uiautomator('new UiSelector().description("Animation")') |
| 45 | + self.assertIsNotNone(el) |
| 46 | + |
| 47 | + def test_find_multiple_elements(self): |
| 48 | + els = self.driver.find_elements_by_android_uiautomator('new UiSelector().clickable(true)') |
| 49 | + self.assertTrue(len(els) > 11) |
| 50 | + |
| 51 | +if __name__ == "__main__": |
| 52 | + unittest.main() |
0 commit comments