Skip to content

Commit 46d617c

Browse files
paveliamknysh
authored andcommitted
Remove redundant dependencies from ElementFinder #31 (#32)
1 parent 3b4c2a1 commit 46d617c

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Applications/Startup.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ public void ConfigureServices(IServiceCollection services, Func<IServiceProvider
3030
settingsFile = settings ?? GetSettings();
3131
services.AddScoped(applicationProvider);
3232

33-
services.AddSingleton<ITimeoutConfiguration>(new TimeoutConfiguration(settingsFile));
34-
services.AddTransient<ConditionalWait>();
35-
services.AddSingleton<ILoggerConfiguration>(new LoggerConfiguration(settingsFile));
33+
services.AddSingleton(settingsFile);
3634
services.AddSingleton(Logger.Instance);
35+
services.AddSingleton<ILoggerConfiguration, LoggerConfiguration>();
36+
services.AddSingleton<ITimeoutConfiguration, TimeoutConfiguration>();
37+
services.AddSingleton<IRetryConfiguration, RetryConfiguration>();
3738
services.AddSingleton<ILocalizationManager, LocalizationManager>();
3839
services.AddSingleton<ILocalizedLogger, LocalizedLogger>();
39-
services.AddSingleton<IRetryConfiguration>(new RetryConfiguration(settingsFile));
4040
services.AddSingleton<ElementActionRetrier>();
4141

42+
services.AddTransient<ConditionalWait>();
4243
services.AddTransient<IElementFinder, ElementFinder>();
4344
services.AddTransient<IElementFactory, ElementFactory>();
4445
}

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Elements/ElementFinder.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Aquality.Selenium.Core.Elements.Interfaces;
22
using Aquality.Selenium.Core.Localization;
3-
using Aquality.Selenium.Core.Logging;
43
using Aquality.Selenium.Core.Waitings;
54
using OpenQA.Selenium;
65
using System;
@@ -15,19 +14,13 @@ namespace Aquality.Selenium.Core.Elements
1514
/// </summary>
1615
public class ElementFinder : IElementFinder
1716
{
18-
public ElementFinder(Logger logger, ILocalizedLogger localizedLogger, ILocalizationManager localizationManager, ConditionalWait conditionalWait)
17+
public ElementFinder(ILocalizedLogger logger, ConditionalWait conditionalWait)
1918
{
2019
Logger = logger;
21-
LocalizedLogger = localizedLogger;
22-
LocalizationManager = localizationManager;
2320
ConditionalWait = conditionalWait;
2421
}
2522

26-
private Logger Logger { get; }
27-
28-
private ILocalizedLogger LocalizedLogger { get; }
29-
30-
private ILocalizationManager LocalizationManager { get; }
23+
private ILocalizedLogger Logger { get; }
3124

3225
private ConditionalWait ConditionalWait { get; }
3326

@@ -90,7 +83,7 @@ public ReadOnlyCollection<IWebElement> FindElements(By locator, DesiredState des
9083

9184
private void HandleTimeoutException(WebDriverTimeoutException ex, DesiredState desiredState, By locator, List<IWebElement> foundElements)
9285
{
93-
var message = LocalizationManager.GetLocalizedMessage("loc.no.elements.found.in.state", locator.ToString(), desiredState.StateName);
86+
var message = $"No elements with locator '{locator.ToString()}' were found in {desiredState.StateName} state";
9487
if (desiredState.IsCatchingTimeoutException)
9588
{
9689
if (!foundElements.Any())
@@ -99,11 +92,11 @@ private void HandleTimeoutException(WebDriverTimeoutException ex, DesiredState d
9992
{
10093
throw new NoSuchElementException(message);
10194
}
102-
Logger.Debug(message);
95+
Logger.Debug("loc.no.elements.found.in.state", null, locator.ToString(), desiredState.StateName);
10396
}
10497
else
10598
{
106-
LocalizedLogger.Debug("loc.elements.were.found.but.not.in.state", null, locator.ToString(), desiredState.StateName);
99+
Logger.Debug("loc.elements.were.found.but.not.in.state", null, locator.ToString(), desiredState.StateName);
107100
}
108101
}
109102
else

0 commit comments

Comments
 (0)