public void RunTest() { StaticUtilities.Log("Running test " + testName + " on machine " + client.Address); status = TestRunnerStatus.Running; setUpConfig(client.Address); RunTestProcess(testName); }
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); }
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); } }
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; }
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); } } }
private void SetUpAssemblies() { if (!Directory.Exists(TestRunDirectory)) { try { Directory.CreateDirectory(TestRunDirectory); } catch (Exception ex) { StaticUtilities.Log(ex); } } StaticUtilities.CopyDirectory(TestAssemblyPath, TestRunDirectory); }
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); } } } }
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); } }
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); } }