__author__ = 'mutingting' # -*- coding: UTF-8 -*- #client import socket,datetime,time,xlrd def GetDateTimeStr(): return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S %f') class SocketClient(): sR = socket.socket(socket.AF_INET,socket.SOCK_STREAM) s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) def InitSocket(self): # host = '192.168.0.40' host = '10.0.238.1' port = 8000 SocketClient.sR.bind((host,port))#绑定端口 SocketClient.sR.listen(5)#等待客户连接,监听sock对象 host = '10.0.238.1' # host = '192.168.0.40' port = 8081 SocketClient.s.connect((host,port)) #建立连接 def Uinit(self): SocketClient.sR.close() SocketClient.s.close() def client(self,message): SocketClient.s.sendall(message.encode('utf-8'))#发送数据 clientSock,addr = SocketClient.sR.accept()#建立客户端连接) #创建接收客户端的一个对象connection(名字随便起);把客户端的Ip和port存储到addr data = clientSock.recv(2048).decode()#接收数据 print(GetDateTimeStr() + ' Receive Data = {}'.format(data)) return data def read_file(self): ExcelFile = xlrd.open_workbook(r'D:\ccp用例_V1.2_0410.xlsx') sheet = ExcelFile.sheet_by_name('Sheet1') rows = sheet.nrows todyTime = time.strftime('%Y-%m-%d', time.localtime(time.time())) for row in range(1, rows): cellValue = sheet.cell(row, 6).value natureValue = sheet.cell(row, 5).value print(natureValue) receivedata = obj.client(cellValue) with open('D:\\'+todyTime+' TestCase.txt', 'a')as testcase_file: testcase_file.write(receivedata +'\n') with open('D:\\'+todyTime+' Result.txt', 'a')as result_file: if '|0|'not in receivedata and natureValue in "正用例": print('failed'+ '\n'+ "--------------------------------------------------") result_file.write("failed"+'\n') elif '|0|'in receivedata and natureValue in '反用例': print('failed'+ '\n'+ "--------------------------------------------------") result_file.write('failed'+'\n') else: print("pass"+ '\n'+ "--------------------------------------------------") result_file.write('pass'+'\n') if __name__ == '__main__': obj = SocketClient() obj.InitSocket() obj.read_file() obj.Uinit()
python+socket测试
猜你喜欢
转载自blog.csdn.net/mutingting988/article/details/80092883
今日推荐
周排行