예제 #1
0
        /// <summary>
        /// Method for getting all the Test Cases for a Project for all the suites
        /// </summary>
        /// <returns></returns>
        public Dictionary <string, string> GetAllTestCasesFromAllSuites()
        {
            Gurock.TestRail.APIClient client         = GetTestRailClientConfig();
            string        ProjectId                  = GetProjectID();
            List <string> SuiteIds                   = GetAllSuiteIds();
            Dictionary <string, string> AllTestCases = new Dictionary <string, string>();

            try
            {
                foreach (string SuiteId in SuiteIds)
                {
                    _testRailUtilsLog.Info("===fetching test cases for suite:=>" + SuiteId);
                    JArray response = (JArray)client.SendGet("get_cases/" + ProjectId + "&suite_id=" + SuiteId);
                    for (int i = 0; i < response.LongCount(); i++)
                    {
                        JObject Case = (JObject)response.ElementAt(i);
                        AllTestCases.Add(Case.GetValue("id").ToString(), Case.GetValue("title").ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                _testRailUtilsLog.Error(ex);
            }

            return(AllTestCases);
        }
예제 #2
0
        /// <summary>
        /// Method for getting all the RunIDs for a specific Project and Specific to Milestone
        /// </summary>
        /// <param name="MilestoneId"></param>
        /// <returns></returns>
        public List <string> GetRunIdsForProjectAndMileStone(String MilestoneId)
        {
            string ProjectId = GetProjectID();

            Gurock.TestRail.APIClient client = GetTestRailClientConfig();
            JArray        response           = null;
            List <string> runs = new List <string>();

            try
            {
                response = (JArray)client.SendGet("get_runs/" + ProjectId);
                for (int i = 0; i < response.LongCount(); i++)
                {
                    JObject sections     = (JObject)response.ElementAt(i);
                    Object  milestone_id = sections.GetValue("milestone_id");
                    if (milestone_id != null)
                    {
                        if (sections.GetValue("milestone_id").ToString().Equals(MilestoneId))
                        {
                            runs.Add(sections.GetValue("id").ToString());
                            continue;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _testRailUtilsLog.Error(ex);
            }
            return(runs);
        }
예제 #3
0
 /// <summary>
 /// Method for Posting the Test status and failure information(if any) to Test Rail
 /// </summary>
 /// <param name="client"></param>
 /// <param name="RunId"></param>
 /// <param name="TestCaseId"></param>
 /// <param name="testResult"></param>
 public void PostResultToTestRail(Gurock.TestRail.APIClient client, string RunId, Dictionary <string, Object> testResult)
 {
     //RunId = GetRunId();
     TestCaseId = GetTestCase();
     try
     {
         client.SendPost("add_result_for_case/" + RunId + "/" + TestCaseId + "", testResult);
         _testRailUtilsLog.Info("Client Post is successfull");
     }
     catch (Exception ex)
     {
         _testRailUtilsLog.Error("Unable to Post the result to Test rail" + ex);
     }
 }
예제 #4
0
 /// <summary>
 /// Method for getting the Project Name from Config file for Test Rail Client
 /// </summary>
 /// <returns></returns>
 public string GetProjectName()
 {
     try
     {
         Gurock.TestRail.APIClient client = GetTestRailClientConfig();
         string ProjectName = _autoutilities.GetKeyValue("TestRailConfig", "ProjectName");
         return(ProjectName);
     }
     catch (Exception ex)
     {
         _testRailUtilsLog.Error("Unable to get the Project Name from the Config " + ex);
     }
     return(null);
 }
예제 #5
0
 /// <summary>
 /// Method for getting the the Client Password for Test Rail Account
 /// </summary>
 /// <param name="client"></param>
 /// <returns></returns>
 public string GetUserClientPwd(Gurock.TestRail.APIClient client)
 {
     try
     {
         client.Password = _autoutilities.GetKeyValue("TestRailConfig", "UserClientPwd");
         _testRailUtilsLog.Info("UserClientPassword" + client.Password);
         return(client.Password);
     }
     catch (Exception ex)
     {
         _testRailUtilsLog.Error("Unable to get the User Client Password " + ex);
         return(null);
     }
 }
예제 #6
0
 /// <summary>
 /// Method for getting the the Client User name for Test Rail Account
 /// </summary>
 /// <param name="client"></param>
 /// <returns></returns>
 public string GetUserClientName(Gurock.TestRail.APIClient client)
 {
     try
     {
         client.User = _autoutilities.GetKeyValue("TestRailConfig", "UserClientName");
         _testRailUtilsLog.Info("UserClientName" + client.User);
         return(client.User);
     }
     catch (Exception ex)
     {
         _testRailUtilsLog.Error("Exception occured while retrieving the Client name " + ex);
         return(null);
     }
 }
예제 #7
0
        /// <summary>
        /// Method for getting All the test cases which is under a Project and a Suite
        /// </summary>
        /// <returns>Dictionary<string,string></returns>
        public Dictionary <string, string> GetAllTestCases()
        {
            Gurock.TestRail.APIClient client = GetTestRailClientConfig();
            string ProjectId = GetProjectID();
            string SuiteId   = GetSuiteId();
            Dictionary <string, string> AllTestCases = new Dictionary <string, string>();
            JArray response = (JArray)client.SendGet("get_cases/" + ProjectId + "&suite_id=" + SuiteId);

            for (int i = 0; i < response.LongCount(); i++)
            {
                JObject Case = (JObject)response.ElementAt(i);
                AllTestCases.Add(Case.GetValue("id").ToString(), Case.GetValue("title").ToString());
            }
            return(AllTestCases);
        }
예제 #8
0
 /// <summary>
 /// Method for fetching the Test Rail Client configuration from the Config file
 /// </summary>
 /// <returns></returns>
 public Gurock.TestRail.APIClient GetTestRailClientConfig()
 {
     Gurock.TestRail.APIClient client = null;
     try
     {
         client = GetClientServerUrl();
         string UserClientName = GetUserClientName(client);
         string UserClientPwd  = GetUserClientPwd(client);
         _testRailUtilsLog.Info("UserClientName" + UserClientName);
         _testRailUtilsLog.Info("UserClientPwd" + UserClientPwd);
         _testRailUtilsLog.Info("Client" + client);
     }
     catch (Exception ex)
     {
         _testRailUtilsLog.Error("Unable to fetch the Client configuration from the Config File");
         _testRailUtilsLog.Error(ex);
     }
     return(client);
 }
예제 #9
0
        /// <summary>
        /// Method for getting all the TestRuns for Certain ProjectID
        /// </summary>
        /// <param name="ProjectId"></param>
        /// <returns></returns>


        public Dictionary <string, string> GetAllRunsForAProject(string ProjectId)
        {
            Gurock.TestRail.APIClient   client  = GetTestRailClientConfig();
            Dictionary <string, string> AllRuns = new Dictionary <string, string>();

            try
            {
                JArray response = (JArray)client.SendGet("get_runs/" + ProjectId + "");
                for (int i = 0; i < response.LongCount(); i++)
                {
                    JObject Run = (JObject)response.ElementAt(i);
                    AllRuns.Add(Run.GetValue("id").ToString(), Run.GetValue("name").ToString());
                }
            }
            catch (Exception ex)
            {
                _testRailUtilsLog.Error(ex);
            }
            return(AllRuns);
        }
예제 #10
0
        /// <summary>
        /// Method for all the Projects Name and their unique IDs for TestRail Client.
        /// </summary>
        /// <returns></returns>
        public Dictionary <string, string> GetAllProjects()
        {
            Gurock.TestRail.APIClient   client      = GetTestRailClientConfig();
            Dictionary <string, string> AllProjects = new Dictionary <string, string>();

            try
            {
                JArray response = (JArray)client.SendGet("get_projects");
                for (int i = 0; i < response.LongCount(); i++)
                {
                    JObject project = (JObject)response.ElementAt(i);
                    AllProjects.Add(project.GetValue("id").ToString(), project.GetValue("name").ToString());
                }
            }
            catch (Exception ex)
            {
                _testRailUtilsLog.Error(ex);
            }
            return(AllProjects);
        }
예제 #11
0
        /// <summary>
        /// Method for getting all the Test Case IDs for a particular Test Run
        /// </summary>
        /// <param name="RunId"></param>
        /// <returns></returns>
        public List <String> getCaseIdsForRun(String RunId)
        {
            Gurock.TestRail.APIClient client  = GetTestRailClientConfig();
            List <String>             caseIds = new List <String>();
            JArray response = null;

            try
            {
                response = (JArray)client.SendGet("get_tests/" + RunId);
                for (int i = 0; i < response.LongCount(); i++)
                {
                    JObject obj = (JObject)response.ElementAt(i);
                    caseIds.Add(obj.GetValue("case_id").ToString());
                }
            }
            catch (Exception ex)
            {
                _testRailUtilsLog.Error(ex);
            }
            return(caseIds);
        }
예제 #12
0
        /// <summary>
        /// Method for adding new MileStone to the project specfied in the Config File
        /// </summary>
        public string AddNewMileStone()
        {
            try
            {
                Gurock.TestRail.APIClient   client = GetTestRailClientConfig();
                Dictionary <string, object> data   = new Dictionary <string, object>();
                string MileStoneName = GenerateTestRunName("MileStone--");
                string Project_Id    = GetProjectID();
                data.Add("name", MileStoneName);
                string SuiteId = GetSuiteId();
                data.Add("include_all", 1);
                data.Add("suite_id", SuiteId);
                client.SendPost("add_milestone/" + Project_Id, data);//2
                _testRailUtilsLog.Info("Added New Milestone for Project ID : " + Project_Id + " Named as : " + MileStoneName);
                return(MileStoneName);
            }

            catch (Exception ex)
            {
                _testRailUtilsLog.Error("Unable to add new Milestone " + ex);
                return("");
            }
        }
예제 #13
0
        /// <summary>
        /// Method for getting all the MileStones for a specific Project
        /// </summary>
        /// <returns></returns>
        public Dictionary <string, string> GetAllMilestones()
        {
            string ProjectId = GetProjectID();

            Gurock.TestRail.APIClient   client     = GetTestRailClientConfig();
            Dictionary <string, string> milestones = new Dictionary <string, string>();
            JArray response = null;

            try
            {
                response = (JArray)client.SendGet("get_milestones/" + ProjectId);
                for (int i = 0; i < response.LongCount(); i++)
                {
                    JObject suite = (JObject)response.ElementAt(i);
                    milestones.Add(suite.GetValue("id").ToString(), suite.GetValue("name").ToString());
                }
            }
            catch (Exception ex)
            {
                _testRailUtilsLog.Error(ex);
            }
            return(milestones);
        }
예제 #14
0
        /// <summary>
        /// Method for generating a New Test Run Configuration at run time and Posting to the
        /// TestRail
        /// </summary>
        /// <returns>string</returns>

        public string AddTestRun()
        {
            try
            {
                Gurock.TestRail.APIClient   client = GetTestRailClientConfig();
                Dictionary <string, object> data   = new Dictionary <string, object>();
                string RunName     = GenerateTestRunName("TestRun-");
                string Project_Id  = GetProjectID();
                string MileStoneID = GetMileStone();
                string SuiteId     = GetSuiteId();
                data.Add("milestone_id", MileStoneID);
                data.Add("name", RunName);
                data.Add("include_all", 1);
                data.Add("suite_id", SuiteId);
                client.SendPost("add_run/" + Project_Id, data);//2
                return(RunName);
            }
            catch (Exception ex)
            {
                _testRailUtilsLog.Error("Unable to Add new Test Run " + ex);
                return(null);
            }
        }
예제 #15
0
        public void PostResultToTestRailUsingMileStones(Gurock.TestRail.APIClient client, Dictionary <string, Object> testResult)
        {
            string         MileStoneId = GetMileStoneId();
            IList <string> RunIds      = new List <string>();

            RunIds = GetRunIdsForProjectAndMileStone(MileStoneId);
            _testRailUtilsLog.Info("=====>>>>" + RunIds.ToString());
            _testRailUtilsLog.Info("size:=>" + RunIds.Count);
            foreach (string RunId in RunIds)
            {
                _testRailUtilsLog.Info("==>" + RunId);
                // _testRailUtilsLog.Info("&&" + RunId + "/" + TestCaseId);
                IList <string> TestCaseId = getCaseIdsForRun(RunId);
                foreach (string CaseId in TestCaseId)
                {
                    if (CaseId.Equals(GetTestCase()))
                    {
                        client.SendPost("add_result_for_case/" + RunId + "/" + CaseId + "", testResult);
                    }
                }
                _testRailUtilsLog.Info("Client Post is successfull");
            }
        }