Browse Source

添加自动化测试

denny 1 year ago
parent
commit
4327b5ffef

+ 1 - 1
Tools/Flyinsono.Client.AutoTestApplication/AutoTestApplication.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <OutputType>Exe</OutputType>
-    <TargetFramework>netcoreapp3.1</TargetFramework>
+    <TargetFramework>net6.0-windows</TargetFramework>
   </PropertyGroup>
 
   <ItemGroup>

+ 3 - 2
Tools/Flyinsono.Client.AutoTestApplication/AutoTestService.cs

@@ -28,7 +28,8 @@ namespace AutoTestApplication
                 //开始比较版本,并copy文件
                 CheckAndCopyFile();
                 var scheduledBeginTime = DateTime.Now;
-                var outputResult = ProcessStarter.StartCmdProcess(CommonConfigManager.ExcuteCmdConfig);
+                var outputResult = ProcessStarter.StartCmdProcess(CommonConfigManager.ExcuteCmdConfig); 
+                Console.WriteLine("执行结果:" + outputResult);
                 var scheduledEndTime = DateTime.Now;
                 //记录今日执行次数
                 if (curDateRecord == null)
@@ -53,7 +54,7 @@ namespace AutoTestApplication
                 }
                 else
                 {
-                    Console.WriteLine(scheduledEndTime.ToString("yyyy-MM-dd HH:mm:ss") + ":执行自动化测试报告Fail");
+                    Console.WriteLine(scheduledEndTime.ToString("yyyy-MM-dd HH:mm:ss") + ":" + CommonConfigManager.ExcuteCmdConfig + "执行自动化测试报告Fail");
                 }
             }
             catch (Exception ex)

+ 0 - 1
Tools/Flyinsono.Client.AutoTestApplication/Program.cs

@@ -8,7 +8,6 @@ namespace AutoTestApplication
         {
             var service = new AutoTestService();
             service.RunRobotFrameworkReport();
-            Console.ReadLine();
         }
     }
 }

+ 1 - 1
Tools/Flyinsono.DBCopy.Tool/Config/TestConfig.json

@@ -73,7 +73,7 @@
   "FilterCourses": [ "test", "ceshi", "tst", "测试", "Connie", "Denny", "Loki", "Nancy", "Riley", "Smith", "demo", "hi", "hahha", "直播", "培训", "啊打发打发", "new" ],
   "FilterPatients": [ "test", "ceshi", "tst", "测试", "Connie", "Denny", "Loki", "Nancy", "Riley", "Smith", "张帅" ],
   "FilterReportPosters": [ "test", "ceshi", "tst", "测试", "Connie", "Denny", "Loki", "Nancy", "Riley", "Smith", "张帅" ],
-  "FilterPatientType": [ "动物", "宠物" ],
+  "FilterPatientType": [ "动物", "宠物", "Animal" ],
   "FilterAgent": [ "代理商", "agent" ],
   "FilterGeneral": {
     "ClearTime": "2023-04-19",

+ 30 - 2
src/WingDeployPlatformService/Common/ProcessStarter.cs

@@ -6,10 +6,10 @@ namespace WingDeployPlatformService.Common
 {
     public class ProcessStarter
     {
-         /// <summary>
+        /// <summary>
         /// 开始执行CMD命令程序
         /// </summary>
-        /// <param name="processName">工具程序名称</param>
+        /// <param name="cmdStr">工具程序名称</param>
         public static string StartCmdProcess(string cmdStr)
         {
             try
@@ -34,5 +34,33 @@ namespace WingDeployPlatformService.Common
                 return "";
             }
         }
+
+        /// <summary>
+        /// 开始执行自动化测试命令程序
+        /// </summary>
+        /// <param name="path">路径</param>
+        public static string StartProcess(string path)
+        {
+            try
+            {
+                Process process = new Process();
+                process.StartInfo.FileName = path;
+                process.StartInfo.CreateNoWindow  = true;
+                process.StartInfo.UseShellExecute  = false;
+                process.StartInfo.RedirectStandardInput = true; //重定向输入,
+                process.StartInfo.RedirectStandardOutput = true; //重定向输出,
+                process.StartInfo.RedirectStandardError = true;
+                process.Start();//执行 
+                var result = process.StandardOutput.ReadToEnd();//获取返回值   
+                process.WaitForExit();//等待程序执行完退出进程   
+                process.Close();//结束
+                return result;
+            }
+            catch(Exception ex)
+            {
+                Console.WriteLine("执行自动化测试命令程序异常:" + path + ",ex: "+ ex.Message);
+                return "";
+            }
+        }
     }
 }

+ 35 - 6
src/WingDeployPlatformService/DeployPlatformService.cs

@@ -74,12 +74,12 @@ namespace WingDeployPlatformService
 
         public override void LoadAfterRegister()
         {
-            var isDeployTool = ConfigurationManager.GetParammeter<BoolParameter>("General", "IsDeployTool").Value;
-            if (!isDeployTool)
-            {
-                //定时执行发送自动化测试报告
-                CallPySet();
-            }
+            // var isDeployTool = ConfigurationManager.GetParammeter<BoolParameter>("General", "IsDeployTool").Value;
+            // if (!isDeployTool)
+            // {
+            //     //定时执行发送自动化测试报告
+            //     CallPySet();
+            // }
         }
 
 
@@ -227,6 +227,35 @@ namespace WingDeployPlatformService
         }
 
         #region 打包记录
+        /// <summary>
+        /// 运行自动化测试应用
+        /// </summary>
+        /// <returns></returns>
+        public async Task<bool> RunAutoTestApplication()
+        {
+            var result = false;
+            try
+            {
+                var path = EnvironmentConfigManager.GetParammeter<StringParameter>("Deploy", "AutoTestToolsPath").Value;
+                var outputResult = ProcessStarter.StartProcess(path);
+                var scheduledTimeStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+                if (outputResult.IndexOf("Success") > 0)
+                {
+                    result = true;
+                    WriteLog(scheduledTimeStr + ":执行自动化测试报告Success");
+                }
+                else
+                {
+                    WriteLog(scheduledTimeStr + ":执行自动化测试报告Fail");
+                }
+            }
+            catch (Exception ex)
+            {
+                WriteLog("RunAutoTestApplication异常:" + ex.Message);
+                return false;
+            }
+            return result;
+        }
 
         /// <summary>
         /// 查询打包记录

+ 2 - 1
src/appsettings.json

@@ -133,7 +133,8 @@
     "HourValue": 14,
     "MinuteValue": 10,
     "IntervalMinutes": 3000000,
-    "CmdStr": "robot --listener \"C:\\Program Files\\Python37\\Lib\\site-packages\\CustomLibrary\\PythonListener.py\" --argumentfile C:\\Users\\VINNO\\AppData\\Local\\Temp\\RIDE8a44u3_n.d\\argfile.txt E:\\robotFramework\\FlyinsonoRobotFrameworkApi"
+    "CmdStr": "robot --listener \"C:\\Program Files\\Python37\\Lib\\site-packages\\CustomLibrary\\PythonListener.py\" --argumentfile C:\\Users\\VINNO\\AppData\\Local\\Temp\\RIDE8a44u3_n.d\\argfile.txt E:\\robotFramework\\FlyinsonoRobotFrameworkApi",
+    "AutoTestToolsPath": "D:\\Project\\git\\wingsolutionMasterBug\\WingCloudServer\\Tools\\Flyinsono.Client.AutoTestApplication\\bin\\Debug\\net6.0-windows\\AutoTestApplication.exe"
   },
   "AppletAPI":{
     "VCloudClientsProxyHost":"192.168.6.6:9096"