示例#1
0
 public static void SetResult(global::TestRail.Types.Test test, ResultStatus res, string message = "")
 {
     if (test.ID != null)
     {
         Client.AddResult((ulong)test.ID, res, message);
     }
 }
示例#2
0
        public static bool IsAutomated(global::TestRail.Types.Test test)
        {
            var automatedToken = test.JsonFromResponse.GetValue(ConfigHelper.TestRailConfig.AttrAutomation);

            if (automatedToken == null)
            {
                return(false);
            }

            return(automatedToken.ToString() == "3");
        }
示例#3
0
        public static string GetTag(global::TestRail.Types.Test test)
        {
            var tagToken = test.JsonFromResponse.GetValue(ConfigHelper.TestRailConfig.AttrTag).ToString();

            if (tagToken.Contains(","))
            {
                tagToken = tagToken.Split(',')[0];
            }

            return(tagToken);
        }
示例#4
0
 public static string GetFullFuncName(global::TestRail.Types.Test test)
 {
     return(test.JsonFromResponse.GetValue(ConfigHelper.TestRailConfig.AttrGit).ToString());
 }
        private static void RunTest(global::TestRail.Types.Test test)
        {
            MethodInfo method = null;

            var tag          = TestRail.GetTag(test);
            var tagDelimiter = '@';
            var tagVals      = tag.Split(tagDelimiter);

            var funcName  = tag.Contains(tagDelimiter) ? tagVals[0] : tag;
            var funcParam = tag.Contains(tagDelimiter) ? tagVals[1] : null;

            var caseId    = $"C{test.CaseID}";
            var screenUrl = TeamCity.GetScreenUrl();

            Program.Logger.Info($" +++++ Run:  {funcName}-{funcParam??""}, {caseId}, {screenUrl}");

            try
            {
                var type = Asm.GetTypes().First(x => (method = GetMethod(x, funcName, caseId)) != null);

                if (type == null)
                {
                    throw new Exception("[Type] is not defined.");
                }

                if (method == null)
                {
                    throw new Exception("[Method] is not defined.");
                }

                var classInstance = Activator.CreateInstance(type);

                var setupMethod =
                    type.GetMethods()
                    .FirstOrDefault(x => x.GetCustomAttributes().Any(atr => atr.GetType().Name == "SetUpAttribute"));
                var teardownMethod =
                    type.GetMethods()
                    .FirstOrDefault(
                        x => x.GetCustomAttributes().Any(atr => atr.GetType().Name == "TearDownAttribute"));

                if (setupMethod != null)
                {
                    ExecMethod(classInstance, setupMethod);
                }

                ExecMethod(classInstance, method, funcParam);

                //if (teardownMethod != null)
                //    ExecMethod(type, teardownMethod);

                TestRail.SetResult(test, ResultStatus.Passed);
                Program.Logger.Info("Success:");
            }
            catch (Exception e)
            {
                if (method == null)
                {
                    TestRail.SetResult(test, ResultStatus.Failed, e.Message);
                    Program.Logger.Info($"Error: {e.Message}");
                    return;
                }

                var screeenFile = $"{screenUrl}/{method.Name}.png";
                var exc         = e.InnerException ?? e;

                var message = exc.Message + Environment.NewLine +
                              screeenFile + Environment.NewLine +
                              exc.StackTrace + Environment.NewLine;

                Program.Logger.Info($"Error: {message}");
                TestRail.SetResult(test, ResultStatus.Failed, message);

                WebDriverHelper.CreateScreenshot(method.Name, false);
            }
        }