|
@@ -1,6 +1,7 @@
|
|
|
#include "StdAfx.h"
|
|
|
#include "SATExecutor.h"
|
|
|
#include "ScriptExecutor.h"
|
|
|
+#include "CharEncoding.h"
|
|
|
|
|
|
CSATExecutor::CSATExecutor(void)
|
|
|
{
|
|
@@ -87,7 +88,7 @@ SATParameters::STCase* CSATExecutor::GetFreeCaseScript(std::vector<SATParameters
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
-void CSATExecutor::ExecuteFreeCaseScript(SATParameters::STTask* pTask)
|
|
|
+SATParameters::STCase* CSATExecutor::ExecuteFreeCaseScript(SATParameters::STTask* pTask)
|
|
|
{
|
|
|
SATParameters::STCase* pCase = GetFreeCaseScript(pTask->Job.vtCases);
|
|
|
if (pCase)
|
|
@@ -98,7 +99,9 @@ void CSATExecutor::ExecuteFreeCaseScript(SATParameters::STTask* pTask)
|
|
|
if ( pExcutor )
|
|
|
{
|
|
|
pCase->_pExcutor = pExcutor;
|
|
|
- if ( pExcutor->InitScript(pCase->_strScriptPath, pCase->_strFileDir + "\\" + pCase->_strFileName + ".txt", "", SUBPROCESS) )
|
|
|
+ // 用例的日志文件路径;
|
|
|
+ pCase->_strCaseLog = pCase->_strFileDir + "\\" + pCase->_strFileName + ".txt";
|
|
|
+ if ( pExcutor->InitScript(pCase->_strScriptPath, pCase->_strCaseLog, "", SUBPROCESS) )
|
|
|
{
|
|
|
pExcutor->StartScript();
|
|
|
// 标记用例执行中;
|
|
@@ -107,6 +110,7 @@ void CSATExecutor::ExecuteFreeCaseScript(SATParameters::STTask* pTask)
|
|
|
pTask->_nExecutionState = 1;
|
|
|
// 记录开始时间;
|
|
|
pCase->_ulStartTickCount = GetTickCount64();
|
|
|
+ pCase->_strStartTime = CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S"));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -115,12 +119,15 @@ void CSATExecutor::ExecuteFreeCaseScript(SATParameters::STTask* pTask)
|
|
|
CScriptExecutor *pExcutor = (CScriptExecutor *)pCase->_pExcutor;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ return pCase;
|
|
|
}
|
|
|
|
|
|
bool CSATExecutor::Login()
|
|
|
{
|
|
|
#ifdef _DEBUG
|
|
|
- std::string url = "http://10.126.16.60:8580/btc_execute_se/ajaxInteractiveManage!executeLogin.action";
|
|
|
+ std::string url = Global::g_stSATConfig.szExecuteServer;
|
|
|
+ url.append("/ajaxInteractiveManage!executeLogin.action");
|
|
|
// 示例值;
|
|
|
m_stLoginReq.strUserName = "superAdmin";
|
|
|
m_stLoginReq.strStatus = "0";
|
|
@@ -175,8 +182,9 @@ bool CSATExecutor::UpdateDevice()
|
|
|
|
|
|
SATParameters::STUpdateDeviceReq stUpdateDeviceReq;
|
|
|
SATParameters::STUpdateDeviceResp stUpdateDeviceResp;
|
|
|
- std::string url = "http://10.126.16.60:8580/btc_execute_se/ajaxInteractiveManage!updateDeviceMessage.action";
|
|
|
-
|
|
|
+ std::string url = Global::g_stSATConfig.szExecuteServer;
|
|
|
+ url.append("/ajaxInteractiveManage!updateDeviceMessage.action");
|
|
|
+
|
|
|
stUpdateDeviceReq.strStatus = "0";
|
|
|
stUpdateDeviceReq.strUserName = "superAdmin";
|
|
|
stUpdateDeviceReq.strIP = "10.118.158.175";
|
|
@@ -201,6 +209,476 @@ bool CSATExecutor::UpdateDevice()
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
+bool CSATExecutor::NotifyTaskStart(SATParameters::STTask* pTask)
|
|
|
+{
|
|
|
+ if ( !pTask )
|
|
|
+ return false;
|
|
|
+
|
|
|
+ SATParameters::STNotifyJobStartReq stNotifyJobStartReq;
|
|
|
+ SATParameters::STNotifyJobStartResp stNotifyJobStartResp;
|
|
|
+ std::string url = Global::g_stSATConfig.szExecuteServer;
|
|
|
+ url.append("/ajaxInteractiveManage!setResult.action");
|
|
|
+
|
|
|
+ TCHAR szValue[36] = {0};
|
|
|
+ _itoa_s(pTask->nDeviceId, szValue, 10);
|
|
|
+ stNotifyJobStartReq.strDeviceId = szValue;
|
|
|
+
|
|
|
+ _itoa_s(pTask->nExecuteId, szValue, 10);
|
|
|
+ stNotifyJobStartReq.strExecuteId = szValue;
|
|
|
+
|
|
|
+ // _itoa_s(stTask.nInstanceId, szValue, 10); // 误导:应该使用id而不是nInstanceId
|
|
|
+ _itoa_s(pTask->Id, szValue, 10);
|
|
|
+ stNotifyJobStartReq.strInstanceId = szValue;
|
|
|
+
|
|
|
+ _itoa_s(pTask->nTaskId, szValue, 10);
|
|
|
+ stNotifyJobStartReq.strTaskId = szValue;
|
|
|
+
|
|
|
+ stNotifyJobStartReq.strSignalImageUrl = "D:\\\\SAT\\\\Runner\\\\btc_runner_se\\\\runner\\\\output\\\\";//ODF_NPI_RT2841\\\\20191216101613370\\\\192.168.1.119_5555";
|
|
|
+ stNotifyJobStartReq.strSignalImageUrl.append(pTask->strTaskName+"\\\\");
|
|
|
+ stNotifyJobStartReq.strSignalImageUrl.append(pTask->Job.strUniqueId+"\\\\");
|
|
|
+ stNotifyJobStartReq.strSignalImageUrl.append(pTask->Job.strDeviceId);
|
|
|
+
|
|
|
+ if ( SetResult(url, stNotifyJobStartReq, stNotifyJobStartResp) )
|
|
|
+ {
|
|
|
+ // 此处可能需要设置设备为忙碌状态;
|
|
|
+ // SetDeviceStatus(BUSY);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+#ifdef _DEBUG
|
|
|
+ OutputDebugString("通知SAT失败\n");
|
|
|
+#endif
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+bool CSATExecutor::UploadCaseImg(SATParameters::STTask* pTask, SATParameters::STCase *pCase, std::string img)
|
|
|
+{
|
|
|
+ TCHAR szValue[MAX_PATH] = {0};
|
|
|
+ std::string url = Global::g_stSATConfig.szExecuteServer;
|
|
|
+ url.append("/ajaxInteractiveManage!saveResultImg.action");
|
|
|
+
|
|
|
+ SATParameters::STSaveImgReq stSaveImgReq;
|
|
|
+ SATParameters::STSaveImgResp stSaveImgResp;
|
|
|
+
|
|
|
+ stSaveImgReq.strCaseId = pCase->strId;
|
|
|
+ stSaveImgReq.strCaseRepeat = "0";
|
|
|
+ stSaveImgReq.strCaseStep = pCase->strIndex;
|
|
|
+ // 实例Id;
|
|
|
+ _itoa_s(pTask->nDeviceId, szValue, 10);
|
|
|
+ stSaveImgReq.strDeviceId = szValue;//pTask->Job.strDeviceId;
|
|
|
+ // 就是Task中的ExecuteId
|
|
|
+ _itoa_s(pTask->nExecuteId, szValue, 10);
|
|
|
+ stSaveImgReq.strExecuteId = szValue;
|
|
|
+ // 实例Id;
|
|
|
+ _itoa_s(pTask->nInstanceId, szValue, 10);
|
|
|
+ stSaveImgReq.strInstanceId = szValue;
|
|
|
+ stSaveImgReq.strJobRepeat = "0";
|
|
|
+ // 注意避坑:roundnum必须赋值0或1;
|
|
|
+ stSaveImgReq.strRoundNum = "0";
|
|
|
+ stSaveImgReq.strTaskType = pTask->strTaskType;
|
|
|
+ stSaveImgReq.strUploads = img;
|
|
|
+
|
|
|
+ // 上传用例图片;
|
|
|
+ if ( SaveResultImg(url, stSaveImgReq, stSaveImgResp) )
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+bool CSATExecutor::UploadCaseLog(SATParameters::STTask* pTask, SATParameters::STCase *pCase)
|
|
|
+{
|
|
|
+ TCHAR szValue[MAX_PATH] = {0};
|
|
|
+ std::string url = Global::g_stSATConfig.szExecuteServer;
|
|
|
+ url.append("/ajaxInteractiveManage!saveCaseOrTaskLog.action");
|
|
|
+
|
|
|
+ SATParameters::STSaveLogReq stSaveLogReq;
|
|
|
+ SATParameters::STSaveLogResp stSaveLogResp;
|
|
|
+
|
|
|
+ stSaveLogReq.strCaseId = pCase->strId;
|
|
|
+ // 执行ID;
|
|
|
+ _itoa_s(pTask->nExecuteId, szValue, 10);
|
|
|
+ stSaveLogReq.strExecuteId = szValue;
|
|
|
+ stSaveLogReq.strFileType = "caseLogFile";
|
|
|
+ // 任务Id;
|
|
|
+ _itoa_s(pTask->nTaskId, szValue, 10);
|
|
|
+ stSaveLogReq.strTaskId = szValue;
|
|
|
+ stSaveLogReq.strUserId = pTask->Job.strUserId;
|
|
|
+ // 要上传的日志文件;
|
|
|
+ stSaveLogReq.strUploads = pCase->_strCaseLog;
|
|
|
+ if ( SaveCaseOrTaskLog(url, stSaveLogReq, stSaveLogResp) )
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+bool CSATExecutor::ReportCaseItemFinish(SATParameters::STTask* pTask, SATParameters::STCase *pCase, STCaseItem &caseItem)
|
|
|
+{
|
|
|
+ TCHAR szValue[MAX_PATH] = {0};
|
|
|
+ std::string url = Global::g_stSATConfig.szExecuteServer;
|
|
|
+ url.append("/ajaxInteractiveManage!setResultList.action");
|
|
|
+
|
|
|
+ SATParameters::STJobProcessReq stJobProcessReq;
|
|
|
+ SATParameters::STJobProcessResp stJobProcessResp;
|
|
|
+
|
|
|
+ stJobProcessReq.strResultState = caseItem.result ? "1" : "0";
|
|
|
+ stJobProcessReq.strCaseScene = "";
|
|
|
+ // 索引;
|
|
|
+ stJobProcessReq.strCaseStep = pCase->strIndex;
|
|
|
+ stJobProcessReq.strApkMD5 = "";
|
|
|
+ stJobProcessReq.strCrashTime = "";
|
|
|
+ // 就是Task中的ExecuteId
|
|
|
+ _itoa_s(pTask->nExecuteId, szValue, 10);
|
|
|
+ stJobProcessReq.strRunnerId = szValue;
|
|
|
+ stJobProcessReq.strCPUInfo = "0";
|
|
|
+ stJobProcessReq.strRunnedActionNameList = "";
|
|
|
+ stJobProcessReq.strArtificialResult = "";
|
|
|
+ stJobProcessReq.strArtificialModify = "";
|
|
|
+ stJobProcessReq.strRunnerName = "";
|
|
|
+ stJobProcessReq.strTaskType = "FUNCTIONALITY";
|
|
|
+ stJobProcessReq.strCaseRepeat = "";
|
|
|
+ stJobProcessReq.strApplicationGroup = "";
|
|
|
+ // 实例Id;
|
|
|
+ _itoa_s(pTask->nInstanceId, szValue, 10);
|
|
|
+ stJobProcessReq.strInstanceId = szValue;
|
|
|
+ stJobProcessReq.strCaseId = pCase->strId;
|
|
|
+ // 进度;
|
|
|
+ _itoa_s(100*(atoi(pCase->strIndex.c_str()))/pTask->Job.vtCases.size(), szValue, 10);
|
|
|
+ stJobProcessReq.strProgress = szValue;
|
|
|
+ // 需要将utf-8转gbk;
|
|
|
+ stJobProcessReq.strReusltMessage = CharEncoding::UTF82ASCII(caseItem.name.c_str());
|
|
|
+ stJobProcessReq.strJobRepeat = "";
|
|
|
+ stJobProcessReq.strScreenShot = "";
|
|
|
+ stJobProcessReq.strStartTime = pCase->_strStartTime;
|
|
|
+ stJobProcessReq.strCrashNumber = "";
|
|
|
+ stJobProcessReq.strCaseName = pCase->strCaseName;
|
|
|
+ stJobProcessReq.strFailedReason = CharEncoding::UTF82ASCII(caseItem.remark.c_str());
|
|
|
+ for (std::vector<std::string>::iterator it = caseItem.imgs.begin(); it != caseItem.imgs.end(); it++ )
|
|
|
+ {
|
|
|
+ int npos = it->find_last_of('/');
|
|
|
+ if ( std::string::npos != npos )
|
|
|
+ {
|
|
|
+ stJobProcessReq.strImgName.append(it->substr(npos));
|
|
|
+ stJobProcessReq.strImgName.append("&");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ( stJobProcessReq.strImgName.size() && stJobProcessReq.strImgName.at(stJobProcessReq.strImgName.size()-1) == '&')
|
|
|
+ stJobProcessReq.strImgName.erase(stJobProcessReq.strImgName.size()-1);
|
|
|
+ stJobProcessReq.strCaseIndex = pCase->strIndex;
|
|
|
+ // 实例Id;
|
|
|
+ _itoa_s(pTask->nDeviceId, szValue, 10);
|
|
|
+ stJobProcessReq.strDeviceId = szValue;
|
|
|
+ stJobProcessReq.strSceneIndex = "";
|
|
|
+ // 实例Id;
|
|
|
+ _itoa_s(pTask->nTaskId, szValue, 10);
|
|
|
+ stJobProcessReq.strTaskId = szValue;
|
|
|
+ stJobProcessReq.strAnalysis = CharEncoding::UTF82ASCII(caseItem.data.c_str());
|
|
|
+ // 设备名称:即DeviceSerial;
|
|
|
+ stJobProcessReq.strDevnceName = pTask->Job.strDeviceId; // 命名及其不范围,一会deviceid是deviceserial,一会是id;
|
|
|
+ // 固定为:TOTAL
|
|
|
+ stJobProcessReq.strInfoType = "";
|
|
|
+ // 如果是Android设备,需要通过adb获取;
|
|
|
+ //stJobProcessReq.strMemoryInfo = stDevice.strMemory;
|
|
|
+ stJobProcessReq.strEndTime = CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S"));//"2019-12-16 10:18:20";
|
|
|
+ stJobProcessReq.strRoundNumber = "1";
|
|
|
+ stJobProcessReq.strResultType = "4"; // reportActionFinish;
|
|
|
+ stJobProcessReq.strOperationStep = "";
|
|
|
+
|
|
|
+ if ( SetResultList(url, stJobProcessReq, stJobProcessResp) )
|
|
|
+ {
|
|
|
+ // 再上传图片;
|
|
|
+ std::string img;
|
|
|
+ for (std::vector<std::string>::iterator it = caseItem.imgs.begin(); it != caseItem.imgs.end(); it++ )
|
|
|
+ {
|
|
|
+ img = "D:/SAT/results/";
|
|
|
+ img.append(it->substr(3));
|
|
|
+ UploadCaseImg(pTask, pCase, img);
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+bool CSATExecutor::ReportCaseFinish(SATParameters::STTask* pTask, SATParameters::STCase *pCase)
|
|
|
+{
|
|
|
+ TCHAR szValue[MAX_PATH] = {0};
|
|
|
+ std::string url = Global::g_stSATConfig.szExecuteServer;
|
|
|
+ url.append("/ajaxInteractiveManage!setResultList.action");
|
|
|
+
|
|
|
+ SATParameters::STJobProcessReq stJobProcessReq;
|
|
|
+ SATParameters::STJobProcessResp stJobProcessResp;
|
|
|
+
|
|
|
+ // 上报用例结果:0表示脚本成功执行, 1表示脚本出错或超时;
|
|
|
+ if ( pCase->_nExecutionState == 2 )
|
|
|
+ stJobProcessReq.strResultState = "0"; // 脚本未执行完成;
|
|
|
+ else if ( pCase->_nExecutionState == 1 )
|
|
|
+ stJobProcessReq.strResultState = "1"; // 脚本执行中,认为fail;
|
|
|
+
|
|
|
+ stJobProcessReq.strCaseScene = "";
|
|
|
+ // 索引;
|
|
|
+ stJobProcessReq.strCaseStep = pCase->strIndex;
|
|
|
+ stJobProcessReq.strApkMD5 = "";
|
|
|
+ stJobProcessReq.strCrashTime = "";
|
|
|
+ // 就是Task中的ExecuteId
|
|
|
+ _itoa_s(pTask->nExecuteId, szValue, 10);
|
|
|
+ stJobProcessReq.strRunnerId = szValue;
|
|
|
+ stJobProcessReq.strCPUInfo = "0";
|
|
|
+ stJobProcessReq.strRunnedActionNameList = "";
|
|
|
+ stJobProcessReq.strArtificialResult = "";
|
|
|
+ stJobProcessReq.strArtificialModify = "";
|
|
|
+ stJobProcessReq.strRunnerName = "";
|
|
|
+ stJobProcessReq.strTaskType = "FUNCTIONALITY";
|
|
|
+ stJobProcessReq.strCaseRepeat = "";
|
|
|
+ stJobProcessReq.strApplicationGroup = "";
|
|
|
+ // 实例Id;
|
|
|
+ _itoa_s(pTask->nInstanceId, szValue, 10);
|
|
|
+ stJobProcessReq.strInstanceId = szValue;
|
|
|
+ stJobProcessReq.strCaseId = pCase->strId;
|
|
|
+ // 进度(###需要修改此处###);
|
|
|
+ _itoa_s(100*(atoi(pCase->strIndex.c_str()))/pTask->Job.vtCases.size(), szValue, 10);
|
|
|
+ stJobProcessReq.strProgress = szValue;
|
|
|
+ // 需要将utf-8转gbk;
|
|
|
+ stJobProcessReq.strReusltMessage = "测试用例结果:";
|
|
|
+ stJobProcessReq.strJobRepeat = "";
|
|
|
+ stJobProcessReq.strScreenShot = "";
|
|
|
+ stJobProcessReq.strStartTime = pCase->_strStartTime;
|
|
|
+ stJobProcessReq.strCrashNumber = "";
|
|
|
+ stJobProcessReq.strCaseName = pCase->strCaseName;
|
|
|
+ stJobProcessReq.strFailedReason = "";
|
|
|
+
|
|
|
+ stJobProcessReq.strImgName = "";
|
|
|
+ stJobProcessReq.strCaseIndex = pCase->strIndex;
|
|
|
+ // 实例Id;
|
|
|
+ _itoa_s(pTask->nDeviceId, szValue, 10);
|
|
|
+ stJobProcessReq.strDeviceId = szValue;
|
|
|
+ stJobProcessReq.strSceneIndex = "";
|
|
|
+ // 实例Id;
|
|
|
+ _itoa_s(pTask->nTaskId, szValue, 10);
|
|
|
+ stJobProcessReq.strTaskId = szValue;
|
|
|
+ stJobProcessReq.strAnalysis = "";
|
|
|
+ // 设备名称:即DeviceSerial;
|
|
|
+ stJobProcessReq.strDevnceName = pTask->Job.strDeviceId; // 命名及其不范围,一会deviceid是deviceserial,一会是id;
|
|
|
+ // 固定为:TOTAL
|
|
|
+ stJobProcessReq.strInfoType = "TOTAL";
|
|
|
+ // 如果是Android设备,需要通过adb获取;
|
|
|
+ //stJobProcessReq.strMemoryInfo = stDevice.strMemory;
|
|
|
+ stJobProcessReq.strEndTime = pCase->_strEndTime;//CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S"));//"2019-12-16 10:18:20";
|
|
|
+ stJobProcessReq.strRoundNumber = "1";
|
|
|
+ stJobProcessReq.strResultType = "5"; // reportCaseFinish;
|
|
|
+ stJobProcessReq.strOperationStep = "";
|
|
|
+
|
|
|
+ if ( SetResultList(url, stJobProcessReq, stJobProcessResp) )
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+bool CSATExecutor::ReportCaseResult(SATParameters::STTask* pTask, SATParameters::STCase *pCase)
|
|
|
+{
|
|
|
+ // 获取xml文件内容;
|
|
|
+ std::string xmlpath = "D:\\SAT\\results\\detail\\";
|
|
|
+ xmlpath.append(pCase->_strFileName);
|
|
|
+ xmlpath.append("_result.xml");
|
|
|
+ std::vector<STCaseItem> vtCaseItem;
|
|
|
+ GetCaseXMLResult(xmlpath, vtCaseItem);
|
|
|
+ if ( vtCaseItem.size() == 0 )
|
|
|
+ return false;
|
|
|
+
|
|
|
+ int nIndex = 1;
|
|
|
+ TCHAR szValue[MAX_PATH] = {0};
|
|
|
+ std::string url = Global::g_stSATConfig.szExecuteServer;
|
|
|
+ url.append("/ajaxInteractiveManage!setResultList.action");
|
|
|
+ SATParameters::STJobProcessReq stJobProcessReq;
|
|
|
+ SATParameters::STJobProcessResp stJobProcessResp;
|
|
|
+ // 遍历所有用例测试项;
|
|
|
+ std::vector<STCaseItem>::iterator it = vtCaseItem.begin();
|
|
|
+ for (; it != vtCaseItem.end(); it++ )
|
|
|
+ {
|
|
|
+ // 上报测试项结果(包含相片);
|
|
|
+ ReportCaseItemFinish(pTask, pCase, *it);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 上报用例完成;
|
|
|
+ ReportCaseFinish(pTask, pCase);
|
|
|
+
|
|
|
+ // 上传用例日志;
|
|
|
+ UploadCaseLog(pTask, pCase);
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+bool CSATExecutor::UploadTaskLog(SATParameters::STTask* pTask)
|
|
|
+{
|
|
|
+ TCHAR szValue[MAX_PATH] = {0};
|
|
|
+ std::string url = Global::g_stSATConfig.szExecuteServer;
|
|
|
+ url.append("/ajaxInteractiveManage!saveCaseOrTaskLog.action");
|
|
|
+
|
|
|
+ SATParameters::STSaveLogReq stSaveLogReq;
|
|
|
+ SATParameters::STSaveLogResp stSaveLogResp;
|
|
|
+
|
|
|
+ stSaveLogReq.strCaseId = "";
|
|
|
+ // 执行ID;
|
|
|
+ _itoa_s(pTask->nExecuteId, szValue, 10);
|
|
|
+ stSaveLogReq.strExecuteId = szValue;
|
|
|
+ stSaveLogReq.strFileType = "taskLogFile";
|
|
|
+ // 任务Id;
|
|
|
+ _itoa_s(pTask->nTaskId, szValue, 10);
|
|
|
+ stSaveLogReq.strTaskId = szValue;
|
|
|
+ stSaveLogReq.strUserId = pTask->Job.strUserId;
|
|
|
+ // 要上传的日志文件;
|
|
|
+ stSaveLogReq.strUploads = pTask->_strTaskLog;
|
|
|
+ if ( SaveCaseOrTaskLog(url, stSaveLogReq, stSaveLogResp) )
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+bool CSATExecutor::ReportTaskFinish(SATParameters::STTask* pTask)
|
|
|
+{
|
|
|
+ TCHAR szValue[MAX_PATH] = {0};
|
|
|
+ std::string url = Global::g_stSATConfig.szExecuteServer;
|
|
|
+ url.append("/ajaxInteractiveManage!setResultList.action");
|
|
|
+
|
|
|
+ SATParameters::STJobProcessReq stJobProcessReq;
|
|
|
+ SATParameters::STJobProcessResp stJobProcessResp;
|
|
|
+
|
|
|
+ // 需要处理###
|
|
|
+ stJobProcessReq.strResultState = "0"; // 脚本执行中,认为fail;
|
|
|
+
|
|
|
+ stJobProcessReq.strCaseScene = "";
|
|
|
+ // 索引;
|
|
|
+ stJobProcessReq.strCaseStep = "0";
|
|
|
+ stJobProcessReq.strApkMD5 = "";
|
|
|
+ stJobProcessReq.strCrashTime = "";
|
|
|
+ // 就是Task中的ExecuteId
|
|
|
+ _itoa_s(pTask->nExecuteId, szValue, 10);
|
|
|
+ stJobProcessReq.strRunnerId = szValue;
|
|
|
+ stJobProcessReq.strCPUInfo = "0";
|
|
|
+ stJobProcessReq.strRunnedActionNameList = "";
|
|
|
+ stJobProcessReq.strArtificialResult = "";
|
|
|
+ stJobProcessReq.strArtificialModify = "";
|
|
|
+ stJobProcessReq.strRunnerName = "";
|
|
|
+ stJobProcessReq.strTaskType = "FUNCTIONALITY";
|
|
|
+ stJobProcessReq.strCaseRepeat = "";
|
|
|
+ stJobProcessReq.strApplicationGroup = "";
|
|
|
+ // 实例Id;
|
|
|
+ _itoa_s(pTask->nInstanceId, szValue, 10);
|
|
|
+ stJobProcessReq.strInstanceId = szValue;
|
|
|
+ stJobProcessReq.strCaseId = "";
|
|
|
+ // 进度(###需要修改此处###);
|
|
|
+ stJobProcessReq.strProgress = "100";
|
|
|
+ // 需要将utf-8转gbk;
|
|
|
+ stJobProcessReq.strReusltMessage = "任务结束";
|
|
|
+ stJobProcessReq.strJobRepeat = "";
|
|
|
+ stJobProcessReq.strScreenShot = "";
|
|
|
+ stJobProcessReq.strStartTime = pTask->strStartTime;
|
|
|
+ stJobProcessReq.strCrashNumber = "";
|
|
|
+ stJobProcessReq.strCaseName = "";
|
|
|
+ stJobProcessReq.strFailedReason = "";
|
|
|
+
|
|
|
+ stJobProcessReq.strImgName = "";
|
|
|
+ stJobProcessReq.strCaseIndex = "";
|
|
|
+ // 实例Id;
|
|
|
+ _itoa_s(pTask->nDeviceId, szValue, 10);
|
|
|
+ stJobProcessReq.strDeviceId = szValue;
|
|
|
+ stJobProcessReq.strSceneIndex = "";
|
|
|
+ // 实例Id;
|
|
|
+ _itoa_s(pTask->nTaskId, szValue, 10);
|
|
|
+ stJobProcessReq.strTaskId = szValue;
|
|
|
+ stJobProcessReq.strAnalysis = "";
|
|
|
+ // 设备名称:即DeviceSerial;
|
|
|
+ stJobProcessReq.strDevnceName = pTask->Job.strDeviceId; // 命名及其不范围,一会deviceid是deviceserial,一会是id;
|
|
|
+ // 固定为:TOTAL
|
|
|
+ stJobProcessReq.strInfoType = "";
|
|
|
+ // 如果是Android设备,需要通过adb获取;
|
|
|
+ //stJobProcessReq.strMemoryInfo = stDevice.strMemory;
|
|
|
+ stJobProcessReq.strEndTime = CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S"));//"2019-12-16 10:18:20";
|
|
|
+ stJobProcessReq.strRoundNumber = "1";
|
|
|
+ stJobProcessReq.strResultType = "1"; // reportJobFinish;
|
|
|
+ stJobProcessReq.strOperationStep = "";
|
|
|
+
|
|
|
+ if ( SetResultList(url, stJobProcessReq, stJobProcessResp) )
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+bool CSATExecutor::GetCaseXMLResult(std::string xmlpath, std::vector<STCaseItem> &vtCaseItem)
|
|
|
+{
|
|
|
+ // 解析xml;
|
|
|
+ tinyxml2::XMLDocument doc;
|
|
|
+ if (tinyxml2::XML_SUCCESS != doc.LoadFile(xmlpath.c_str()) )
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ tinyxml2::XMLElement *pXmlRoot = NULL;
|
|
|
+ if ((pXmlRoot = doc.RootElement()) == NULL)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ if (_tcsicmp(pXmlRoot->Value(), "results") != 0)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ tinyxml2::XMLElement *pXmlElent = pXmlRoot->FirstChildElement();
|
|
|
+ while (pXmlElent)
|
|
|
+ {
|
|
|
+ if (_tcsicmp(pXmlElent->Value(), _T("item")) == 0)
|
|
|
+ {
|
|
|
+ STCaseItem cItem;
|
|
|
+ tinyxml2::XMLElement *pItem = pXmlElent->FirstChildElement();
|
|
|
+ while (pItem)
|
|
|
+ {
|
|
|
+ if (_tcsicmp(pItem->Value(), _T("name")) == 0)
|
|
|
+ {
|
|
|
+ cItem.name = pItem->GetText();
|
|
|
+ }
|
|
|
+ else if (_tcsicmp(pItem->Value(), _T("result")) == 0)
|
|
|
+ {
|
|
|
+ cItem.result = pItem->BoolText();
|
|
|
+ }
|
|
|
+ else if (_tcsicmp(pItem->Value(), _T("data")) == 0)
|
|
|
+ {
|
|
|
+ cItem.data = pItem->GetText();
|
|
|
+ }
|
|
|
+ else if (_tcsicmp(pItem->Value(), _T("log")) == 0)
|
|
|
+ {
|
|
|
+ cItem.log = pItem->GetText();
|
|
|
+ }
|
|
|
+ else if (_tcsicmp(pItem->Value(), _T("remark")) == 0)
|
|
|
+ {
|
|
|
+ cItem.remark = pItem->GetText();
|
|
|
+ }
|
|
|
+ else if (_tcsicmp(pItem->Value(), _T("screen")) == 0)
|
|
|
+ {
|
|
|
+ cItem.imgs.push_back(pItem->GetText());
|
|
|
+ }
|
|
|
+
|
|
|
+ pItem = pItem->NextSiblingElement();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 压入容器;
|
|
|
+ if ( cItem.name.size() )
|
|
|
+ vtCaseItem.push_back(cItem);
|
|
|
+ }
|
|
|
+
|
|
|
+ pXmlElent = pXmlElent->NextSiblingElement();
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
void CSATExecutor::StartWork()
|
|
|
{
|
|
|
m_hEventHearbeat = CreateEvent(NULL, TRUE, FALSE, NULL);
|
|
@@ -256,14 +734,11 @@ void CSATExecutor::EndofWork()
|
|
|
DWORD CSATExecutor::HearbeatThread(LPVOID lpVoid)
|
|
|
{
|
|
|
CSATExecutor *that = (CSATExecutor*)lpVoid;
|
|
|
- if ( !that )
|
|
|
- return 0;
|
|
|
+ if ( !that ) return 0;
|
|
|
|
|
|
- do
|
|
|
- {
|
|
|
+ do {
|
|
|
// 没有登录成功,不查询;
|
|
|
- if ( !that->m_bLogin )
|
|
|
- continue;
|
|
|
+ if ( !that->m_bLogin ) continue;
|
|
|
|
|
|
SATParameters::STHeartbeatReq stHeartbeatReq;
|
|
|
SATParameters::STHeartbeatResp stHeartbeatResp;
|
|
@@ -273,24 +748,19 @@ DWORD CSATExecutor::HearbeatThread(LPVOID lpVoid)
|
|
|
stHeartbeatReq.strUserName = that->m_stLoginReq.strUserName;
|
|
|
stHeartbeatReq.strRunnerMac = that->m_stLoginReq.strMAC;
|
|
|
stHeartbeatReq.devicelist.assign(that->m_vtDevice.begin(), that->m_vtDevice.end());
|
|
|
- if ( Heartbeat(url, stHeartbeatReq, stHeartbeatResp) )
|
|
|
- {
|
|
|
+ if ( Heartbeat(url, stHeartbeatReq, stHeartbeatResp) ) {
|
|
|
std::vector<SATParameters::STTask>::iterator it = stHeartbeatResp.vtTask.begin();
|
|
|
- for ( ; it != stHeartbeatResp.vtTask.end(); it++ )
|
|
|
- {
|
|
|
- if (!that->IsTaskExist(*it))
|
|
|
- {
|
|
|
+ for ( ; it != stHeartbeatResp.vtTask.end(); it++ ) {
|
|
|
+ if (!that->IsTaskExist(*it)) {
|
|
|
// 将任务压入队列中;
|
|
|
AutoThreadSection ats(&that->m_csTask);
|
|
|
// 同时下载任务;
|
|
|
std::string host = Global::g_stSATConfig.szCaseServer;
|
|
|
std::string url = host + "/ajaxInteractiveManage!getCaseFileListUrl.action";
|
|
|
std::vector<SATParameters::STCase>::iterator _case = it->Job.vtCases.begin();
|
|
|
- for ( ;_case != it->Job.vtCases.end(); _case++)
|
|
|
- {
|
|
|
+ for ( ;_case != it->Job.vtCases.end(); _case++) {
|
|
|
SATParameters::STScriptUrlResp stScriptUrlResp;
|
|
|
- if ( DownloadScript(url, _case->strId, Global::g_stSATConfig.szScriptDir, stScriptUrlResp) )
|
|
|
- {
|
|
|
+ if ( DownloadScript(url, _case->strId, Global::g_stSATConfig.szScriptDir, stScriptUrlResp) ) {
|
|
|
_case->_strFileDir = stScriptUrlResp._strFileDir;
|
|
|
_case->_strFileName = stScriptUrlResp._strFileName;
|
|
|
_case->_strScriptPath = stScriptUrlResp._strScripFile;
|
|
@@ -298,7 +768,12 @@ DWORD CSATExecutor::HearbeatThread(LPVOID lpVoid)
|
|
|
}
|
|
|
|
|
|
that->m_vtTask.push_back(*it);
|
|
|
+
|
|
|
+ // 通知SAT服务器,脚本开始执行;
|
|
|
// 待开发:同时将任务存储到数据库中;
|
|
|
+ /*
|
|
|
+ db process
|
|
|
+ */
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -311,66 +786,61 @@ DWORD CSATExecutor::HearbeatThread(LPVOID lpVoid)
|
|
|
DWORD CSATExecutor::ExecuteScriptThread(LPVOID lpVoid)
|
|
|
{
|
|
|
CSATExecutor *that = (CSATExecutor*)lpVoid;
|
|
|
- if ( !that )
|
|
|
- return 0;
|
|
|
+ if ( !that ) return 0;
|
|
|
|
|
|
- do
|
|
|
- {
|
|
|
+ do {
|
|
|
SATParameters::STTask *pTask = that->IsTaskProcess();
|
|
|
- if ( pTask )
|
|
|
- {// 有任务在执行中;
|
|
|
- if ( pTask->_bConcurrent )
|
|
|
- {// 并发;
|
|
|
+ if ( pTask ) {// 有任务在执行中;
|
|
|
+ if ( pTask->_bConcurrent ) {// 并发;
|
|
|
|
|
|
}
|
|
|
- else
|
|
|
- {// 串行,查询执行中的任务是否超时;
|
|
|
+ else {// 串行;
|
|
|
+ // 查询执行中的任务是否完成或超时;
|
|
|
SATParameters::STCase* pCase = that->IsCaseScriptProcess(pTask->Job.vtCases);
|
|
|
- if ( pCase )
|
|
|
- {
|
|
|
+ if ( pCase ) {
|
|
|
CScriptExecutor *pExcutor = (CScriptExecutor*)pCase->_pExcutor;
|
|
|
- if ( pExcutor )
|
|
|
- {
|
|
|
- if ( pExcutor->IsScriptOver() )
|
|
|
- {
|
|
|
+ if ( pExcutor ) {
|
|
|
+ if ( pExcutor->IsScriptOver() ) {
|
|
|
pCase->_nExecutionState = 2;
|
|
|
+ // 上报服务器,完成脚本用例,并上传用例结果;
|
|
|
+ that->ReportCaseResult(pTask, pCase);
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
+ else {
|
|
|
// 判断是否超时;
|
|
|
- if ( GetTickCount64() - pCase->_ulStartTickCount > 1800000 )
|
|
|
- {
|
|
|
+ ULONGLONG ulCurTickCount = GetTickCount64();
|
|
|
+ if ( ulCurTickCount - pExcutor->GetActiveTickCount() > 1800000) {
|
|
|
// 超时中断;
|
|
|
pCase->_nExecutionState = 3;
|
|
|
+ // 上报用例结果;
|
|
|
+ that->ReportCaseResult(pTask, pCase);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
+ else {
|
|
|
// 没有在执行的用例,开始执行新的用例;
|
|
|
- that->ExecuteFreeCaseScript(pTask);
|
|
|
+ pCase = that->ExecuteFreeCaseScript(pTask);
|
|
|
+ if ( NULL == pCase ) {
|
|
|
+ // 没有空闲的用例可执行,说明所有用例已执行完成;
|
|
|
+ pTask->_nExecutionState = 2;
|
|
|
+ // 上报任务结果;
|
|
|
+ that->UploadTaskLog(pTask);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- // 获取未执行的任务;
|
|
|
+ else {
|
|
|
+ // 获取空闲的任务;
|
|
|
pTask = that->GetFreeTask();
|
|
|
- if ( pTask)
|
|
|
- {
|
|
|
+ if ( pTask ) {
|
|
|
// 是否支持并发;
|
|
|
- if ( pTask->_bConcurrent )
|
|
|
- {
|
|
|
+ if ( pTask->_bConcurrent ) {
|
|
|
// 暂时全部一起并发;
|
|
|
std::vector<SATParameters::STCase>::iterator _case = pTask->Job.vtCases.begin();
|
|
|
- for ( ; _case != pTask->Job.vtCases.end(); _case++)
|
|
|
- {
|
|
|
- if (!_case->_pExcutor)
|
|
|
- {
|
|
|
+ for ( ; _case != pTask->Job.vtCases.end(); _case++) {
|
|
|
+ if (!_case->_pExcutor) {
|
|
|
CScriptExecutor *pExcutor = new CScriptExecutor();
|
|
|
- if ( pExcutor )
|
|
|
- {
|
|
|
+ if ( pExcutor ) {
|
|
|
_case->_pExcutor = pExcutor;
|
|
|
pExcutor->InitScript(_case->_strScriptPath, _case->_strFileDir + "\\" + _case->_strFileName + ".txt", "", SUBPROCESS);
|
|
|
pExcutor->StartScript();
|
|
@@ -383,15 +853,17 @@ DWORD CSATExecutor::ExecuteScriptThread(LPVOID lpVoid)
|
|
|
// 标记任务为执行中;
|
|
|
pTask->_nExecutionState = 1;
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
+ else {
|
|
|
// 是否有用例脚本在执行;
|
|
|
SATParameters::STCase* pCase = that->IsCaseScriptProcess(pTask->Job.vtCases);
|
|
|
- if ( !pCase )
|
|
|
- {
|
|
|
+ if ( !pCase ) {
|
|
|
+ // 执行空闲用例脚本;
|
|
|
that->ExecuteFreeCaseScript(pTask);
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 通知SAT服务器,脚本开始执行;
|
|
|
+ that->NotifyTaskStart(pTask);
|
|
|
}
|
|
|
}
|
|
|
} while ( WaitForSingleObject(that->m_hEventExcuteScript, 10000) == WAIT_TIMEOUT );
|