From 46d617c34d8899299c011d8bd3532dbdb1b67888 Mon Sep 17 00:00:00 2001 From: Pavel Anihimovsky <47742067+pavelanihimovsky@users.noreply.github.com> Date: Mon, 9 Dec 2019 09:47:56 +0300 Subject: [PATCH] Remove redundant dependencies from ElementFinder #31 (#32) --- .../Applications/Startup.cs | 9 +++++---- .../Elements/ElementFinder.cs | 17 +++++------------ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/Aquality.Selenium.Core/src/Aquality.Selenium.Core/Applications/Startup.cs b/Aquality.Selenium.Core/src/Aquality.Selenium.Core/Applications/Startup.cs index 34d8a58..412de1d 100644 --- a/Aquality.Selenium.Core/src/Aquality.Selenium.Core/Applications/Startup.cs +++ b/Aquality.Selenium.Core/src/Aquality.Selenium.Core/Applications/Startup.cs @@ -30,15 +30,16 @@ public void ConfigureServices(IServiceCollection services, Func(new TimeoutConfiguration(settingsFile)); - services.AddTransient(); - services.AddSingleton(new LoggerConfiguration(settingsFile)); + services.AddSingleton(settingsFile); services.AddSingleton(Logger.Instance); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(new RetryConfiguration(settingsFile)); services.AddSingleton(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); } diff --git a/Aquality.Selenium.Core/src/Aquality.Selenium.Core/Elements/ElementFinder.cs b/Aquality.Selenium.Core/src/Aquality.Selenium.Core/Elements/ElementFinder.cs index e8fea6e..1e1276c 100644 --- a/Aquality.Selenium.Core/src/Aquality.Selenium.Core/Elements/ElementFinder.cs +++ b/Aquality.Selenium.Core/src/Aquality.Selenium.Core/Elements/ElementFinder.cs @@ -1,6 +1,5 @@ using Aquality.Selenium.Core.Elements.Interfaces; using Aquality.Selenium.Core.Localization; -using Aquality.Selenium.Core.Logging; using Aquality.Selenium.Core.Waitings; using OpenQA.Selenium; using System; @@ -15,19 +14,13 @@ namespace Aquality.Selenium.Core.Elements /// public class ElementFinder : IElementFinder { - public ElementFinder(Logger logger, ILocalizedLogger localizedLogger, ILocalizationManager localizationManager, ConditionalWait conditionalWait) + public ElementFinder(ILocalizedLogger logger, ConditionalWait conditionalWait) { Logger = logger; - LocalizedLogger = localizedLogger; - LocalizationManager = localizationManager; ConditionalWait = conditionalWait; } - private Logger Logger { get; } - - private ILocalizedLogger LocalizedLogger { get; } - - private ILocalizationManager LocalizationManager { get; } + private ILocalizedLogger Logger { get; } private ConditionalWait ConditionalWait { get; } @@ -90,7 +83,7 @@ public ReadOnlyCollection FindElements(By locator, DesiredState des private void HandleTimeoutException(WebDriverTimeoutException ex, DesiredState desiredState, By locator, List foundElements) { - var message = LocalizationManager.GetLocalizedMessage("loc.no.elements.found.in.state", locator.ToString(), desiredState.StateName); + var message = $"No elements with locator '{locator.ToString()}' were found in {desiredState.StateName} state"; if (desiredState.IsCatchingTimeoutException) { if (!foundElements.Any()) @@ -99,11 +92,11 @@ private void HandleTimeoutException(WebDriverTimeoutException ex, DesiredState d { throw new NoSuchElementException(message); } - Logger.Debug(message); + Logger.Debug("loc.no.elements.found.in.state", null, locator.ToString(), desiredState.StateName); } else { - LocalizedLogger.Debug("loc.elements.were.found.but.not.in.state", null, locator.ToString(), desiredState.StateName); + Logger.Debug("loc.elements.were.found.but.not.in.state", null, locator.ToString(), desiredState.StateName); } } else