Notebook半自动化测试
import os,sys,time,functools,datetime,subprocess,requests sys.path.append("..") print('半自动测试工具©2023 By xcsg') print('') #使用装饰器scoket 端口,实现脚本唯一 def ApplicationInstance(func): @functools.wraps(func) def fun(*args,**kwargs): import socket try: global s s = socket.socket() host = socket.gethostname() s.bind((host, 60123)) #一个脚本一个全局端口号,保证不重复运行 except: prin('不能重复打开已存在的程序...') return None return func(*args,**kwargs) return fun def set_system_time_from_server(url): try: response = requests.head(url, timeout=5) server_time = response.headers.get('Date') # 解析服务器时间(格林威治时间) server_time = datetime.datetime.strptime(server_time, '%a, %d %b %Y %H:%M:%S %Z') # 增加8小时,转换为北京时间 server_time = server_time + datetime.timedelta(hours=8) server_time = server_time + datetime.timedelta(seconds=1) # 格式化为适合设置系统时间的字符串格式 system_time_str = server_time.strftime('%Y-%m-%d %H:%M:%S') # 分割日期和时间 date_str, time_str = system_time_str.split() # 设置日期 subprocess.call(['cmd', '/c', 'date', date_str]) # 设置时间 subprocess.call(['cmd', '/c', 'time', time_str]) print(u"2,本地系统时间已更新为北京时间") except Exception as e: print(u"出现错误:", str(e)) def run(q,m): T = subprocess.Popen("%s" %q) time.sleep(m) T.kill() @ApplicationInstance def main(): # 替换下面的url变量为你要获取时间的网站 url = 'http://www.qq.com/' exit_code = os.system('ping www.baidu.com') if exit_code: print("网络测试失败,请连接网络...") exit() else: print("1,网络测试成功") set_system_time_from_server(url) print(u"3,正在查看系统激活状态") os.system('start ms-settings:activation') time.sleep(4) os.system('taskkill /f /im SystemSettings.exe') print(u"4,正在测试摄像头") run('test\VideoCap.exe',4) print(u"5,正在测试wifi ") run('test\TEST_TOOL\WiFi.exe',6) print(u"6,正在测试蓝牙") run('test\TEST_TOOL\Bluetooth.exe',8) print(u"7,正在测试麦克风和声音") os.system('test\Recorder.exe') print(u"8,正在测试喇叭和声音") os.system('test\AudioTest.exe') print(u"9,正在测试键盘") os.system('test\TEST_TOOL\Keyboard.exe') print(u"10,正在测试显示屏") os.system('test\LCD.EXE') print(u"11,正在监测系统硬件") os.system('test\dd.exe') os.system('devmgmt.msc') print(u"12,正在测试系统稳定性") os.system('test\ida64.exe') if __name__ == '__main__': main() sys.exit() # # for i in range(30): # # print(u"感谢使用,本程序将在{}秒后自动关闭...".format(str(30-i))) # # time.sleep(1)