Пример #1
0
        private static void RunTests(ulong testRun)
        {
            var testsList = TestRail.GetTestList(testRun);

            if (testsList.Count == 0)
            {
                throw new Exception($"There are no tests in Run [{testRun}]");
            }

            //WebDriverHelper.DeleteScreenshot();
            TestExecutor.RunTests(testsList);
        }
        private static void RunTest(TestInfo testInfo)
        {
            //Program.Logger.Info($" +++++ Run:  {testInfo.TestMethod}({testInfo.FuncParam ?? ""}), {testInfo.TestRailInfo.CaseID}, {ScreenUrl}");
            Program.Logger.Info($" +++++ Run:  {testInfo.TestMethod}({testInfo.FuncParam ?? ""}), {testInfo.TestRailInfo.CaseID}");

            var classInstance = Activator.CreateInstance(testInfo.TestClass);

            //Program.Logger.Info("--- Test.Setup");
            ExecMethod(classInstance, testInfo.SetupMethod);

            try
            {
                //Program.Logger.Info("--- Test.Run");
                ExecMethod(classInstance, testInfo.TestMethod, testInfo.FuncParam);

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

                var screeenFile = $"{ScreenUrl}/{testInfo.TestMethod.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(testInfo.TestRailInfo, ResultStatus.Failed, message);

                WebDriverHelper.CreateScreenshot(testInfo.TestMethod.Name, false);
            }
            finally
            {
                //Program.Logger.Info("--- Test.Teardown");
                ExecMethod(classInstance, testInfo.TeardownMethod);
            }
        }
        private static void AddTests(ulong testRun)
        {
            var testsList = TestRail.GetTestList(testRun);

            if (testsList.Count == 0)
            {
                throw new Exception($"There are no tests in Run [{testRun}]");
            }

            foreach (var test in testsList)
            {
                foreach (var asm in Assemblies)
                {
                    MethodInfo method = null;

                    var tag       = TestRail.GetTag(test);
                    var tagVals   = tag.Split('@');
                    var funcName  = tagVals[0];
                    var funcParam = tagVals.Length > 1 ? tagVals[1] : null;
                    var caseId    = $"C{test.CaseID}";

                    var type = asm.Assembly.GetTypes().FirstOrDefault(x => (method = GetMethod(x, funcName, caseId)) != null);

                    if (type == null || method == null)
                    {
                        continue;
                    }

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

                    asm.TestsList.Add(new TestInfo()
                    {
                        TestRailInfo   = test,
                        TestClass      = type,
                        TestMethod     = method,
                        SetupMethod    = setupMethod,
                        TeardownMethod = teardownMethod,
                        FuncParam      = funcParam
                    });
                }
            }
        }
Пример #4
0
        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);
            }
        }