forked from appium-boneyard/sample-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathios_simple.py
More file actions
70 lines (56 loc) · 2.21 KB
/
ios_simple.py
File metadata and controls
70 lines (56 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
Simple iOS tests, showing accessing elements and getting/setting text from them.
"""
import unittest
import os
from random import randint
from appium import webdriver
from time import sleep
class SimpleIOSTests(unittest.TestCase):
def setUp(self):
# set up appium
app = os.path.abspath('../../apps/TestApp/build/release-iphonesimulator/TestApp-iphonesimulator.app')
self.driver = webdriver.Remote(
command_executor='http://127.0.0.1:4723/wd/hub',
desired_capabilities={
'app': app,
'platformName': 'iOS',
'platformVersion': '10.1',
'deviceName': 'iPhone 6'
})
def tearDown(self):
self.driver.quit()
def _populate(self):
# populate text fields with two random numbers
els = [self.driver.find_element_by_accessibility_id('TextField1'),
self.driver.find_element_by_accessibility_id('TextField2')]
self._sum = 0
for i in range(2):
rnd = randint(0, 10)
els[i].send_keys(rnd)
self._sum += rnd
def test_ui_computation(self):
# populate text fields with values
self._populate()
# trigger computation by using the button
self.driver.find_element_by_accessibility_id('ComputeSumButton').click()
# is sum equal ?
# sauce does not handle class name, so get fourth element
sum = self.driver.find_element_by_accessibility_id('Answer').text
self.assertEqual(int(sum), self._sum)
def test_scroll(self):
els = self.driver.find_elements_by_class_name('XCUIElementTypeButton')
els[5].click()
sleep(1)
try:
el = self.driver.find_element_by_accessibility_id('Allow')
el.click()
sleep(1)
except:
pass
el = self.driver.find_element_by_xpath('//XCUIElementTypeMap[1]')
location = el.location
self.driver.swipe(start_x=location['x'], start_y=location['y'], end_x=0.5, end_y=location['y'], duration=800)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(SimpleIOSTests)
unittest.TextTestRunner(verbosity=2).run(suite)