/// <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);
        }
Esempio n. 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);
        }
Esempio n. 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;
        }
Esempio n. 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);
            }
        }
Esempio n. 5
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.");
        }
Esempio n. 6
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);
        }
Esempio n. 7
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;
            }
        }