Skip to content

Commit 8f98b37

Browse files
authored
Update Selenium version to v4.11.0 (#109)
* Update Selenium to v4.9.1 - Update NLog dependency to v5.1.4 - Update Appium test dependency to v5.0.0-beta04 - Remove WebDriverManager test dependency as Selenium Manager could be used now * Make web cachedElementTests only parallelizable by themselves * Updated to latest package versions. Add GenerateLocator as additional abstraction level * Fix logger configuration * Fix some warnings * Add workaround in tests for GoToUrl webDriver issue and session not created issue * Update azure-pipelines.yml for Azure Pipelines: add retryCountOnTaskFailure: 1
1 parent 903aa86 commit 8f98b37

File tree

16 files changed

+71
-40
lines changed

16 files changed

+71
-40
lines changed

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Aquality.Selenium.Core.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050
<PackageReference Include="DotNetSeleniumExtras.PageObjects" Version="3.11.0" />
5151
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
5252
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
53-
<PackageReference Include="NLog" Version="5.1.2" />
54-
<PackageReference Include="Selenium.Support" Version="4.8.1" />
55-
<PackageReference Include="Selenium.WebDriver" Version="4.8.1" />
56-
<PackageReference Include="SkiaSharp" Version="2.88.3" />
53+
<PackageReference Include="NLog" Version="5.2.3" />
54+
<PackageReference Include="Selenium.Support" Version="4.11.0" />
55+
<PackageReference Include="Selenium.WebDriver" Version="4.11.0" />
56+
<PackageReference Include="SkiaSharp" Version="2.88.5" />
5757
</ItemGroup>
5858
</Project>

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Aquality.Selenium.Core.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public virtual IList<T> FindElements<T>(By locator, string name = null, ElementS
7575
{
7676
var elementIndex = index + 1;
7777
var elementName = $"{name ?? "element"} {elementIndex}";
78-
return elementSupplier(GenerateXpathLocator(locator, webElement, elementIndex), elementName, state);
78+
return elementSupplier(GenerateLocator(locator, webElement, elementIndex), elementName, state);
7979
});
8080
return elements.ToList();
8181
}
@@ -85,6 +85,18 @@ public virtual T GetCustomElement<T>(ElementSupplier<T> elementSupplier, By loca
8585
return elementSupplier(locator, name, state);
8686
}
8787

88+
/// <summary>
89+
/// Generates locator for target element
90+
/// </summary>
91+
/// <param name="baseLocator">locator of parent element</param>
92+
/// <param name="webElement">target element</param>
93+
/// <param name="elementIndex">index of target element</param>
94+
/// <returns>target element's locator</returns>
95+
protected virtual By GenerateLocator(By baseLocator, IWebElement webElement, int elementIndex)
96+
{
97+
return GenerateXpathLocator(baseLocator, webElement, elementIndex);
98+
}
99+
88100
/// <summary>
89101
/// Generates xpath locator for target element
90102
/// </summary>

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Localization/LocalizationManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Aquality.Selenium.Core.Configurations;
22
using Aquality.Selenium.Core.Logging;
33
using Aquality.Selenium.Core.Utilities;
4-
using System.Linq;
4+
using System;
55
using System.Reflection;
66

77
namespace Aquality.Selenium.Core.Localization
@@ -24,7 +24,7 @@ public LocalizationManager(ILoggerConfiguration loggerConfiguration, Logger logg
2424
private static ISettingsFile GetLocalizationFile(string language, Assembly assembly)
2525
{
2626
var embeddedResourceName = string.Format(LangResource, language.ToLower());
27-
var assemblyToUse = assembly.GetManifestResourceNames().Any(name => name.Contains(embeddedResourceName))
27+
var assemblyToUse = Array.Exists(assembly.GetManifestResourceNames(), name => name.Contains(embeddedResourceName))
2828
? assembly
2929
: Assembly.GetExecutingAssembly();
3030
return new JsonSettingsFile(embeddedResourceName, assemblyToUse);

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Logging/Logger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private Logger()
1919
{
2020
try
2121
{
22-
LogManager.LoadConfiguration("NLog.config");
22+
LogManager.Setup().LoadConfigurationFromFile("NLog.config", optional: false);
2323
}
2424
catch (FileNotFoundException)
2525
{

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Utilities/EnvironmentConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static string GetVariable(string key)
2424
//necessary for Azure
2525
Environment.GetEnvironmentVariable(key.ToUpper().Replace('.', '_'))
2626
};
27-
return variables.FirstOrDefault(variable => variable != null);
27+
return variables.Find(variable => variable != null);
2828
}
2929
}
3030
}
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
using Aquality.Selenium.Core.Applications;
22
using Aquality.Selenium.Core.Configurations;
3+
using Aquality.Selenium.Core.Utilities;
34
using Microsoft.Extensions.DependencyInjection;
45
using System;
5-
using WebDriverManager;
6-
using WebDriverManager.DriverConfigs.Impl;
7-
using WebDriverManager.Helpers;
6+
using System.Collections.Generic;
87

