-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSampleAndroidTest.py
More file actions
executable file
·99 lines (72 loc) · 2.99 KB
/
SampleAndroidTest.py
File metadata and controls
executable file
·99 lines (72 loc) · 2.99 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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import unittest
from page.account.accounts import Accounts
from page.initialsetup.welcome import Welcome
from page.common.utils import get_window_size, GlobalVar
from appium import webdriver
# Returns abs path relative to this file and not cwd
def PATH(p: str) -> str: return os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
)
caps = {
'platformName': "Android",
'platformVersion': "8.0",
# 'platformVersion': "9",
'deviceName': "Android Emulator",
'appPackage': "org.gnucash.android",
'appActivity': ".ui.account.AccountsActivity",
'app': PATH('./gnucash.apk'),
'automationName': "uiautomator2",
}
class BaseTest(unittest.TestCase):
def __init__(self, method_name: str) -> None:
super(BaseTest, self).__init__(method_name)
self.caps = caps
def setUp(self) -> None:
self.driver = webdriver.Remote(
'http://localhost:4723/wd/hub', self.caps)
self.width, self.height = get_window_size(self.driver)
# Start taking evidence
self.make_log_dir(self._testMethodName)
self.driver.start_recording_screen()
def tearDown(self) -> None:
# Stop taking evidence
payload = self.driver.stop_recording_screen()
with open(os.path.join(GlobalVar().log_dir, "cap.mp4"), "wb") as fd:
import base64
fd.write(base64.b64decode(payload))
with open(os.path.join(GlobalVar().log_dir, "log.txt"), "w") as fd: # type: ignore
logs = self.driver.get_log('logcat')
for lines in logs:
for line in lines['message'].split('¥n'):
fd.write(line + '\n')
# end the session
self.driver.quit()
@staticmethod
def make_log_dir(dir_name: str) -> None:
GlobalVar().log_dir = os.path.join(GlobalVar().log_root_dir, dir_name)
os.path.isdir(GlobalVar().log_dir) or os.makedirs(GlobalVar().log_dir) # type: ignore
class SampleAndroidTest(BaseTest):
def testtest(self) -> None:
# print(self.driver.location)
# print(self.driver.finger_print(1))
print('*****')
# self.driver.send_sms("090-6553-2354", "Hello")
self.driver.toggle_airplane_mode()
# print(self.driver.get_settings())
# data = {'waitForIdleTimeout': 10001}
# self.driver.update_settings(data)
# print(self.driver.get_settings())
# data = {'waitForIdleTimeout': 10000}
# self.driver.update_settings(data)
# print(self.driver.get_settings())
import time
time.sleep(3)
if __name__ == '__main__':
import datetime as dt
GlobalVar().log_root_dir = os.path.join(PATH('.'), 'output', dt.datetime.now().strftime('%y%m%d-%H%M%S'))
os.path.isdir(GlobalVar().log_root_dir) or os.makedirs(GlobalVar().log_root_dir) # type: ignore
suite = unittest.TestLoader().loadTestsFromTestCase(SampleAndroidTest) # For debug
unittest.TextTestRunner(verbosity=2).run(suite)