예제 #1
0
        private void RunOneIteration(TestCase testCase)
        {
            string        className     = string.Empty;
            Assembly      assembly      = Assembly.GetEntryAssembly();
            CategoryClass categoryClass = ExecutionSession.lstCategoryClass.First(category => category.CategoryName.ToLower().Trim() == testCase.Category.ToLower().Trim());

            className = "TB2." + categoryClass.ClassName;
            Type   type          = assembly.GetType(className);
            object classInstance = Activator.CreateInstance(type, testCase);

            MethodInfo methodInfo;

            methodInfo = type.GetMethod("GenerateHeader");
            if (methodInfo != null)
            {
                methodInfo.Invoke(classInstance, null);
            }
            string methodName = testCase.TestCaseName.Replace(" ", "_");

            methodInfo = type.GetMethod(methodName);
            if (methodInfo != null)
            {
                try
                {
                    methodInfo.Invoke(classInstance, null);
                }
                catch (TargetInvocationException ex)
                {
                    Logger.Log(testCase, ex.ToString());
                    methodInfo = type.GetMethod("AddErrorStep");
                    if (methodInfo != null)
                    {
                        methodInfo.Invoke(classInstance, null);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex.ToString());
                }
            }

            methodInfo = type.GetMethod("GenerateFooter");
            if (methodInfo != null)
            {
                methodInfo.Invoke(classInstance, null);
            }
            //methodInfo = type.GetMethod("EndTestCase");
            //if (methodInfo != null)
            //{
            //    methodInfo.Invoke(classInstance, null);
            //}

            ExecutionSession.TestCaseExecuted = ExecutionSession.TestCaseExecuted + 1;
        }
예제 #2
0
        private void RunMultipleIterations(TestCase testCase, int iterationCount)
        {
            string        className     = string.Empty;
            Assembly      assembly      = Assembly.GetEntryAssembly();
            CategoryClass categoryClass = ExecutionSession.lstCategoryClass.First(category => category.CategoryName == testCase.Category);

            className = "AutomationFramework." + categoryClass.ClassName;
            Type       type          = assembly.GetType(className);
            object     classInstance = Activator.CreateInstance(type, testCase);
            MethodInfo methodInfo;

            methodInfo = type.GetMethod("SetTotalIterationCount");
            if (methodInfo != null)
            {
                object[]        paramArray = new object[] { iterationCount };
                ParameterInfo[] parameters = methodInfo.GetParameters();
                methodInfo.Invoke(classInstance, paramArray);
            }
            methodInfo = type.GetMethod("GenerateHeader");
            if (methodInfo != null)
            {
                methodInfo.Invoke(classInstance, null);
            }
            string methodName = testCase.TestCaseName.Replace(" ", "_");

            for (int i = 1; i <= iterationCount; i++)
            {
                Console.WriteLine("Current Iteration");
                methodInfo = type.GetMethod("SetToCurrentIteration");
                if (methodInfo != null)
                {
                    object[]        paramArray = new object[] { i };
                    ParameterInfo[] parameters = methodInfo.GetParameters();
                    methodInfo.Invoke(classInstance, paramArray);
                }
                Thread.Sleep(1000);
                methodInfo = type.GetMethod(methodName);
                if (methodInfo != null)
                {
                    methodInfo.Invoke(classInstance, null);
                }
            }
            methodInfo = type.GetMethod("GenerateFooter");
            if (methodInfo != null)
            {
                methodInfo.Invoke(classInstance, null);
            }
            ExecutionSession.TestCaseExecuted = ExecutionSession.TestCaseExecuted + 1;
        }
예제 #3
0
        public static void AddCategoryClassList()
        {
            XmlDocument xmlCategoryClassConfig = new XmlDocument();

            xmlCategoryClassConfig.Load(categoryClassXmlPath);
            if (!(xmlCategoryClassConfig == null))
            {
                ExecutionSession.lstCategoryClass = new List <CategoryClass>();
                CategoryClass categoryClass;
                XmlNodeList   categoryFields = xmlCategoryClassConfig.SelectNodes("Category/var");

                foreach (XmlNode headerField in categoryFields)
                {
                    categoryClass = new CategoryClass();
                    categoryClass.CategoryName = headerField.Attributes["category"].Value;
                    categoryClass.ClassName    = headerField.Attributes["classname"].Value;
                    ExecutionSession.lstCategoryClass.Add(categoryClass);
                }
            }
        }