Skip to content

Update Selenium version to v4.11.0 #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
<PackageReference Include="DotNetSeleniumExtras.PageObjects" Version="3.11.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="NLog" Version="5.1.2" />
<PackageReference Include="Selenium.Support" Version="4.8.1" />
<PackageReference Include="Selenium.WebDriver" Version="4.8.1" />
<PackageReference Include="SkiaSharp" Version="2.88.3" />
<PackageReference Include="NLog" Version="5.2.3" />
<PackageReference Include="Selenium.Support" Version="4.11.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.11.0" />
<PackageReference Include="SkiaSharp" Version="2.88.5" />
</ItemGroup>
</Project>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public virtual IList<T> FindElements<T>(By locator, string name = null, ElementS
{
var elementIndex = index + 1;
var elementName = $"{name ?? "element"} {elementIndex}";
return elementSupplier(GenerateXpathLocator(locator, webElement, elementIndex), elementName, state);
return elementSupplier(GenerateLocator(locator, webElement, elementIndex), elementName, state);
});
return elements.ToList();
}
Expand All @@ -85,6 +85,18 @@ public virtual T GetCustomElement<T>(ElementSupplier<T> elementSupplier, By loca
return elementSupplier(locator, name, state);
}

/// <summary>
/// Generates locator for target element
/// </summary>
/// <param name="baseLocator">locator of parent element</param>
/// <param name="webElement">target element</param>
/// <param name="elementIndex">index of target element</param>
/// <returns>target element's locator</returns>
protected virtual By GenerateLocator(By baseLocator, IWebElement webElement, int elementIndex)
{
return GenerateXpathLocator(baseLocator, webElement, elementIndex);
}

/// <summary>
/// Generates xpath locator for target element
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Aquality.Selenium.Core.Configurations;
using Aquality.Selenium.Core.Logging;
using Aquality.Selenium.Core.Utilities;
using System.Linq;
using System;
using System.Reflection;

