2021-06-11 19:14:57 +02:00
|
|
|
"""
|
|
|
|
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 telenium.tests import TeleniumTestCase
|
2021-07-30 10:02:05 +02:00
|
|
|
from telenium.client import TeleniumHttpException
|
|
|
|
|
2021-06-11 19:14:57 +02:00
|
|
|
|
|
|
|
_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', 'mock', 'kivy_main.py')]
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
"""Setupclass is for setting temp environment"""
|
|
|
|
os.environ["BITMESSAGE_HOME"] = tempfile.gettempdir()
|
2021-09-28 15:33:24 +02:00
|
|
|
cls.populate_test_data()
|
2021-06-11 19:14:57 +02:00
|
|
|
super(TeleniumTestProcess, cls).setUpClass()
|
|
|
|
|
2021-09-29 15:24:55 +02:00
|
|
|
@staticmethod
|
2021-09-28 15:33:24 +02:00
|
|
|
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)
|
|
|
|
|
2021-06-11 19:14:57 +02:00
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
"""Ensures that pybitmessage stopped and removes files"""
|
|
|
|
# pylint: disable=no-member
|
|
|
|
try:
|
|
|
|
cls.cli.app_quit()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
try:
|
|
|
|
cls.process.kill()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
cleanup()
|
|
|
|
|
2021-07-30 10:02:05 +02:00
|
|
|
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)
|
2021-08-18 12:37:20 +02:00
|
|
|
break
|
2021-07-30 10:02:05 +02:00
|
|
|
except TeleniumHttpException:
|
|
|
|
sleep(0.1)
|
|
|
|
continue
|
|
|
|
finally:
|
|
|
|
# Finally Sleep is used to make the menu button funcationlly available for the click process.
|
|
|
|
# (because Transition is little bit slow)
|
2021-08-18 12:37:20 +02:00
|
|
|
sleep(0.2)
|
2021-07-30 10:02:05 +02:00
|
|
|
|
2021-06-11 19:14:57 +02:00
|
|
|
def drag(self, xpath1, xpath2):
|
|
|
|
"""this method is for dragging"""
|
|
|
|
self.cli.drag(xpath1, xpath2, 1)
|
|
|
|
self.cli.sleep(0.3)
|
|
|
|
|
|
|
|
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.1)
|
2021-08-18 14:35:57 +02:00
|
|
|
|
|
|
|
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.1)
|