|
| 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 unittest |
| 16 | + |
| 17 | +from appium import webdriver |
| 18 | +import desired_capabilities |
| 19 | + |
| 20 | +class FindByIOClassChainTests(unittest.TestCase): |
| 21 | + @classmethod |
| 22 | + def setUpClass(self): |
| 23 | + desired_caps = desired_capabilities.get_desired_capabilities('UICatalog.app.zip') |
| 24 | + self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) |
| 25 | + |
| 26 | + @classmethod |
| 27 | + def tearDownClass(self): |
| 28 | + self.driver.quit() |
| 29 | + |
| 30 | + def test_find_element_by_path(self): |
| 31 | + el = self.driver.find_element_by_ios_class_chain('XCUIElementTypeWindow/*/*/XCUIElementTypeStaticText') |
| 32 | + self.assertEqual('UICatalog', el.get_attribute('name')) |
| 33 | + |
| 34 | + def test_find_multiple_elements_by_path(self): |
| 35 | + el = self.driver.find_elements_by_ios_class_chain('XCUIElementTypeWindow/*/*') |
| 36 | + self.assertEqual(len(el), 2) |
| 37 | + self.assertEqual('UICatalog', el[0].get_attribute('name')) |
| 38 | + self.assertEqual(None, el[1].get_attribute('name')) |
| 39 | + |
| 40 | +if __name__ == "__main__": |
| 41 | + suite = unittest.TestLoader().loadTestsFromTestCase(FindByIOClassChainTests) |
| 42 | + unittest.TextTestRunner(verbosity=2).run(suite) |
0 commit comments