Пример #1
0
        public void CleanRunSpace()
        {
            var configFilePath = TestRunDirectory + "\\config.json";

            if (File.Exists(configFilePath))
            {
                var configFile = new FileInfo(configFilePath);
                try
                {
                    configFile.Delete();
                }
                catch (Exception ex)
                {
                    StaticUtilities.Log(ex);
                }
            }
            else
            {
                StaticUtilities.Log("config.json is not found during clean up");
            }

            if (Directory.Exists(TestResultsDirectoryPath))
            {
                StaticUtilities.DeleteDirectory(TestResultsDirectoryPath);
            }
        }
Пример #2
0
        private static List <string> GetListOfClients()
        {
            MatchCollection matches = null;

            try
            {
                WebClient webClient = new WebClient();
                string    s         = webClient.DownloadString("http://localhost:4444/grid/console");
                matches = Regex.Matches(s, "remoteHost:[^<]*");
            }
            catch (Exception ex) {
                StaticUtilities.Log(ex);
            }

            List <string> hosts = new List <string>();

            if (matches.Count > 0)
            {
                foreach (Match match in matches)
                {
                    string host = match.ToString().Substring(11);
                    hosts.Add(host);
                }
            }

            return(hosts);
        }
Пример #3
0
 public void RunTest()
 {
     StaticUtilities.Log("Running test " + testName + " on machine " + client.Address);
     status = TestRunnerStatus.Running;
     setUpConfig(client.Address);
     RunTestProcess(testName);
 }
Пример #4
0
        private List <string> GetListOfTests()
        {
            var testQuery        = new TestQuery();
            var workingDirectory = StaticUtilities.GetWorkingDirectoryPath();
            var testList         = testQuery.GetTestNames(workingDirectory + @"\TestAssembly\" + StaticUtilities.GetTestProjectDll(), StaticUtilities.GetTestsNamespace());

            return(testList);
        }
Пример #5
0
        private List <string> GetListOfTests()
        {
            var testQuery        = new TestQuery();
            var workingDirectory = StaticUtilities.GetWorkingDirectoryPath();
            var testList         = testQuery.GetTestNames(workingDirectory + @"\TestAssembly\CampaignUI.dll", "CampaignUI.CampaignFeatures");

            return(testList);
        }
Пример #6
0
        private void processExited(object sender, System.EventArgs e)
        {
            StaticUtilities.Log("TestName  : " + testName + " ran on machine with ip : " + client.Address + " exited with code " + process.ExitCode);

            runSpace.SaveTestResults();

            runSpace.status = RunSpaceStatus.Free;
            client.status   = ClientStatus.Free;
            status          = TestRunnerStatus.Exited;
        }
Пример #7
0
        public void SaveTestResults()
        {
            string[] trxFilePaths = null;
            try
            {
                trxFilePaths = Directory.GetFiles(TestResultsDirectoryPath, "*.trx");
            }
            catch (Exception ex) {
                StaticUtilities.Log(ex);
            }

            if (trxFilePaths != null && trxFilePaths.Length > 0)
            {
                FileInfo testResultFile = null;
                try
                {
                    testResultFile = new FileInfo(trxFilePaths[0]);
                }
                catch (Exception ex)
                {
                    StaticUtilities.Log(ex);
                }

                if (!Directory.Exists(AccumulatedTestResultsDirectory))
                {
                    try
                    {
                        Directory.CreateDirectory(AccumulatedTestResultsDirectory);
                    }
                    catch (Exception ex)
                    {
                        StaticUtilities.Log(ex);
                    }
                }

                var newTestResultPath = AccumulatedTestResultsDirectory + Guid.NewGuid().ToString() + ".trx";

                if (newTestResultPath != null && !File.Exists(newTestResultPath))
                {
                    try
                    {
                        testResultFile.CopyTo(newTestResultPath);
                    }
                    catch (Exception ex)
                    {
                        StaticUtilities.Log(ex);
                    }
                }
                else
                {
                    StaticUtilities.Log("test results file not found, expected path : " + newTestResultPath);
                }
            }
        }
Пример #8
0
        public RunSpace()
        {
            this.status = RunSpaceStatus.Free;
            RunInstance = new Random().Next();

            WorkingDirectory                = StaticUtilities.GetWorkingDirectoryPath();
            TestRunDirectory                = WorkingDirectory + @"TestRuns\TestRun" + RunInstance;
            TestResultsDirectoryPath        = TestRunDirectory + @"\TestResults\";
            AccumulatedTestResultsDirectory = WorkingDirectory + @"\TestResults\";
            TestAssemblyPath                = StaticUtilities.GetTestAssemblyPath();

            SetUpAssemblies();
        }
Пример #9
0
 private void SetUpAssemblies()
 {
     if (!Directory.Exists(TestRunDirectory))
     {
         try
         {
             Directory.CreateDirectory(TestRunDirectory);
         }
         catch (Exception ex)
         {
             StaticUtilities.Log(ex);
         }
     }
     StaticUtilities.CopyDirectory(TestAssemblyPath, TestRunDirectory);
 }
Пример #10
0
        public void TimerEvent(object sender, System.Timers.ElapsedEventArgs args)
        {
            //var freeClients = clientManager.GetFreeClients();
            var freeClients = clientManager.GetFreeClientsHubMock();

            if (freeClients.Count > 0)
            {
                for (int index = 0; index < freeClients.Count; index++)
                {
                    //for (int index = 0; index < 1; index++){
                    var client = freeClients[index];
                    client.status = ClientStatus.Busy;

                    var runSpace = runSpaceManager.GetFreeRunSpace();
                    runSpace.status = RunSpaceStatus.Busy;

                    var testToExecute = testManager.GetNextTestToExecute();

                    if (testToExecute == null)
                    {
                        StaticUtilities.Log("Test run completed");
                        timer.Enabled = false;
                        return;
                    }

                    var testRunner = new TestRunner(runSpace, testToExecute, client);
                    runningTests.Add(testToExecute, testRunner);
                    Thread newThread = null;
                    try
                    {
                        newThread = new Thread(new ThreadStart(testRunner.RunTest));
                        newThread.Start();
                    }
                    catch (Exception ex)
                    {
                        StaticUtilities.Log(ex);
                    }

                    if (newThread != null)
                    {
                        runningThreads.Add(newThread);
                    }
                }
            }
        }
Пример #11
0
        private void setUpConfig(string clientAddress)
        {
            var config = new Config()
            {
                clientUrl = clientAddress + "/wd/hub"
            };
            var configString = JsonConvert.SerializeObject(config);

            try
            {
                using (StreamWriter sWriter = new StreamWriter(TestRunDirectory + "\\config.json"))
                {
                    sWriter.WriteLine(configString);
                    sWriter.Flush();
                }
            }
            catch (Exception ex) {
                StaticUtilities.Log(ex);
            }
        }
Пример #12
0
        private void RunTestProcess(string testName)
        {
            try
            {
                var processStartInfo = new ProcessStartInfo();

                processStartInfo.FileName = "mstest";
                //processStartInfo.FileName = "vstest.console.exe";
                processStartInfo.Arguments = "/testcontainer:CampaignUI.dll " +
                                             "/testsettings:PPE.testsettings " +
                                             "/test:" + testName;
                processStartInfo.CreateNoWindow   = true;
                processStartInfo.WorkingDirectory = TestRunDirectory;

                process = Process.Start(processStartInfo);

                process.EnableRaisingEvents = true;
                process.Exited += new EventHandler(processExited);
                process.WaitForExit();
            }
            catch (Exception ex) {
                StaticUtilities.Log(ex);
            }
        }