|
| 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 | + |
| 21 | +class FindByIOSPredicateTests(unittest.TestCase): |
| 22 | + @classmethod |
| 23 | + def setUpClass(self): |
| 24 | + desired_caps = desired_capabilities.get_desired_capabilities('UICatalog.app.zip') |
| 25 | + self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) |
| 26 | + |
| 27 | + @classmethod |
| 28 | + def tearDownClass(self): |
| 29 | + self.driver.quit() |
| 30 | + |
| 31 | + def test_find_element_by_name(self): |
| 32 | + # Will throw exception if element is not found |
| 33 | + self.driver.find_element_by_ios_predicate('wdName == "Buttons"') |
| 34 | + |
| 35 | + def test_find_multiple_element_by_type(self): |
| 36 | + e = self.driver.find_elements_by_ios_predicate('wdType == "XCUIElementTypeStaticText"') |
| 37 | + self.assertNotEqual(len(e), 0) |
| 38 | + |
| 39 | + def test_find_element_by_label(self): |
| 40 | + # Will throw exception if element is not found |
| 41 | + self.driver.find_element_by_ios_predicate('label == "TextFields"') |
| 42 | + |
| 43 | + def test_find_element_by_value(self): |
| 44 | + # Will throw exception if element is not found |
| 45 | + self.driver.find_element_by_ios_predicate('wdValue == "Controls"') |
| 46 | + |
| 47 | + def test_find_element_by_isvisible(self): |
| 48 | + # Will throw exception if element is not found |
| 49 | + self.driver.find_element_by_ios_predicate('wdValue == "SearchBar" AND isWDVisible == 1') |
| 50 | + |
| 51 | + # Should not find any elements |
| 52 | + e = self.driver.find_elements_by_ios_predicate('wdValue == "SearchBar" AND isWDVisible == 0') |
| 53 | + self.assertEqual(len(e), 0) |
| 54 | + |
| 55 | + def test_find_element_by_isenabled(self): |
| 56 | + # Will throw exception if element is not found |
| 57 | + self.driver.find_element_by_ios_predicate('wdValue == "SearchBar" AND isWDEnabled == 1') |
| 58 | + |
| 59 | + # Should not find any elements |
| 60 | + e = self.driver.find_elements_by_ios_predicate('wdValue == "SearchBar" AND isWDEnabled == 0') |
| 61 | + self.assertEqual(len(e), 0) |
| 62 | + |
| 63 | + |
| 64 | +if __name__ == "__main__": |
| 65 | + suite = unittest.TestLoader().loadTestsFromTestCase(FindByIOSPredicateTests) |
| 66 | + unittest.TextTestRunner(verbosity=2).run(suite) |
0 commit comments