namespace Aquality.Selenium.Core.Localization
Expand All @@ -24,7 +24,7 @@ public LocalizationManager(ILoggerConfiguration loggerConfiguration, Logger logg
private static ISettingsFile GetLocalizationFile(string language, Assembly assembly)
{
var embeddedResourceName = string.Format(LangResource, language.ToLower());
var assemblyToUse = assembly.GetManifestResourceNames().Any(name => name.Contains(embeddedResourceName))
var assemblyToUse = Array.Exists(assembly.GetManifestResourceNames(), name => name.Contains(embeddedResourceName))
? assembly
: Assembly.GetExecutingAssembly();
return new JsonSettingsFile(embeddedResourceName, assemblyToUse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private Logger()
{
try
{
LogManager.LoadConfiguration("NLog.config");
LogManager.Setup().LoadConfigurationFromFile("NLog.config", optional: false);
}
catch (FileNotFoundException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static string GetVariable(string key)
//necessary for Azure
Environment.GetEnvironmentVariable(key.ToUpper().Replace('.', '_'))
};
return variables.FirstOrDefault(variable => variable != null);
return variables.Find(variable => variable != null);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
using Aquality.Selenium.Core.Applications;
using Aquality.Selenium.Core.Configurations;
using Aquality.Selenium.Core.Utilities;
using Microsoft.Extensions.DependencyInjection;
using System;
using WebDriverManager;
using WebDriverManager.DriverConfigs.Impl;
using WebDriverManager.Helpers;
using System.Collections.Generic;

namespace Aquality.Selenium.Core.Tests.Applications.Browser
{
public class AqualityServices : AqualityServices<ChromeApplication>
{
private static readonly object downloadDriverLock = new object();

public new static bool IsApplicationStarted => IsApplicationStarted();

public static ChromeApplication Application => GetApplication(services => StartChrome(services));
Expand All @@ -26,16 +23,13 @@ public static IServiceProvider ServiceProvider
{
SetServiceProvider(value);
}
}
}

private static ChromeApplication StartChrome(IServiceProvider services)
{
lock (downloadDriverLock)
{
new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser);
}

return new ChromeApplication(services.GetRequiredService<ITimeoutConfiguration>());
// temp workaround to handle ChromeDriver issue: https://groups.google.com/g/chromedriver-users/c/Dgv9xRHZf58
return services.GetService<IActionRetrier>().DoWithRetry(() =>
new ChromeApplication(services.GetRequiredService<ITimeoutConfiguration>()), new List<Type> { typeof(InvalidOperationException) });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

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

private IConditionalWait ConditionalWait => AqualityServices.ServiceProvider.GetRequiredService<IConditionalWait>();
private static IConditionalWait ConditionalWait => AqualityServices.ServiceProvider.GetRequiredService<IConditionalWait>();

[SetUp]
public new void SetUp()
{
Environment.SetEnvironmentVariable(ElementCacheVariableName, true.ToString());
}

private void StartLoading()
private static void StartLoading()
{
AqualityServices.Application.Driver.Navigate().GoToUrl(DynamicLoadingUrl);
GoToUrl(DynamicLoadingUrl);
new Label(StartLoc, "start", ElementState.Displayed).Click();
}

private void OpenDynamicContent()
private static void OpenDynamicContent()
{
AqualityServices.Application.Driver.Navigate().GoToUrl(DynamicContentUrl);
GoToUrl(DynamicContentUrl);
}

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

private void AssertStateConditionAfterReopen(Func<IElementStateProvider, bool> stateCondition, bool expectedValue)
private static void AssertStateConditionAfterReopen(Func<IElementStateProvider, bool> stateCondition, bool expectedValue)
{
Label testElement = null;
AqualityServices.ServiceProvider.GetRequiredService<IActionRetrier>().DoWithRetry(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void Should_BePossibleTo_UseConditionalWait_WithDriver()
{
Assert.DoesNotThrow(() => ConditionalWait.WaitFor(driver =>
{
driver.Navigate().GoToUrl(WikiURL);
GoToUrl(WikiURL, driver);
return driver.FindElements(By.XPath("//*")).Count > 0;
}));
}
Expand Down Expand Up @@ -100,7 +100,7 @@ bool elementFinderCondition() => ServiceProvider.GetRequiredService<IElementFind
Assert.IsFalse(elementFinderCondition());
Assert.DoesNotThrow(() => ConditionalWait.WaitFor(driver =>
{
driver.Navigate().GoToUrl(WikiURL);
GoToUrl(WikiURL, driver);
return elementFinderCondition();
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected virtual IList<T> FindElements<T>(By locator, string name = null, Eleme
public new void SetUp()
{
ElementFactory = ServiceProvider.GetRequiredService<IElementFactory>();
AqualityServices.Application.Driver.Navigate().GoToUrl(HoversURL);
GoToUrl(HoversURL);
ParentElement = new Label(ContentLoc, "Example", ElementState.Displayed);
ParentElement.Click();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Aquality.Selenium.Core.Applications;
using Aquality.Selenium.Core.Configurations;
using Aquality.Selenium.Core.Elements.Interfaces;
using Aquality.Selenium.Core.Tests.Applications.Browser.Elements;
using Aquality.Selenium.Core.Logging;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using OpenQA.Selenium;
using System;
using WebElementFactory = Aquality.Selenium.Core.Tests.Applications.Browser.Elements.WebElementFactory;

namespace Aquality.Selenium.Core.Tests.Applications.Browser
{
Expand All @@ -26,6 +28,20 @@ public void SetUp()
AqualityServices.ServiceProvider = ServiceProvider;
}

protected static void GoToUrl(Uri url, IWebDriver driver = null)
{
var driverInstance = driver ?? AqualityServices.Application.Driver;
// temporary workaround to avoid issue described at https://github.com/SeleniumHQ/selenium/issues/12277
try
{
driverInstance.Navigate().GoToUrl(url);
}
catch (WebDriverException e) when (driver.Url == url.ToString())
{
Logger.Instance.Fatal($"Random error occurred: [{e.Message}], but successfully navigated to URL [{url}]", e);
}
}

[TearDown]
public void CleanUp()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Appium.WebDriver" Version="5.0.0-beta03" />
<PackageReference Include="Appium.WebDriver" Version="5.0.0-beta04" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="nunit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2">
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="WebDriverManager" Version="2.16.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class FormDumpTests : TestWithBrowser
public new void SetUp()
{
var form = new WebForm();
AqualityServices.Application.Driver.Navigate().GoToUrl(HoversURL);
GoToUrl(HoversURL);
form.ClickOnContent();
form.WaitUntilPresent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed class ImageComparatorTests : TestWithBrowser
[SetUp]
public new void SetUp()
{
AqualityServices.Application.Driver.Navigate().GoToUrl(DynamicLoadingUrl);
GoToUrl(DynamicLoadingUrl);
}

private void StartLoading()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public sealed class VisualStateProviderTests : TestWithBrowser
[SetUp]
public new void SetUp()
{
AqualityServices.Application.Driver.Navigate().GoToUrl(DynamicLoadingUrl);
GoToUrl(DynamicLoadingUrl);
}

private void StartLoading()
Expand Down
1 change: 1 addition & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ stages:

- task: DotNetCoreCLI@2
displayName: 'Run tests'
retryCountOnTaskFailure: 1
inputs:
command: 'test'
projects: '**/*Tests*/*.csproj'
Expand Down