public virtual IDriverCleanup Create() { string browserServer; string browserProcess; var browserTypeValue = _configurationReader.GetConfigurationValue(Constants.Configuration.BrowserTypeKey); var browserType = !string.IsNullOrWhiteSpace(browserTypeValue) ? BrowserTypeMapper.ConvertBrowserValue(browserTypeValue) : BrowserTypes.InternetExplorer; switch (browserType) { case Enums.BrowserTypes.InternetExplorer: browserProcess = Enums.BrowserTypes.InternetExplorer.GetDescription(); browserServer = BrowserDriverServer.InternetExplorer; break; case Enums.BrowserTypes.Chrome: browserProcess = Enums.BrowserTypes.Chrome.GetDescription(); browserServer = BrowserDriverServer.Chrome; break; case Enums.BrowserTypes.Firefox: browserProcess = Enums.BrowserTypes.Firefox.GetDescription(); browserServer = BrowserDriverServer.Firefox; break; default: browserProcess = Enums.BrowserTypes.InternetExplorer.GetDescription(); browserServer = BrowserDriverServer.InternetExplorer; break; } return(new DriverCleanup(browserServer, browserProcess, _osProcess, _configurationReader)); }
public virtual DriverOptions Create() { var browserTypeValue = _configurationReader.GetConfigurationValue(Constants.Configuration.BrowserTypeKey); var browserType = !string.IsNullOrWhiteSpace(browserTypeValue) ? BrowserTypeMapper.ConvertBrowserValue(browserTypeValue) : BrowserTypes.InternetExplorer; switch (browserType) { case BrowserTypes.Firefox: return(CreateFirefoxDriverOptions()); case BrowserTypes.InternetExplorer: return(CreateInternetExplorerDriverOptions()); case BrowserTypes.Chrome: return(CreateChromeDriverOptions()); case BrowserTypes.Edge: return(CreateEdgeDriverOptions()); case BrowserTypes.NotSet: return(CreateInternetExplorerDriverOptions()); default: return(CreateInternetExplorerDriverOptions()); } }
private void CleanBrowserProcesses(bool onInitialise = false) { try { var noOfKillAttempts = 0; if (string.Equals(Generic.TrueValue.ToLower(), _configurationReader.GetConfigurationValue(Constants.Configuration.ForceKillProcessKey).ToLower())) { var processIds = Process.GetProcessesByName(_browserProcess.ToLower()).ToList(); if (processIds.Count <= 0) { return; } //Due to the nature of how processes are killed in windows (parent and children termination of processes) and how we have already //performed a check for processes the do while loop is the most appropriate. We also need to take into account that the account may //not be authorised to kill a process that doesnt belong to them do { Process.Kill(processIds.FirstOrDefault()); processIds = Process.GetProcessesByName(_browserProcess.ToLower()).ToList(); noOfKillAttempts++; } while (processIds.Count > 0 && noOfKillAttempts < MaxKillAttemps); } else if (!onInitialise) { var processIdsAfter = Process.GetProcessesByName(_browserProcess); var processIds = processIdsAfter.Except(_processIdsBefore).ToList(); if (processIds.Count <= 0) { return; } //Due to the nature of how processes are killed in windows (parent and children termination of processes) and how we have already //performed a check for processes the do while loop is the most appropriate. We also need to take into account that the account may //not be authorised to kill a process that doesnt belong to them do { Process.Kill(processIds.FirstOrDefault()); processIdsAfter = Process.GetProcessesByName(_browserProcess); processIds = processIdsAfter.Except(_processIdsBefore).ToList(); noOfKillAttempts++; } while (processIds.Count > 0 && noOfKillAttempts < MaxKillAttemps); } } catch (System.Exception e) { Console.WriteLine(e); } }
/// <summary> /// Gets the configuration value of the specified property /// </summary> /// <typeparam name="T">Type of configuration value</typeparam> /// <param name="nameOfProperty">Property name</param> /// <param name="defaultValue">Default property value</param> /// <returns>Configuration value</returns> public T GetValue <T>(string nameOfProperty, T defaultValue = default(T)) { string value; if (!_valueReader.GetConfigurationValue(_categoryName, nameOfProperty, out value)) { return(defaultValue); } var converter = TypeDescriptor.GetConverter(typeof(T)); return((T)converter.ConvertFrom(value)); }
private void SetupLogger() { var config = new LoggingConfiguration(); var consoleTarget = new ConsoleTarget(); config.AddTarget("Console", consoleTarget); var fileTarget = new FileTarget(); config.AddTarget("File", fileTarget); consoleTarget.Layout = @"${date:format=HH\:mm\:ss} ${logger} ${message}"; var outputDirectory = _configurationReader.GetConfigurationValue(FileOutputDirectory); string outputFile; if (!string.IsNullOrWhiteSpace(outputDirectory) && outputDirectory.Contains("/")) //handle relative paths { outputFile = $"{outputDirectory}/{DefaultFileName}"; } else if (!string.IsNullOrWhiteSpace(outputDirectory) && outputDirectory.Contains(@"\")) //handle absolute paths { outputFile = Path.Combine(Path.GetDirectoryName(outputDirectory), DefaultFileName); } else //set default log file { outputFile = "${basedir}/" + DefaultFileName; } fileTarget.FileName = outputFile; fileTarget.Layout = "${message}"; // Step 4. Define rules var rule1 = new LoggingRule("*", LogLevel.Debug, consoleTarget); config.LoggingRules.Add(rule1); var rule2 = new LoggingRule("*", LogLevel.Debug, fileTarget); config.LoggingRules.Add(rule2); // Step 5. Activate the configuration LogManager.Configuration = config; Logger = LogManager.GetLogger("TestAutomationLogger"); }