private void SaveJson(TestResultInfo dirInfo, string basePath)
        {
            var filesPath = Path.Combine(basePath, dirInfo.DirId);

            dirInfo.Files = Directory.EnumerateFiles(filesPath, "*.png").Select(c => Path.GetFileName(c)).ToArray();

            var jsonStr  = Newtonsoft.Json.JsonConvert.SerializeObject(dirInfo);
            var fileName = Path.Combine(basePath, $"{dirInfo.DirId}.json");

            File.WriteAllText(fileName, jsonStr);
        }
        private void MethodInfoInvole(RemoteWebDriver driver, string basepath, TestResultInfo dirInfo, SeleniumTestBase instance, MethodInfo mi, object[] param)
        {
            try
            {
                mi.Invoke(instance, param);
            }
            catch (Exception e)
            {
                dirInfo.Exceptions.Add(new ErrorInfo
                {
                    ClassName = mi.DeclaringType.Name,
                    TestName  = mi.Name,
                    Message   = e.ToString(),
                });
            }
            dirInfo.ExecutedIndex++;
            SaveJson(dirInfo, basepath);
            try
            {
                var imgName = GenFileName(mi, param);
                var imgPath = Path.Combine(basepath, dirInfo.DirId, imgName);


                ScreenShotHelper.Capture(driver, imgPath);

                foreach (var item in instance.Errors)
                {
                    item.ClassName = mi.DeclaringType.Name;
                    item.TestName  = mi.Name;
                }

                dirInfo.Errors.AddRange(instance.Errors);
                instance.Errors.Clear();
                SaveJson(dirInfo, basepath);
            }
            catch
            {
            }
        }
        internal string TestStart(DriverType driverType, string basePath, string baseUrl, string className, string methodName)
        {
            //throw new NotImplementedException();
            var id       = $"{DateTimeOffset.Now:yyyyMMddHHmmss}";
            var savePath = Path.Combine(basePath, id);

            Directory.CreateDirectory(savePath);

            var dirInfo = new TestResultInfo
            {
                DirId       = id,
                Files       = new string[0],
                IsExecuting = true,
                Exceptions  = new List <ErrorInfo>(),
                Errors      = new List <ErrorInfo>(),
                BaseUrl     = baseUrl
            };
            var testClasses = EnumSubClass <SeleniumTestBase>();

            if (!string.IsNullOrEmpty(className))
            {
                testClasses = testClasses.Where(c => c.Name == className).ToArray();
            }



            dirInfo.TestCount = CalcTestCount(testClasses, methodName);
            SaveJson(dirInfo, basePath);

            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                using (var driver = GetWebDriver(driverType))
                {
                    foreach (var type in testClasses)
                    {
                        var instance = (SeleniumTestBase)Activator.CreateInstance(type);
                        instance.Setup(driver, baseUrl);
                        instance.Init();

                        foreach (var methodInfo in EnumTestMethods(type))
                        {
                            if (!string.IsNullOrEmpty(methodName))
                            {
                                if (methodInfo.Name != methodName)
                                {
                                    continue;
                                }
                            }


                            var paramAttris = methodInfo.GetCustomAttributes <TestParamAttribute>().ToArray();
                            if (paramAttris.Length == 0)
                            {
                                instance.SetScreenShotPathTemplate(GenFileNameTemplatePath(savePath, methodInfo, null));

                                MethodInfoInvole(driver, basePath, dirInfo, instance, methodInfo, null);
                            }
                            else
                            {
                                foreach (var item in paramAttris)
                                {
                                    instance.SetScreenShotPathTemplate(GenFileNameTemplatePath(savePath, methodInfo, item.Args));
                                    MethodInfoInvole(driver, basePath, dirInfo, instance, methodInfo, item.Args);
                                }
                            }
                        }
                        dirInfo.Errors.AddRange(instance.Errors);
                        SaveJson(dirInfo, basePath);
                    }
                }
                dirInfo.IsExecuting = false;
                SaveJson(dirInfo, basePath);

                //テストが全部終了したとき

                //
            });
            return(id);
        }