98
namespace Aquality.Selenium.Core.Tests.Applications.Browser
109
{
1110
public class AqualityServices : AqualityServices<ChromeApplication>
1211
{
13-
private static readonly object downloadDriverLock = new object();
14-
1512
public new static bool IsApplicationStarted => IsApplicationStarted();
1613

1714
public static ChromeApplication Application => GetApplication(services => StartChrome(services));
@@ -26,16 +23,13 @@ public static IServiceProvider ServiceProvider
2623
{
2724
SetServiceProvider(value);
2825
}
29-
}
26+
}
3027

3128
private static ChromeApplication StartChrome(IServiceProvider services)
3229
{
33-
lock (downloadDriverLock)
34-
{
35-
new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser);
36-
}
37-
38-
return new ChromeApplication(services.GetRequiredService<ITimeoutConfiguration>());
30+
// temp workaround to handle ChromeDriver issue: https://groups.google.com/g/chromedriver-users/c/Dgv9xRHZf58
31+
return services.GetService<IActionRetrier>().DoWithRetry(() =>
32+
new ChromeApplication(services.GetRequiredService<ITimeoutConfiguration>()), new List<Type> { typeof(InvalidOperationException) });
3933
}
4034
}
4135
}

Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Applications/Browser/CachedElementTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
namespace Aquality.Selenium.Core.Tests.Applications.Browser
1212
{
13+
[Parallelizable(ParallelScope.Children)]
1314
public class CachedElementTests : TestWithBrowser
1415
{
15-
private static readonly By RemoveButtonLoc = By.XPath("//button[.='Remove']");
1616
private static readonly By ContentLoc = By.Id("checkbox");
1717
private static readonly By StartLoc = By.XPath("//*[@id='start']//button");
1818
private static readonly By LoadingLoc = By.Id("loading");
@@ -49,26 +49,26 @@ private static readonly Func<IElementStateProvider, bool>[] StateFunctionsThrowN
4949
state => !state.WaitForNotEnabled(TimeSpan.Zero),
5050
};
5151

52-
private IConditionalWait ConditionalWait => AqualityServices.ServiceProvider.GetRequiredService<IConditionalWait>();
52+
private static IConditionalWait ConditionalWait => AqualityServices.ServiceProvider.GetRequiredService<IConditionalWait>();
5353

5454
[SetUp]
5555
public new void SetUp()
5656
{
5757
Environment.SetEnvironmentVariable(ElementCacheVariableName, true.ToString());
5858
}
5959

60-
private void StartLoading()
60+
private static void StartLoading()
6161
{
62-
AqualityServices.Application.Driver.Navigate().GoToUrl(DynamicLoadingUrl);
62+
GoToUrl(DynamicLoadingUrl);
6363
new Label(StartLoc, "start", ElementState.Displayed).Click();
6464
}
6565

66-
private void OpenDynamicContent()
66+
private static void OpenDynamicContent()
6767
{
68-
AqualityServices.Application.Driver.Navigate().GoToUrl(DynamicContentUrl);
68+
GoToUrl(DynamicContentUrl);
6969
}
7070

71-
private void WaitForLoading(Label loader)
71+
private static void WaitForLoading(Label loader)
7272
{
7373
Assume.That(loader.State.WaitForDisplayed(), "Loader should be displayed in the beginning");
7474
Assume.That(loader.State.WaitForNotDisplayed(), "Loader should not be displayed in the end");
@@ -137,7 +137,7 @@ public void Should_ReturnCorrectState_True_WhenWindowIsReopened([ValueSource(nam
137137
AssertStateConditionAfterReopen(stateCondition, expectedValue: true);
138138
}
139139

140-
private void AssertStateConditionAfterReopen(Func<IElementStateProvider, bool> stateCondition, bool expectedValue)
140+
private static void AssertStateConditionAfterReopen(Func<IElementStateProvider, bool> stateCondition, bool expectedValue)
141141
{
142142
Label testElement = null;
143143
AqualityServices.ServiceProvider.GetRequiredService<IActionRetrier>().DoWithRetry(() =>

Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Applications/Browser/ConditionalWaitTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void Should_BePossibleTo_UseConditionalWait_WithDriver()
3939
{
4040
Assert.DoesNotThrow(() => ConditionalWait.WaitFor(driver =>
4141
{
42-
driver.Navigate().GoToUrl(WikiURL);
42+
GoToUrl(WikiURL, driver);
4343
return driver.FindElements(By.XPath("//*")).Count > 0;
4444
}));
4545
}
@@ -100,7 +100,7 @@ bool elementFinderCondition() => ServiceProvider.GetRequiredService<IElementFind
100100
Assert.IsFalse(elementFinderCondition());
101101
Assert.DoesNotThrow(() => ConditionalWait.WaitFor(driver =>
102102
{
103-
driver.Navigate().GoToUrl(WikiURL);
103+
GoToUrl(WikiURL, driver);
104104
return elementFinderCondition();
105105
}));
106106
}

Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Applications/Browser/FindElementsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected virtual IList<T> FindElements<T>(By locator, string name = null, Eleme
3232
public new void SetUp()
3333
{
3434
ElementFactory = ServiceProvider.GetRequiredService<IElementFactory>();
35-
AqualityServices.Application.Driver.Navigate().GoToUrl(HoversURL);
35+
GoToUrl(HoversURL);
3636
ParentElement = new Label(ContentLoc, "Example", ElementState.Displayed);
3737
ParentElement.Click();
3838
}

0 commit comments

Comments
 (0)