/
test_session.py
120 lines (98 loc) · 3.39 KB
/
test_session.py
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# coding: utf-8
import pytest
from pytest import mark
import time
import wda
c = wda.Client()
def setup_function():
wda.DEBUG = True
c.home()
def teardown_function():
pass
@mark.skip("no test enviroment")
def test_session_open_url():
""" TODO: do not know how to use this api """
pass
def test_session_deactivate():
with c.session('com.apple.mobilesafari') as s:
s.deactivate(3.0)
assert s(name='Share').wait(2.0, raise_error=False)
def test_session_just_tap():
s = c.session()
x, y = s(name='Settings').bounds.center
s.tap(x, y)
assert s(name='Bluetooth').wait(2.0, raise_error=False)
c.home()
@mark.skip("not finished")
def test_session_double_tap():
s = c.session()
x, y = s(name='Settings').bounds.center
s.double_tap(x, y)
def test_session_tap_hold():
s = c.session()
x, y = s(name='Settings').bounds.center
s.tap_hold(x, y, 2.0)
s(name="DeleteButton").wait(2.0, raise_error=False)
c.home()
def test_session_swipe():
s = c.session()
s.swipe_left()
assert not s(name="Settings").displayed
s.swipe_right()
assert s(name="Settings").displayed
s.swipe_up()
assert s(name="Airplane Mode").wait(2.0, raise_error=False)
s.swipe_down()
assert s(name="Airplane Mode").wait_gone(2.0, raise_error=False)
def test_session_set_text():
with c.session('com.apple.mobilesafari') as s:
s(name='URL', className='Button').set_text("status.github.com")
url = s(name='URL', className='TextField').get()
assert url.value == 'status.github.com'
def test_session_window_size():
s = c.session()
wsize = s.window_size()
assert wsize.width == 320
assert wsize.height == 568
def test_session_send_keys():
with c.session('com.apple.mobilesafari') as s:
u = s(label='Address', className='Button')
u.clear_text()
s.send_keys('www.github.com')
assert 'www.github.com' == s(label='Address', className='TextField').get().value
@mark.skip("wait for WDA fix")
def test_session_keyboard_dismiss():
with c.session('com.apple.mobilesafari') as s:
u = s(label='Address', className='Button')
u.clear_text()
s.send_keys('www.github.com')
assert s(className='Keyboard').exists
s.keyboard_dismiss()
assert not s(className='Keyboard').exists
def test_session_orientation():
with c.session('com.apple.mobilesafari') as s:
assert s.orientation == wda.PORTRAIT
s.orientation = wda.LANDSCAPE
time.sleep(1.0)
assert s.orientation == wda.LANDSCAPE
# recover orientation
s.orientation = wda.PORTRAIT
def test_session_wait_gone():
s = c.session()
elem = s(name="Settings", visible=True)
with pytest.raises(wda.WDAElementNotDisappearError) as e_info:
elem.wait_gone(1.0)
assert not elem.wait_gone(1.0, raise_error=False)
s.swipe_left()
assert elem.wait_gone(1.0)
def test_text_contains_matches():
with c.session('com.apple.Preferences') as s:
s(text='Bluetooth').get()
assert s(textContains="Blue").exists
assert not s(text="Blue").exists
assert s(text="Bluetooth").exists
assert s(textMatches="Blue?").exists
assert s(nameMatches="Blue?").exists
assert not s(textMatches="^lue?").exists
assert not s(textMatches="^Blue$").exists
assert s(textMatches=r"^(Blue|Red).*").exists