/// <summary>
        /// The SetTestSetByUID.
        /// </summary>
        /// <param name="uID">The UID<see cref="int"/>.</param>
        /// <returns>The <see cref="TestSetInstance"/>.</returns>
        public TestSetInstance SetTestSetByUID(int uID)
        {
            // create a new filter filtering out by UID
            TestSetFactory factory = this.connection.TestSetFactory as TestSetFactory;
            TDFilter       filter  = factory.Filter as TDFilter;

            try
            {
                filter[ALMUID] = uID.ToString();
            }
            catch (Exception)
            {
            }

            List list = filter.NewList(); // filters out testset by UID

            if (list.Count == 1)
            {
                this.TestSet = new TestSetInstance(list[1] as TestSet, this.Username);
            }
            else
            {
                throw new CannotFindTestSet(CannotFindTestSet.ErrorMsg + uID);
            }

            return(this.TestSet);
        }
Exemple #2
0
        /// <summary>
        /// This method will download an attachment from a folder in Quality Center
        /// </summary>
        /// <param name="qcFolderLocation">Folder Location from where attachment needs to be downloaded</param>
        /// <param name="strFileName">Name of the file that needs to be downloaded from specified location.
        /// Name should be specified along with extenstion </param>
        /// <returns>Location of local (usually temp) path where file has been downloaded. Returns empty string if file could not be downloaded.</returns>
        public string DownloadAttachment(string qcFolderLocation, string strFileName)
        {
            //Connect with Quality Center
            TDConnection qctd = new TDConnection();

            qctd.InitConnectionEx(qcServer);
            qctd.ConnectProjectEx(strDomainName, strProjectName, strQCUserName, strQCUserPassword);

            if (qctd.Connected)
            {
                //Define objects that will be used to download files
                SubjectNode       otaSysTreeNode       = new SubjectNode();
                AttachmentFactory otaAttachmentFactory = new AttachmentFactory();
                TDFilter          otaAttachmentFilter  = new TDFilter();
                List            otaAttachmentList      = new List();
                ExtendedStorage attStorage             = new ExtendedStorage();

                otaSysTreeNode       = qctd.TreeManager.NodeByPath(qcFolderLocation); //Returns node object from test plan in Quality Center
                otaAttachmentFactory = otaSysTreeNode.Attachments();                  //Returns all attachments for the folder in QC
                otaAttachmentFilter  = otaAttachmentFactory.Filter();                 //Can be used to filter list of attachments
                otaAttachmentList    = otaAttachmentFilter.NewList();                 //Creates list of attached files

                //Check if there is any attachment available for the specified folder
                if (otaAttachmentList.Count > 0)
                {
                    foreach (Attachment otaAttachment in otaAttachmentList)
                    {
                        //Check if file names are same
                        if (otaAttachment.FileName.ToLower() == strFileName.ToLower())
                        {
                            attStorage         = otaAttachment.AttachmentStorage();
                            _localFileLocation = otaAttachment.DirectLink;

                            //Load method will download file to local workstation. true to used for synchronised download.
                            attStorage.Load(_localFileLocation, true);

                            //Client path refers to local path where file has been downloaded
                            _localFileLocation = attStorage.ClientPath;
                            break;
                        }
                    }
                }
            }

            //Return empty string if connection to QC was not successfull.
            else
            {
                _localFileLocation = string.Empty;
            }

            return(_localFileLocation);
        }
