Skip to content

Commit db79041

Browse files
committed
Added test cases for clear and find elements by ios predicate string.
1 parent c5a0043 commit db79041

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

test/functional/ios/appium_tests.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,26 @@ def test_hide_keyboard_no_key_name(self):
9696
# currently fails.
9797
self.assertFalse(el.is_displayed())
9898

99+
def test_clear(self):
100+
# Click text fields
101+
self.driver.find_element_by_accessibility_id('TextFields').click()
102+
103+
# Verify default text
104+
def_text = '<enter text>'
105+
text = self.driver.find_element_by_accessibility_id('Normal').get_attribute('value')
106+
self.assertEqual(text, def_text)
107+
108+
# Input some text, verify
109+
input_text = 'blah'
110+
self.driver.find_element_by_accessibility_id('Normal').send_keys(input_text)
111+
text = self.driver.find_element_by_accessibility_id('Normal').get_attribute('value')
112+
self.assertEqual(text, input_text)
113+
114+
# Clear text, verify
115+
self.driver.find_element_by_accessibility_id('Normal').clear()
116+
text = self.driver.find_element_by_accessibility_id('Normal').get_attribute('value')
117+
self.assertEqual(text, def_text)
118+
99119

100120
if __name__ == "__main__":
101121
suite = unittest.TestLoader().loadTestsFromTestCase(AppiumTests)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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

Comments
 (0)