-
Notifications
You must be signed in to change notification settings - Fork 574
Expand file tree
/
Copy pathtelenium_process.py
More file actions
126 lines (108 loc) · 4.39 KB
/
telenium_process.py
File metadata and controls
126 lines (108 loc) · 4.39 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
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
121
122
123
124
125
126
"""
Base class for telenium test cases which run kivy app as background process
"""
import os
import shutil
import tempfile
from time import time, sleep
from requests.exceptions import ChunkedEncodingError
from telenium.tests import TeleniumTestCase
from telenium.client import TeleniumHttpException
_files = (
'keys.dat', 'debug.log', 'messages.dat', 'knownnodes.dat',
'.api_started', 'unittest.lock'
)
tmp_db_file = (
'keys.dat', 'messages.dat'
)
def cleanup(files=_files):
"""Cleanup application files"""
for pfile in files:
try:
os.remove(os.path.join(tempfile.gettempdir(), pfile))
except OSError:
pass
class TeleniumTestProcess(TeleniumTestCase):
"""Setting Screen Functionality Testing"""
cmd_entrypoint = [os.path.join(os.path.abspath(os.getcwd()), 'src', 'mockbm', 'kivy_main.py')]
@classmethod
def setUpClass(cls):
"""Setupclass is for setting temp environment"""
os.environ["BITMESSAGE_HOME"] = tempfile.gettempdir()
cls.populate_test_data()
super(TeleniumTestProcess, cls).setUpClass()
@staticmethod
def populate_test_data():
"""Set temp data in tmp directory"""
for file_name in tmp_db_file:
old_source_file = os.path.join(
os.path.abspath(os.path.dirname(__file__)), 'sampleData', file_name)
new_destination_file = os.path.join(os.environ['BITMESSAGE_HOME'], file_name)
shutil.copyfile(old_source_file, new_destination_file)
@classmethod
def tearDownClass(cls):
"""Ensures that pybitmessage stopped and removes files"""
# pylint: disable=no-member
try:
super(TeleniumTestProcess, cls).tearDownClass()
except ChunkedEncodingError:
pass
cleanup()
def assert_wait_no_except(self, selector, timeout=-1, value='inbox'):
"""This method is to check the application is launched."""
start = time()
deadline = start + timeout
while time() < deadline:
try:
if self.cli.getattr(selector, 'current') == value:
self.assertTrue(selector, value)
return
except TeleniumHttpException:
sleep(0.1)
continue
finally:
# Finally Sleep is used to make the menu button functionally available for the click process.
# (because screen transition is little bit slow)
sleep(0.2)
raise AssertionError("Timeout")
def drag(self, xpath1, xpath2):
"""this method is for dragging"""
self.cli.drag(xpath1, xpath2, 1)
self.cli.sleep(1)
def assertCheckScrollDown(self, selector, timeout=-1):
"""this method is for checking scroll"""
start = time()
while True:
scroll_distance = self.cli.getattr(selector, 'scroll_y')
if scroll_distance > 0.0:
self.assertGreaterEqual(scroll_distance, 0.0)
return True
if timeout == -1:
return False
if timeout > 0 and time() - start > timeout:
raise Exception("Timeout")
sleep(0.5)
def assertCheckScrollUp(self, selector, timeout=-1):
"""this method is for checking scroll UP"""
start = time()
while True:
scroll_distance = self.cli.getattr(selector, 'scroll_y')
if scroll_distance < 1.0:
self.assertGreaterEqual(scroll_distance, 0.0)
return True
if timeout == -1:
return False
if timeout > 0 and time() - start > timeout:
raise Exception("Timeout")
sleep(0.5)
def open_side_navbar(self):
"""Common method for opening Side navbar (Side Drawer)"""
# Checking the drawer is in 'closed' state
self.cli.execute('app.ContentNavigationDrawer.MDNavigationDrawer.opening_time=0')
self.assertExists('//MDNavigationDrawer[@status~=\"closed\"]', timeout=5)
# This is for checking the menu button is appeared
self.assertExists('//ActionTopAppBarButton[@icon~=\"menu\"]', timeout=5)
# this is for opening Nav drawer
self.cli.wait_click('//ActionTopAppBarButton[@icon=\"menu\"]', timeout=5)
# checking state of Nav drawer
self.assertExists("//MDNavigationDrawer[@state~=\"open\"]", timeout=5)