Exemple #3
0
        /// <summary>
        /// This method will download an attachment from a folder in Quality Center
        /// </summary>
        /// <param name="qcFolderLocation">Folder Location from where attachment needs to be downloaded</param>
        /// <param name="strFileName">Name of the file that needs to be downloaded from specified location. 
        /// Name should be specified along with extenstion </param>
        /// <returns>Location of local (usually temp) path where file has been downloaded. Returns empty string if file could not be downloaded.</returns>
        public string DownloadAttachment(string qcFolderLocation, string strFileName)
        {
            //Connect with Quality Center
            TDConnection qctd = new TDConnection();
            qctd.InitConnectionEx(qcServer);
            qctd.ConnectProjectEx(strDomainName, strProjectName, strQCUserName, strQCUserPassword);

            if (qctd.Connected)
            {
                //Define objects that will be used to download files
                SubjectNode otaSysTreeNode = new SubjectNode();
                AttachmentFactory otaAttachmentFactory = new AttachmentFactory();
                TDFilter otaAttachmentFilter = new TDFilter();
                List otaAttachmentList = new List();
                ExtendedStorage attStorage = new ExtendedStorage();

                otaSysTreeNode = qctd.TreeManager.NodeByPath(qcFolderLocation);     //Returns node object from test plan in Quality Center
                otaAttachmentFactory = otaSysTreeNode.Attachments();                //Returns all attachments for the folder in QC
                otaAttachmentFilter = otaAttachmentFactory.Filter();                //Can be used to filter list of attachments
                otaAttachmentList = otaAttachmentFilter.NewList();                  //Creates list of attached files

                //Check if there is any attachment available for the specified folder
                if (otaAttachmentList.Count > 0)
                {
                    foreach (Attachment otaAttachment in otaAttachmentList)
                    {
                        //Check if file names are same
                        if (otaAttachment.FileName.ToLower() == strFileName.ToLower())
                        {
                            attStorage = otaAttachment.AttachmentStorage();
                            _localFileLocation = otaAttachment.DirectLink;

                            //Load method will download file to local workstation. true to used for synchronised download.
                            attStorage.Load(_localFileLocation, true);

                            //Client path refers to local path where file has been downloaded
                            _localFileLocation = attStorage.ClientPath;
                            break;
                        }
                    }
                }
            }

            //Return empty string if connection to QC was not successfull.
            else
            {
                _localFileLocation = string.Empty;
            }

            return _localFileLocation;
        }
