0 Star 0 Fork 0

Jaque/DeuToolsGUITestPY2_V3.0

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
TileBuilder_V3.py 13.90 KB
一键复制 编辑 原始数据 按行查看 历史
Jaque 提交于 2018-10-22 09:42 . no commit message
# -*- coding:utf-8 -*-
import sys, os
import time
from time import sleep
import unittest
from pywinauto.application import Application
from extendScript.HTMLTestRunner import *
from extendScript.RWExcleIMPL import ExcelImpl
from extendScript.ChangeTestCase import TestCaseNumIMPL
from extendScript.DBAadaptor import DB_Excel
from extendScript.DBAadaptor import DB_MySQL
class setValueToGUI:
def __init__(self, listValue=None):
# self.ei = ExcelImpl()
# self.listValue = self.ei.getOneTestCaseByExcel(testNo=listValue)
self.gtd = GetTestData()
self.listValue = self.gtd.get_onedata_value(listValue)
self.startTilebuilder(self.listValue)
def startTilebuilder(self, data):
filePath = self.gtd.get_pz_data("TileBuilder")
app = Application()
try:
self.app = app = app.connect(title_re="DEUTileBuilder")
self.wfMain = wfMain = app.DEUTileBuilder
except Exception as e:
self.app = app = app.start(cmd_line=filePath)
print e
self.wfMain = wfMain = app.DEUTileBuilder
wfMain.Wait('ready')
# 暂停1s
sleep(2)
if data[1] == "影像数据":
wfMain['影像'].Click()
if data[1] == '高程数据':
wfMain['高程'].Click()
# 01、加载数据
wfMain['添加'].Click()
sleep(1)
self.loadTestData(app, data[2], data[8])
sleep(2)
# 02、设置输出路径
wfMain['浏览'].Click()
sleep(1)
outputdata = os.getcwd() + "\\outputdata\\DataSet\\" + data[0] + "_" + data[2] + "_" + str(int(data[3]))
self.setOUTPutData(app['另存为'], outputdata)
sleep(2)
# 03、设置最大最小层级
self.setMinLevel(wfMain, int(data[5]))
self.setMaxLevel(wfMain, int(data[6]))
# 04、设置规格
self.setSize(wfMain, int(data[3]))
# 05、设置数据集编号
self.setDataSetNO(wfMain, int(data[7]))
sleep(2)
# 06、开始切片
# wfMain['开始'].Click()
# while wfMain['Edit0'].IsEnabled() is False:
# sleep(2)
#
# sleep(1)
# wfMain['关闭'].Click()
#
# app['WindowsForms10.Window.8.app.0.2bf8098_r11_ad1']['确定'].Click()
def loadTestData(self, winfrom, dataformat, testData):
testData = '"' + testData.replace(',', '" "') + '"'
dataformat = dataformat.upper()
if dataformat == 'TIF' or dataformat == 'BIL':
winfrom['打开']['ComboBox2'].Select(0)
if dataformat == 'IMG' or dataformat == 'DEM':
winfrom['打开']['ComboBox2'].Select(1)
if dataformat == 'JPG':
winfrom['打开']['ComboBox2'].Select(2)
if dataformat == 'BMP':
winfrom['打开']['ComboBox2'].Select(2)
# winfrom[u'Edit1'].ClickInput() #点击文本编辑框
# winfrom[u'Edit1'].TypeKeys(testData) #输入文本内容
winfrom['打开']['Edit1'].SetEditText(testData) #清空文本框内容再输入
try:
winfrom['打开'][u'打开(&O)'].Click()
# sleep(1)
except Exception as e1:
print(e1)
winfrom['打开'][u'打开(&O)'].Click()
finally:
try:
winfrom['打开'][u'打开(&O)'].Click()
except Exception as e3:
print(e3)
'''
try:
#winfrom.print_control_identifiers()
winfrom['Button1'].Click()
print("第一次打开.")
except Exception as e:
winfrom['打开(O)'].Click()
print("第二次打开.")
print(e+"错误出现了,检查目录或文件!")
'''
def setOUTPutData(self, winfrom, outputdata):
# winfrom.print_control_identifiers()
# winfrom['ComboBox0'].TypeKeys(outputdata)
winfrom['Edit1'].SetEditText(outputdata)
# sleep(1)
# winfrom.Click()
# winfrom[u"保存(S)"].Click()
# winfrom[u"保存(S)"].Click()
try:
winfrom['Button1'].Click()
print("第一次保存.")
except Exception as e1:
print(e1)
winfrom[u'保存(S)'].Click()
print("第二次保存.")
finally:
try:
winfrom['Button1'].Click()
except Exception as e1:
print(e1)
def setSize(self, wimfrom, size):
if size == 128 or size == 8:
wimfrom['ComboBox1'].Select(0)
if size == 256 or size == 16:
wimfrom['ComboBox1'].Select(1)
if size == 512 or size == 32:
wimfrom['ComboBox1'].Select(2)
if size == 64:
wimfrom['ComboBox1'].Select(3)
def setMaxLevel(self, winfrom, strMaxLevel):
if strMaxLevel > int(winfrom['ComboBox2'].ItemTexts()[len(winfrom['ComboBox2'].ItemTexts()) - 1]):
winfrom['ComboBox2'].Select(len(winfrom['ComboBox2'].ItemTexts()) - 1)
else:
for index, value in enumerate(winfrom['ComboBox2'].ItemTexts()):
if strMaxLevel == int(value):
winfrom['ComboBox2'].Select(index)
break
def setMinLevel(self, winfrom, strMinLevel):
sleep(2)
if strMinLevel < int(winfrom['ComboBox3'].ItemTexts()[0]):
winfrom['ComboBox3'].Select(0)
else:
for index, value in enumerate(winfrom['ComboBox3'].ItemTexts()):
if strMinLevel == int(value):
winfrom['ComboBox3'].Select(index)
break
def setDataSetNO(self, winfrom, strDataSetNO):
winfrom['Edit0'].SetEditText(strDataSetNO)
def getWinForm(self):
return (self.app, self.wfMain, self.listValue)
class StartTestGui(unittest.TestCase):
def setUp(self):
# self.verificationErrors = []
self.tcn = TestCaseNumIMPL()
self.svi = setValueToGUI(listValue=self.tcn.getValue())
self.app, self.wfMain, self.listValue = self.svi.getWinForm()
def testloadData(self):
loadpath = self.listValue[8]
self.assertEqual(loadpath.lower(), str(self.wfMain['LISTBOX2'].texts()[1]).lower())
def testsetOUTPutData(self):
filepath = os.getcwd() + "\\outputdata\\DataSet\\" + self.listValue[0] + "_" + self.listValue[2] + "_" + str(
int(self.listValue[3]))
self.assertEqual(filepath.lower(), str(self.wfMain["EDIT4"].texts()[0]).lower())
def testsetSize(self):
size = self.listValue[3]
self.assertEqual(int(size), int(self.wfMain['COMBOBOX1'].selected_text()))
def testsetMaxLevel(self):
MaxLevel = self.listValue[6]
self.assertEqual(int(MaxLevel), int(self.wfMain['COMBOBOX2'].selected_text()))
def testsetMinLevel(self):
MinLevel = self.listValue[5]
self.assertEqual(int(MinLevel), int(self.wfMain['COMBOBOX3'].selected_text()))
def testDataSetNO(self):
DataSetNO = self.listValue[7]
self.assertEqual(int(DataSetNO), int(self.wfMain['Edit1'].texts()[1]))
def testSCFile(self):
filepath = os.getcwd() + "\\outputdata\\DataSet\\" + self.listValue[0] + "_" + self.listValue[2] + "_" + str(
int(self.listValue[3]))
self.wfMain['开始'].Click()
while self.wfMain['Edit0'].IsEnabled() is False:
sleep(2)
sleep(1)
if self.listValue[1] == "影像数据":
self.assertTrue(
os.path.exists(filepath + '.DeuDom') and os.path.exists(filepath + '.idx') and os.path.exists(
filepath + '_0.db'))
if self.listValue[1] == '高程数据':
self.assertTrue(
os.path.exists(filepath + '.DeuDem') and os.path.exists(filepath + '.idx') and os.path.exists(
filepath + '_0.db'))
def tearDown(self):
pass
# self.tcn.addOneToFile()
# self.wfMain['关闭'].Click()
# self.app['WindowsForms10.Window.8.app.0.2bf8098_r11_ad1']['确定'].Click()
class initThisTester:
def __init__(self):
pass
def delReportAndOutdata(self):
print u"测试环境初始化,请稍后!"
self.delReport()
self.delOutdata()
def delReport(self):
self.delAllfolder(os.getcwd() + "\\ReportFile")
def delOutdata(self):
self.delAllfolder(os.getcwd() + "\\outputdata\\DataSet")
def delAllfolder(self, filepath):
for dfile in os.listdir(filepath):
os.remove(filepath + "\\" + dfile)
def closd_forme(self):
try:
app = Application().connect(title_re="DEUTileBuilder")
wfMain = app.DEUTileBuilder
sleep(1)
wfMain['关闭'].Click()
app['WindowsForms10.Window.8.app.0.2bf8098_r11_ad1']['确定'].Click()
except Exception as e:
print e
def jltext_tilebuilder(self):
ei = ExcelImpl()
tcn = TestCaseNumIMPL()
tcn.setValue("TC1")
inittter = initThisTester()
inittter.delReportAndOutdata()
noTestcase = ei.getTestCaseByExcel(type='TileBuilder')
for i in noTestcase:
print "=" * 100
print u"执行测试用例:" + i[0]
print i
tcn.setValue(i[0])
suite = unittest.makeSuite(StartTestGui)
filename = os.getcwd() + "\\ReportFile\\" + i[0] + "_" + i[2] + "_" + str(int(i[3])) + "_Report.html"
fp = file(filename, 'wb')
runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u'自动化测试报告',
description=u'自动化测试报告,测试用例' + i[0] + "_" + i[2] + "_" + str(
int(i[3])))
runner.run(suite)
inittter.closd_forme()
tcn.setValue("TC1")
class GetTestData:
def __init__(self):
self.program = os.getcwd() + u'\\inputdata\\FilePath.xlsx'
self.program_info = DB_Excel(self.program, u'FilePath').get_globe_dict()
def get_pz_data(self, strOption):
return self.program_info[strOption]
def get_alldata_value(self):
if self.program_info["dbsourcetype"] == 0: # 0:excel 1:mysql
return self.get_excel_data(os.getcwd() + "\\inputdata\\" + self.program_info["excel_TileBuilder"] + ".xlsx",
self.program_info["excel_TileBuilder"])
elif self.program_info["dbsourcetype"] == 1: # 0:excel 1:mysql
return self.get_mysql_data(self.program_info["mysql_host"],
self.program_info["mysql_username"], self.program_info["mysql_passwd"],
self.program_info["mysql_dbname"], "TileBuilder")
print "配置文件" + os.getcwd() + u'\\inputdata\\FilePath.xlsx' + "的dbsourcetype值错误","\n" ,"0:excel 1:mysql"
def get_onedata_value(self, strtestnum):
if self.program_info["dbsourcetype"] == 0: # 0:excel 1:mysql
return self.get_excel_onedata(
os.getcwd() + "\\inputdata\\" + self.program_info["excel_TileBuilder"] + ".xlsx",
self.program_info["excel_TileBuilder"], strtestnum)
if self.program_info["dbsourcetype"] == 1: # 0:excel 1:mysql
return self.get_mysql_onedata(self.program_info["mysql_host"],
self.program_info["mysql_username"], self.program_info["mysql_passwd"],
self.program_info["mysql_dbname"], "TileBuilder", strtestnum)
def get_excel_data(self, excelpath, tablename):
data_list = DB_Excel(excelpath, tablename).get_OneTestCase_row_RList()
return data_list
def get_mysql_data(self, host, username, passwd, dbname, tablename):
data_list = DB_MySQL(host, username, passwd, dbname, tablename).get_OneTestCase_row_RList()
return data_list
def get_excel_program_info(self, excelpath):
return DB_Excel(excelpath, 'FilePath').get_globe_dict()
def get_mysql_program_info(self, host, username, passwd, dbname):
return DB_MySQL(host, username, passwd, dbname, 'FilePath').get_globe_dict()
def get_mysql_onedata(self, host, username, passwd, dbname, tablename, strtestnum):
data_list = DB_MySQL(host, username, passwd, dbname, tablename)
return data_list.get_OneTestCase_by_testNO(strtestnum)
def get_excel_onedata(self, excelpath, tablename, strtestnum):
data_list = DB_Excel(excelpath, tablename).get_OneTestCase_by_testNO(strtestnum)
return data_list
if __name__ == '__main__':
gtd = GetTestData()
noTestcase = gtd.get_alldata_value()
tcn = TestCaseNumIMPL()
tcn.setValue("TC1")
inittter = initThisTester()
inittter.delReportAndOutdata()
for i in noTestcase:
print "=" * 100
print u"执行测试用例:" + i[0]
print i
tcn.setValue(i[0])
suite = unittest.makeSuite(StartTestGui)
times = time.strftime("%Y_%m_%d", time.localtime())
filename = os.getcwd() + "\\ReportFile\\" + i[0] + times + "_" + i[2] + "_" + str(int(i[3])) + "_Report.html"
fp = file(filename, 'wb')
runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u'自动化测试报告',
description=u'自动化测试报告,测试用例' + i[0] + "_" + i[2] + "_" + str(int(i[3])))
runner.run(suite)
inittter.closd_forme()
tcn.setValue("TC1")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/jaque/DeuToolsGUITestPY2_V3.0.git
git@gitee.com:jaque/DeuToolsGUITestPY2_V3.0.git
jaque
DeuToolsGUITestPY2_V3.0
DeuToolsGUITestPY2_V3.0
master

搜索帮助