Exemple #4
0
        //Given the test target machine name for calling RunTestSets
        public bool RunTestSets(string testMachine, string configPath)
        {
            try
            {
                TestSetTreeManager TestSetTreeMana   = tdConn.TestSetTreeManager as TestSetTreeManager;
                TestSetFolder      TestSetFolderPath = TestSetTreeMana.get_NodeByPath("Root\\AUTORUN\\" + tsFolderName) as TestSetFolder;
                TestSetFactory     TestSetFact       = TestSetFolderPath.TestSetFactory as TestSetFactory;
                TDFilter           TestSetFilter     = TestSetFact.Filter as TDFilter;
                List TestSetList = TestSetFilter.NewList() as List;
                foreach (TestSet ts in TestSetList)
                {
                    // need give the testmachine name and notice the whether use QTP,
                    // These value from command input

                    if (testMachine != null && testMachine != "")
                    {
                        AutoLog.Info("[bool RunTestSets]Begin to run test set: " + ts.Name);
                        //Console.Out.WriteLine("==========[bool RunTestSets]Begin to run test set: " + ts.Name);
                        RunCurrentSet(ts, testMachine, configFile.RunParameter.UsingQTP, configPath);
                        AutoLog.Info("[bool RunTestSets]End to run test set: " + ts.Name);
                        //Console.Out.WriteLine("==========[bool RunTestSets]End run test set: " + ts.Name);
                    }
                    else
                    {
                        RunCurrentSet(ts, configFile.RunParameter.TestMachine, configFile.RunParameter.UsingQTP, configPath);
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                AutoLog.Info("AutoIntSys: Run test sets exception" + e.Message);
                //Console.Out.WriteLine("AutoIntSys: Run test sets exception" + e.Message);
                //Debug.Print("AutoIntSys:" + e);
                //Debug.Print("AutoIntSys:Run Test Sets Error!");
                return(false);
            }
        }
Exemple #5
0
        public static Object GetTSRunStatus(dynamic TSItem)
        {
            TestSetFactory TSetFact = mTDConn.TestSetFactory;
            TDFilter       tsFilter = TSetFact.Filter;

            tsFilter["CY_CYCLE_ID"] = "" + TSItem.TestSetID + "";
            List Testset = TSetFact.NewList(tsFilter.Text);

            foreach (TestSet testset in Testset)
            {
                if (testset.Name == TSItem.TestSetName)
                {
                    TSTestFactory TSTestFact   = testset.TSTestFactory;
                    TDFilter      tsTestFilter = TSetFact.Filter;
                    tsTestFilter["TC_CYCLE_ID"] = "" + TSItem.TestSetID + "";
                    List TSActivities = TSTestFact.NewList(tsTestFilter.Text);
                    foreach (TSTest tst in TSActivities)
                    {
                        bool existing = false;
                        foreach (string[] status in TSItem.TestSetStatuses)
                        {
                            if (status[0] == tst.Status)
                            {
                                existing  = true;
                                status[1] = (Int32.Parse(status[1]) + 1).ToString();
                            }
                        }
                        if (!existing)
                        {
                            TSItem.TestSetStatuses.Add(new string[] { tst.Status, "1" });
                        }
                    }
                }
            }
            return(TSItem);
        }
Exemple #6
0
        //get test set explorer(tree view)
        public static IEnumerable <Object> GetTestSetExplorer(string PathNode)
        {
            TestSetTreeManager treeM    = (TestSetTreeManager)mTDConn.TestSetTreeManager;
            TestSetFolder      tsFolder = treeM.get_NodeByPath(PathNode);

            if (tsFolder == null && PathNode.ToUpper() == "ROOT")
            {
                tsFolder = treeM.Root;
            }

            TestSetFactory TSetFact = mTDConn.TestSetFactory;
            TDFilter       tsFilter = TSetFact.Filter;

            try
            {
                tsFilter["CY_FOLDER_ID"] = "" + tsFolder.NodeID + "";
            }
            catch (Exception e)
            {
                tsFilter["CY_FOLDER_ID"] = "\"" + tsFolder.Path.ToString() + "\"";
                Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {e.Message}", e);
            }

            List TestsetList = TSetFact.NewList(tsFilter.Text);
            List <ALMTestSetSummary> testlabPathList = new List <ALMTestSetSummary>();

            foreach (TestSet testset in TestsetList)
            {
                ALMTestSetSummary QCTestSetTreeItem = new ALMTestSetSummary();
                QCTestSetTreeItem.TestSetID   = testset.ID;
                QCTestSetTreeItem.TestSetName = testset.Name;
                testlabPathList.Add(QCTestSetTreeItem);
            }

            return(testlabPathList);
        }
Exemple #7
0
        public static bool ExportBusinessFlowToQC(BusinessFlow businessFlow, TestSet mappedTestSet, string uploadPath, ObservableList <ExternalItemFieldBase> testSetFields, ref string result)
        {
            TestSet testSet;
            ObservableList <ActivitiesGroup> existingActivitiesGroups = new ObservableList <ActivitiesGroup>();

            try
            {
                if (mappedTestSet == null)
                {
                    //##create new Test Set in QC
                    TestSetFactory TestSetF = (TestSetFactory)mTDConn.TestSetFactory;
                    testSet = (TestSet)TestSetF.AddItem(System.DBNull.Value);

                    //set the upload path
                    TestSetTreeManager treeM = (TestSetTreeManager)mTDConn.TestSetTreeManager;
                    ISysTreeNode       testSetParentFolder = (ISysTreeNode)treeM.get_NodeByPath(uploadPath);
                    testSet.TestSetFolder = testSetParentFolder.NodeID;
                }
                else
                {
                    //##update existing test set
                    //testSet = mappedTestSet;
                    testSet = ImportFromQC.GetQCTestSet(mappedTestSet.ID.ToString());

                    TSTestFactory testsF      = (TSTestFactory)testSet.TSTestFactory;
                    List          tsTestsList = testsF.NewList("");
                    foreach (TSTest tsTest in tsTestsList)
                    {
                        ActivitiesGroup ag = businessFlow.ActivitiesGroups.Where(x => (x.ExternalID == tsTest.TestId.ToString() && x.ExternalID2 == tsTest.ID.ToString())).FirstOrDefault();
                        if (ag == null)
                        {
                            testsF.RemoveItem(tsTest.ID);
                        }
                        else
                        {
                            existingActivitiesGroups.Add(ag);
                        }
                    }
                }

                //set item fields
                foreach (ExternalItemFieldBase field in testSetFields)
                {
                    if (field.ToUpdate || field.Mandatory)
                    {
                        if (string.IsNullOrEmpty(field.SelectedValue) == false && field.SelectedValue != "NA")
                        {
                            testSet[field.ID] = field.SelectedValue;
                        }
                        else
                        {
                            try { testSet[field.ID] = "NA"; }
                            catch { }
                        }
                    }
                }

                //post the test set
                testSet.Name = businessFlow.Name;

                try
                {
                    testSet.Post();
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("The Test Set already exists"))
                    {
                        result = "Cannot export " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) + "- The Test Set already exists in the selected folder. ";
                        Reporter.ToLog(eLogLevel.ERROR, result, ex);
                        return(false);
                    }

                    //Searching for the testset in case it was created in ALM although getting exception
                    TestSetFactory     TSetFact            = mTDConn.TestSetFactory;
                    TDFilter           tsFilter            = TSetFact.Filter;
                    TestSetTreeManager treeM               = (TestSetTreeManager)mTDConn.TestSetTreeManager;
                    ISysTreeNode       testSetParentFolder = (ISysTreeNode)treeM.get_NodeByPath(uploadPath);

                    try
                    {
                        tsFilter["CY_FOLDER_ID"] = "" + testSetParentFolder.NodeID + "";
                    }
                    catch (Exception e)
                    {
                        tsFilter["CY_FOLDER_ID"] = "\"" + testSetParentFolder.Path.ToString() + "\"";
                        Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {e.Message}", e);
                    }

                    List TestsetList = TSetFact.NewList(tsFilter.Text);
                    foreach (TestSet set in TestsetList)
                    {
                        if (set.Name == businessFlow.Name)
                        {
                            testSet = set;
                            break;
                        }
                    }
                }

                businessFlow.ExternalID = testSet.ID.ToString();

                //Add missing test cases
                TSTestFactory testCasesF = testSet.TSTestFactory;
                foreach (ActivitiesGroup ag in businessFlow.ActivitiesGroups)
                {
                    if (existingActivitiesGroups.Contains(ag) == false && string.IsNullOrEmpty(ag.ExternalID) == false && ImportFromQC.GetQCTest(ag.ExternalID) != null)
                    {
                        TSTest tsTest = testCasesF.AddItem(ag.ExternalID);
                        if (tsTest != null)
                        {
                            ag.ExternalID2 = tsTest.ID;//the test case instance ID in the test set- used for exporting the execution details
                        }
                    }
                    else
                    {
                        foreach (ActivityIdentifiers actIdent in ag.ActivitiesIdentifiers)
                        {
                            ExportActivityAsTestStep(ImportFromQC.GetQCTest(ag.ExternalID), (Activity)actIdent.IdentifiedActivity);
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                result = "Unexpected error occurred- " + ex.Message;
                Reporter.ToLog(eLogLevel.ERROR, "Failed to export the " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) + " to QC/ALM", ex);
                return(false);
            }
        }
Exemple #8
0
        private static void ExportRequirements()
        {
            string server_url = ConfigurationManager.AppSettings["SERVER_URL"];
            string username   = ConfigurationManager.AppSettings["USER_NAME"];
            string password   = ConfigurationManager.AppSettings["PASSWORD"];
            string domain     = ConfigurationManager.AppSettings["DOMAIN"];
            string project    = ConfigurationManager.AppSettings["PROJECT"];

            string req_file = ConfigurationManager.AppSettings["REQUIREMENTS_FILE"];
            string att_file = ConfigurationManager.AppSettings["ATTACHMENTS_FILE"];
            string att_path = ConfigurationManager.AppSettings["ATTACHMENTS_PATH"];

            if (!Directory.Exists(att_path))
            {
                Directory.CreateDirectory(att_path);
            }

            TDConnection tdc = new TDConnection();

            tdc.InitConnectionEx(server_url);
            tdc.ConnectProjectEx(domain, project, username, password);

            Console.WriteLine("Connected to QC Server");

            ReqFactory req_factory = (ReqFactory)tdc.ReqFactory;
            TDFilter   req_filter  = (TDFilter)req_factory.Filter;


            /**
             *  Set your own filters for requirements below
             */

            // req_filter["RQ_REQ_PATH"] = "AAAAAGAAE*";


            StreamWriter rfs = new StreamWriter(File.Open(req_file, FileMode.Create),
                                                Encoding.Default,
                                                1024);

            StreamWriter afs = new StreamWriter(File.Open(att_file, FileMode.Create),
                                                Encoding.Default,
                                                1024);

            foreach (Req r in req_filter.NewList())
            {
                string name = r.Name.Replace("\"", "").Replace("\t", "").Trim();

                Console.WriteLine("Req \"{0}\"", name);

                rfs.WriteLine(String.Join("\t", new String[] {
                    r.ID.ToString(),
                    r.ParentId.ToString(),
                    r["RQ_REQ_PATH"],
                    name,
                    r["RQ_VTS"].ToString()
                }));

                if (!r.HasAttachment)
                {
                    continue;
                }

                AttachmentFactory att_factory = r.Attachments;

                foreach (Attachment a in att_factory.NewList(""))
                {
                    Console.WriteLine("Attachment \"{0}\"", a.Name);

                    afs.WriteLine(String.Join("\t", new String[] {
                        r.ID.ToString(),
                        a.ID.ToString(),
                        a.Name,
                        a.FileSize.ToString(),
                        a.LastModified.ToShortDateString()
                    }));

                    IExtendedStorage storage = a.AttachmentStorage;
                    storage.ClientPath = Path.GetFullPath(att_path) + "\\";
                    storage.Load(a.Name, true);
                }
            }

            rfs.Close();
            afs.Close();

            tdc.Disconnect();
            tdc.Logout();

            Console.WriteLine("Disconnected.");
        }
Exemple #9
0
        public int Create(
            int TestSetId,
            int TestConfigId,
            TestStatus Status,
            string RunName,
            bool DraftRun,
            string[] Additional = default(string[]))
        {
            int runId = 0;

            try
            {
                if (!Connect(ServerUrl, Username, Password, Domain, Project))
                {
                    return(0);
                }

                if (!CanPerformAction("ac_run_manual_test"))
                {
                    rr.AddErrorLine("Error: The user does not have permission to execute tests");
                    return(0);
                }

                string runStatus = NormalizeTestStatus(Status);

                TestSetFactory tsFact        = tdc.TestSetFactory;
                TestSet        targetTestSet = tsFact[TestSetId];
                TSTestFactory  tsTestFactory = targetTestSet.TSTestFactory;

                TDFilter filter = tsTestFactory.Filter;
                filter["TC_TEST_CONFIG_ID"] = TestConfigId.ToString();

                List testInstanceList = filter.NewList();

                if (testInstanceList.Count == 1)
                {
                    TSTest     testInstance = testInstanceList[1];
                    RunFactory runFact      = testInstance.RunFactory;

                    //Best practice is to provide a null value, but an ALM bug keeps the test status of the test instance unchanged unless a name is provided
                    Run testRun = runFact.AddItem(RunName + "_" + DateTime.Now);

                    testRun.Status = runStatus;

                    if (DraftRun)
                    {
                        testRun["RN_DRAFT"] = "Y";
                    }

                    //Set additional field values
                    if (Additional != default(string[]))
                    {
                        foreach (string fieldPair in Additional)
                        {
                            string[] tempFieldArray = fieldPair.Split(new[] { ";;" }, StringSplitOptions.None);
                            testRun[tempFieldArray[0]] = tempFieldArray[1];
                        }
                    }

                    testRun.Post();
                    runId = testRun.ID;
                    //Console.Out.WriteLine(runId);
                }
                else if (testInstanceList.Count == 0)
                {
                    rr.AddErrorLine("Error: The test configuration ID does not exist in the test set.");
                }
                else
                {
                    //More than one instace of the test configuration exists in the test set
                    //The integration cannot support duplicates
                    rr.AddErrorLine("Error: multiple instances of the test configuration exist in this test set.");
                }
            }
            catch (COMException ce)
            {
                rr.AddErrorLine(HandleException(ce));
            }
            finally { Disconnect(); }

            return(runId);
        }
Exemple #10
0
        public void ParseDataSet(params object[] parameters)
        {
            lstTestPlanSteps = new List <string[]>();
            lstStrEvidenceID = new List <string>();
            try
            {
                string       strQCURL             = (string)parameters[0];
                string       strTargetFolderPath  = (string)parameters[1];
                string       strproject           = (string)parameters[2];
                string       strdomain            = (string)parameters[3];
                string       strpass              = (string)parameters[4];
                string       strTestPlanFileName  = Path.GetFileNameWithoutExtension((string)parameters[5]);
                bool         bIsCandidateEvidence = false;
                string       strscreenprint       = string.Empty;
                TDConnection qctd = new TDConnection();
                Test         tst;

                qctd.InitConnectionEx(strQCURL);
                qctd.ConnectProjectEx(strdomain, strproject, Environment.UserName, strpass);
                if (qctd.Connected)
                {
                    TestFactory testFactory = (TestFactory)qctd.TestFactory;
                    TDFilter    testFilter  = testFactory.Filter;

                    TDAPIOLELib.List testList;

                    testFilter["TS_NAME"] = "\"" + strTestPlanFileName + "\"";
                    // testFilter["TS_PATH"] = "\"" + strTargetFolderPath + "\"";
                    TDAPIOLELib.List listOfTests = testFilter.NewList();

                    testList = (TDAPIOLELib.List)testFactory.NewList(testFilter.Text);
                    string strdescription = string.Empty;
                    int    itestcount     = testList.Count;
                    int    stepscount     = 0;
                    if (testList.Count == 0)
                    {
                        throw new FileNotFoundException("No test plans Found .Check the testplan name");
                    }
                    else if (testList.Count > 1)
                    {
                        MessageBox.Show("Multiple Test plans found , Click Ok to view and select the Right Test Plan", "Mutiple Test Plans");
                        DisplayListOFTestPlan(testList, testFactory);
                        tst             = SelectedTest;
                        strTestplanPath = testFactory[tst.ID]["TS_SUBJECT"].Path;
                    }
                    else
                    {
                        tst = testList[1];
                    }
                    if (tst == null)
                    {
                        throw new Exception("No Test plans selected ");
                    }
                    strTestPlanName = tst.Name;
                    //   string noHTML = Regex.Replace(tst["TS_DESCRIPTION"], @"<[^>]+>|&nbsp;", "").Trim();
                    //  noHTML = WebUtility.HtmlDecode(noHTML);
                    string noHTML = RemoveHTML(tst["TS_DESCRIPTION"]);
                    //  Match m = Regex.Match(noHTML, "(?s)[Pp]rerequisites.*[Cc]hange [Cc]ontrol");
                    Match m = Regex.Match(noHTML, "(?s)[Pp]rerequisites.*");
                    strPrerequisites = m.Value;
                    DesignStepFactory dsf      = tst.DesignStepFactory;
                    TDAPIOLELib.List  dslflist = dsf.NewList("");
                    stepscount = dslflist.Count;
                    foreach (DesignStep ds in dslflist)
                    {
                        arrStepData    = new string[3];
                        arrStepData[0] = ds.StepName;
                        arrStepData[1] = RemoveHTML(ds.StepDescription);
                        arrStepData[2] = RemoveHTML(ds.StepExpectedResult);
                        lstTestPlanSteps.Add(arrStepData);
                        bIsCandidateEvidence = false;
                        strscreenprint       = (string)ds["DS_USER_01"];
                        if (!string.IsNullOrEmpty(strscreenprint))
                        {
                            if (string.Compare(strscreenprint.ToLower(), "none") != 0)
                            {
                                foreach (char ch in strscreenprint)
                                {
                                    if ((int)ch >= 33 && (int)ch <= 126)
                                    {
                                        bIsCandidateEvidence = true;
                                        break;
                                    }
                                }
                                if (bIsCandidateEvidence)
                                {
                                    lstStrEvidenceID.Add(ds.StepName);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }