diff --git a/Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.csproj b/Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.csproj index 82d6cad0..fba187ed 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.csproj +++ b/Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.csproj @@ -59,7 +59,7 @@ - + diff --git a/Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserManager.cs b/Aquality.Selenium/src/Aquality.Selenium/Browsers/AqualityServices.cs similarity index 71% rename from Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserManager.cs rename to Aquality.Selenium/src/Aquality.Selenium/Browsers/AqualityServices.cs index fa554f85..a01ce9c4 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserManager.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Browsers/AqualityServices.cs @@ -1,19 +1,43 @@ using Microsoft.Extensions.DependencyInjection; using System; using System.Threading; -using Aquality.Selenium.Core.Applications; using Aquality.Selenium.Configurations; +using Aquality.Selenium.Core.Applications; +using Aquality.Selenium.Core.Localization; +using Aquality.Selenium.Core.Logging; +using Aquality.Selenium.Core.Waitings; namespace Aquality.Selenium.Browsers { /// /// Controls browser instance creation. /// - public class BrowserManager : ApplicationManager + public class AqualityServices : AqualityServices { private static readonly ThreadLocal BrowserStartupContainer = new ThreadLocal(() => new BrowserStartup()); private static readonly ThreadLocal BrowserFactoryContainer = new ThreadLocal(); + /// + /// Check if browser already started. + /// + /// true if browser started and false otherwise. + public static bool IsBrowserStarted => IsApplicationStarted(); + + /// + /// Gets registered instance of logger + /// + public static Logger Logger => Get(); + + /// + /// Gets registered instance of localized logger + /// + public static ILocalizedLogger LocalizedLogger => Get(); + + /// + /// Gets ConditionalWait object + /// + public static ConditionalWait ConditionalWait => Get(); + /// /// Gets and sets thread-safe instance of browser. /// @@ -26,12 +50,6 @@ public static Browser Browser private static Func StartBrowserFunction => services => BrowserFactory.Browser; - public static IServiceProvider ServiceProvider - { - get => GetServiceProvider(services => Browser, ConfigureServices); - set => SetServiceProvider(value); - } - /// /// Method which allow user to override or add custom services. /// @@ -68,15 +86,15 @@ public static IBrowserFactory BrowserFactory /// public static void SetDefaultFactory() { - var appProfile = GetRequiredService(); + var appProfile = Get(); IBrowserFactory applicationFactory; if (appProfile.IsRemote) { - applicationFactory = new RemoteBrowserFactory(ServiceProvider); + applicationFactory = new RemoteBrowserFactory(); } else { - applicationFactory = new LocalBrowserFactory(ServiceProvider); + applicationFactory = new LocalBrowserFactory(); } BrowserFactory = applicationFactory; @@ -88,11 +106,13 @@ public static void SetDefaultFactory() /// type of required service. /// Thrown if there is no service of the required type. /// - public static T GetRequiredService() + public static T Get() { return ServiceProvider.GetRequiredService(); } + private static IServiceProvider ServiceProvider => GetServiceProvider(services => Browser, ConfigureServices); + private static IServiceCollection ConfigureServices() { return BrowserStartupContainer.Value.ConfigureServices(new ServiceCollection(), services => Browser); diff --git a/Aquality.Selenium/src/Aquality.Selenium/Browsers/Browser.cs b/Aquality.Selenium/src/Aquality.Selenium/Browsers/Browser.cs index 1ec74c60..4f39a2c6 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Browsers/Browser.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Browsers/Browser.cs @@ -7,7 +7,6 @@ using System.Drawing; using System.Reflection; using System; -using Microsoft.Extensions.DependencyInjection; using Aquality.Selenium.Core.Waitings; namespace Aquality.Selenium.Browsers @@ -26,14 +25,14 @@ public class Browser : IApplication /// Instantiate browser. /// /// Instance of Selenium WebDriver for desired web browser. - public Browser(RemoteWebDriver webDriver, IServiceProvider serviceProvider) + public Browser(RemoteWebDriver webDriver) { Driver = webDriver; - Logger = serviceProvider.GetRequiredService(); - LocalizationManager = serviceProvider.GetRequiredService(); - browserProfile = serviceProvider.GetRequiredService(); - conditionalWait = serviceProvider.GetRequiredService(); - var timeoutConfiguration = serviceProvider.GetRequiredService(); + Logger = AqualityServices.LocalizedLogger; + LocalizationManager = AqualityServices.Get(); + browserProfile = AqualityServices.Get(); + conditionalWait = AqualityServices.ConditionalWait; + var timeoutConfiguration = AqualityServices.Get(); SetImplicitWaitTimeout(timeoutConfiguration.Implicit); SetPageLoadTimeout(timeoutConfiguration.PageLoad); SetScriptTimeout(timeoutConfiguration.Script); diff --git a/Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserFactory.cs b/Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserFactory.cs index 52e572f1..c1432ad4 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserFactory.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserFactory.cs @@ -1,19 +1,14 @@ -using System; - -namespace Aquality.Selenium.Browsers +namespace Aquality.Selenium.Browsers { /// /// Abstract representation of . /// public abstract class BrowserFactory : IBrowserFactory { - protected BrowserFactory(IServiceProvider serviceProvider) + protected BrowserFactory() { - ServiceProvider = serviceProvider; } - protected IServiceProvider ServiceProvider { get; } - public abstract Browser Browser { get; } } } diff --git a/Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserNavigation.cs b/Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserNavigation.cs index 89a2b92c..10ab4815 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserNavigation.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserNavigation.cs @@ -17,7 +17,7 @@ internal BrowserNavigation(RemoteWebDriver driver) this.driver = driver; } - private ILocalizedLogger Logger => BrowserManager.GetRequiredService(); + private ILocalizedLogger Logger => AqualityServices.LocalizedLogger; /// /// Navigates back. diff --git a/Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserStartup.cs b/Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserStartup.cs index 406ebe58..05926dca 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserStartup.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserStartup.cs @@ -29,7 +29,7 @@ public override IServiceCollection ConfigureServices(IServiceCollection services services.AddSingleton(serviceProvider => new TimeoutConfiguration(settings)); services.AddSingleton(serviceProvider => new BrowserProfile(settings)); services.AddSingleton(serviceProvider => new LocalizationManager(serviceProvider.GetRequiredService(), serviceProvider.GetRequiredService(), Assembly.GetExecutingAssembly())); - services.AddTransient(serviceProvider => BrowserManager.BrowserFactory); + services.AddTransient(serviceProvider => AqualityServices.BrowserFactory); return services; } } diff --git a/Aquality.Selenium/src/Aquality.Selenium/Browsers/LocalBrowserFactory.cs b/Aquality.Selenium/src/Aquality.Selenium/Browsers/LocalBrowserFactory.cs index c7c5e698..cbc5dabe 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Browsers/LocalBrowserFactory.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Browsers/LocalBrowserFactory.cs @@ -1,6 +1,5 @@ using Aquality.Selenium.Configurations; using Aquality.Selenium.Configurations.WebDriverSettings; -using Microsoft.Extensions.DependencyInjection; using OpenQA.Selenium.Chrome; using OpenQA.Selenium.Edge; using OpenQA.Selenium.Firefox; @@ -23,7 +22,7 @@ public class LocalBrowserFactory : BrowserFactory { private static readonly object WebDriverDownloadingLock = new object(); - public LocalBrowserFactory(IServiceProvider serviceProvider) : base(serviceProvider) + public LocalBrowserFactory() : base() { } @@ -31,7 +30,7 @@ public LocalBrowserFactory(IServiceProvider serviceProvider) : base(serviceProvi private Browser CreateBrowser() { - var browserProfile = ServiceProvider.GetRequiredService(); + var browserProfile = AqualityServices.Get(); var browserName = browserProfile.BrowserName; var driverSettings = browserProfile.DriverSettings; RemoteWebDriver driver; @@ -58,7 +57,7 @@ private Browser CreateBrowser() default: throw new ArgumentOutOfRangeException($"Browser {browserName} is not supported."); } - return new Browser(driver, ServiceProvider); + return new Browser(driver); } private static void SetUpDriver(IDriverConfig driverConfig, IDriverSettings driverSettings) diff --git a/Aquality.Selenium/src/Aquality.Selenium/Browsers/RemoteBrowserFactory.cs b/Aquality.Selenium/src/Aquality.Selenium/Browsers/RemoteBrowserFactory.cs index 1b54b922..d90961cb 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Browsers/RemoteBrowserFactory.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Browsers/RemoteBrowserFactory.cs @@ -1,7 +1,5 @@ using Aquality.Selenium.Configurations; -using Microsoft.Extensions.DependencyInjection; using OpenQA.Selenium.Remote; -using System; namespace Aquality.Selenium.Browsers { @@ -10,7 +8,7 @@ namespace Aquality.Selenium.Browsers /// public class RemoteBrowserFactory : BrowserFactory { - public RemoteBrowserFactory(IServiceProvider serviceProvider) : base(serviceProvider) + public RemoteBrowserFactory() : base() { } @@ -18,11 +16,11 @@ public override Browser Browser { get { - var browserProfile = ServiceProvider.GetRequiredService(); + var browserProfile = AqualityServices.Get(); var capabilities = browserProfile.DriverSettings.DriverOptions.ToCapabilities(); - var timeoutConfiguration = ServiceProvider.GetRequiredService(); + var timeoutConfiguration = AqualityServices.Get(); var driver = new RemoteWebDriver(browserProfile.RemoteConnectionUrl, capabilities, timeoutConfiguration.Command); - return new Browser(driver, ServiceProvider); + return new Browser(driver); } } } diff --git a/Aquality.Selenium/src/Aquality.Selenium/Elements/Actions/JsActions.cs b/Aquality.Selenium/src/Aquality.Selenium/Elements/Actions/JsActions.cs index aec04fc5..4a0914cc 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Elements/Actions/JsActions.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Elements/Actions/JsActions.cs @@ -27,7 +27,7 @@ public JsActions(IElement element, string elementType, ILocalizedLogger logger, Logger = logger; } - private Browser Browser => BrowserManager.Browser; + private Browser Browser => AqualityServices.Browser; protected ILocalizedLogger Logger { get; } diff --git a/Aquality.Selenium/src/Aquality.Selenium/Elements/Actions/MouseActions.cs b/Aquality.Selenium/src/Aquality.Selenium/Elements/Actions/MouseActions.cs index 1e3d8703..832b8ae8 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Elements/Actions/MouseActions.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Elements/Actions/MouseActions.cs @@ -28,7 +28,7 @@ public MouseActions(IElement element, string elementType, ILocalizedLogger logge this.elementActionsRetrier = elementActionsRetrier; } - private JsActions JsActions => new JsActions(element, elementType, logger, BrowserManager.GetRequiredService()); + private JsActions JsActions => new JsActions(element, elementType, logger, AqualityServices.Get()); /// /// Performs click on element. @@ -65,12 +65,12 @@ public void MoveToElement() { LogElementAction("loc.moving"); JsActions.ScrollIntoView(); - elementActionsRetrier.DoWithRetry(() => PerformAction(element => MoveToElement(element))); + elementActionsRetrier.DoWithRetry(() => PerformAction(MoveToElement)); } private SeleniumActions MoveToElement(IWebElement element) { - return new SeleniumActions(BrowserManager.Browser.Driver).MoveToElement(element); + return new SeleniumActions(AqualityServices.Browser.Driver).MoveToElement(element); } private void PerformAction(Func action) diff --git a/Aquality.Selenium/src/Aquality.Selenium/Elements/Element.cs b/Aquality.Selenium/src/Aquality.Selenium/Elements/Element.cs index 045b4f65..02c7cf55 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Elements/Element.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Elements/Element.cs @@ -26,7 +26,7 @@ protected Element(By locator, string name, ElementState state) : base(locator, n public override CoreElementStateProvider State => new ElementStateProvider(Locator, ConditionalWait, Finder); - protected IBrowserProfile BrowserProfile => BrowserManager.GetRequiredService(); + protected IBrowserProfile BrowserProfile => AqualityServices.Get(); public JsActions JsActions => new JsActions(this, ElementType, LocalizedLogger, BrowserProfile); @@ -34,21 +34,21 @@ protected Element(By locator, string name, ElementState state) : base(locator, n private Browser Browser => (Browser)Application; - protected override IApplication Application => BrowserManager.Browser; + protected override IApplication Application => AqualityServices.Browser; - protected override ElementActionRetrier ActionRetrier => BrowserManager.GetRequiredService(); + protected override ElementActionRetrier ActionRetrier => AqualityServices.Get(); protected override CoreElementFactory Factory => CustomFactory; - protected virtual IElementFactory CustomFactory => BrowserManager.GetRequiredService(); + protected virtual IElementFactory CustomFactory => AqualityServices.Get(); - protected override CoreElementFinder Finder => BrowserManager.GetRequiredService(); + protected override CoreElementFinder Finder => AqualityServices.Get(); - protected override ILocalizedLogger LocalizedLogger => BrowserManager.GetRequiredService(); + protected override ILocalizedLogger LocalizedLogger => AqualityServices.LocalizedLogger; - protected ILocalizationManager LocalizationManager => BrowserManager.GetRequiredService(); + protected ILocalizationManager LocalizationManager => AqualityServices.Get(); - protected override ConditionalWait ConditionalWait => BrowserManager.GetRequiredService(); + protected override ConditionalWait ConditionalWait => AqualityServices.ConditionalWait; public void ClickAndWait() { diff --git a/Aquality.Selenium/src/Aquality.Selenium/Forms/Form.cs b/Aquality.Selenium/src/Aquality.Selenium/Forms/Form.cs index f7b707c1..ccac756a 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Forms/Form.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Forms/Form.cs @@ -36,13 +36,13 @@ protected Form(By locator, string name) /// Instance of logger /// /// Logger instance. - protected ILocalizedLogger Logger => BrowserManager.GetRequiredService(); + protected ILocalizedLogger Logger => AqualityServices.LocalizedLogger; /// /// Element factory /// /// Element factory. - protected IElementFactory ElementFactory => BrowserManager.GetRequiredService(); + protected IElementFactory ElementFactory => AqualityServices.Get(); /// /// Return form state for form locator diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Actions/JsActionsTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Actions/JsActionsTests.cs index d827ab8e..98c8280e 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Actions/JsActionsTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Actions/JsActionsTests.cs @@ -4,7 +4,6 @@ using System.Linq; using Aquality.Selenium.Browsers; using Aquality.Selenium.Core.Elements; -using Aquality.Selenium.Core.Waitings; using Aquality.Selenium.Elements; using Aquality.Selenium.Tests.Integration.TestApp; using Aquality.Selenium.Tests.Integration.TestApp.AutomationPractice.Forms; @@ -48,7 +47,7 @@ public void Should_BePossibleTo_HighlightElement() [Test] public void Should_BePossibleTo_HoverMouse() { - BrowserManager.Browser.GoTo(Constants.UrlAutomationPractice); + AqualityServices.Browser.GoTo(Constants.UrlAutomationPractice); var productList = new ProductListForm(); productList.NavigateToLastProduct(); @@ -61,7 +60,7 @@ public void Should_BePossibleTo_HoverMouse() [Test] public void Should_BePossibleTo_SetFocus() { - BrowserManager.Browser.GoTo(Constants.UrlAutomationPractice); + AqualityServices.Browser.GoTo(Constants.UrlAutomationPractice); var productList = new ProductListForm(); productList.NavigateToLastProduct(); @@ -134,7 +133,7 @@ public void Should_BePossibleTo_ScrollIntoView() infiniteScrollForm.WaitForPageToLoad(); var defaultCount = infiniteScrollForm.ExampleLabels.Count; Assert.DoesNotThrow( - () => BrowserManager.GetRequiredService().WaitForTrue(() => + () => AqualityServices.ConditionalWait.WaitForTrue(() => { infiniteScrollForm.LastExampleLabel.JsActions.ScrollIntoView(); return infiniteScrollForm.ExampleLabels.Count > defaultCount; @@ -148,7 +147,7 @@ public void Should_BePossibleTo_ScrollBy() var homeDemoSiteForm = new HomeDemoSiteForm(); homeDemoSiteForm.Open(); homeDemoSiteForm.FirstScrollableExample.JsActions.ScrollBy(point.X, point.Y); - var currentCoordinates = BrowserManager.Browser + var currentCoordinates = AqualityServices.Browser .ExecuteScriptFromFile>("Resources.GetScrollCoordinates.js", homeDemoSiteForm.FirstScrollableExample.GetElement()).Select(item => int.Parse(item.ToString())) .ToList(); @@ -164,8 +163,8 @@ public void Should_BePossibleTo_ScrollToTheCenter() welcomeForm.Open(); welcomeForm.GetExampleLink(AvailableExample.Dropdown).JsActions.ScrollToTheCenter(); - var windowSize = BrowserManager.Browser.ExecuteScriptFromFile("Resources.GetWindowSize.js").ToString(); - var currentY = BrowserManager.Browser.ExecuteScriptFromFile("Resources.GetElementYCoordinate.js", + var windowSize = AqualityServices.Browser.ExecuteScriptFromFile("Resources.GetWindowSize.js").ToString(); + var currentY = AqualityServices.Browser.ExecuteScriptFromFile("Resources.GetElementYCoordinate.js", welcomeForm.GetExampleLink(AvailableExample.Dropdown).GetElement()).ToString(); var coordinateRelatingWindowCenter = double.Parse(windowSize) / 2 - double.Parse(currentY); Assert.LessOrEqual(Math.Abs(coordinateRelatingWindowCenter), accuracy, "Upper bound of element should be in the center of the page"); @@ -179,7 +178,7 @@ public void Should_BePossibleTo_ScrollToTheCenter_CheckUI() infiniteScrollForm.WaitForPageToLoad(); var defaultCount = infiniteScrollForm.ExampleLabels.Count; Assert.DoesNotThrow( - () => BrowserManager.GetRequiredService().WaitForTrue(() => + () => AqualityServices.ConditionalWait.WaitForTrue(() => { infiniteScrollForm.Footer.JsActions.ScrollToTheCenter(); return infiniteScrollForm.ExampleLabels.Count > defaultCount; diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Actions/MouseActionsTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Actions/MouseActionsTests.cs index c25d268b..0c72ca89 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Actions/MouseActionsTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Actions/MouseActionsTests.cs @@ -33,13 +33,13 @@ public void Should_BePossibleTo_RightClick() var contextMenuForm = new ContextMenuForm(); contextMenuForm.Open(); contextMenuForm.HotSpotLabel.MouseActions.RightClick(); - Assert.DoesNotThrow(() => BrowserManager.Browser.HandleAlert(AlertAction.Decline), "Alert should be opened after right click"); + Assert.DoesNotThrow(() => AqualityServices.Browser.HandleAlert(AlertAction.Decline), "Alert should be opened after right click"); } [Test] public void Should_BePossibleTo_MoveToElement() { - BrowserManager.Browser.GoTo(Constants.UrlAutomationPractice); + AqualityServices.Browser.GoTo(Constants.UrlAutomationPractice); var productList = new ProductListForm(); productList.NavigateToLastProduct(); diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/AlertTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/AlertTests.cs index 6b8eafe0..f74f4e18 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/AlertTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/AlertTests.cs @@ -19,7 +19,7 @@ public void BeforeTest() public void Should_BePossibleTo_AcceptAlert() { alertsForm.JsAlertButton.Click(); - BrowserManager.Browser.HandleAlert(AlertAction.Accept); + AqualityServices.Browser.HandleAlert(AlertAction.Accept); Assert.AreEqual("You successfuly clicked an alert", alertsForm.ResultLabel.GetText()); } @@ -27,7 +27,7 @@ public void Should_BePossibleTo_AcceptAlert() public void Should_BePossibleTo_AcceptConfirmationAlert() { alertsForm.JsConfirmButton.Click(); - BrowserManager.Browser.HandleAlert(AlertAction.Accept); + AqualityServices.Browser.HandleAlert(AlertAction.Accept); Assert.AreEqual("You clicked: Ok", alertsForm.ResultLabel.GetText()); } @@ -35,7 +35,7 @@ public void Should_BePossibleTo_AcceptConfirmationAlert() public void Should_BePossibleTo_DeclineConfirmationAlert() { alertsForm.JsConfirmButton.Click(); - BrowserManager.Browser.HandleAlert(AlertAction.Decline); + AqualityServices.Browser.HandleAlert(AlertAction.Decline); Assert.AreEqual("You clicked: Cancel", alertsForm.ResultLabel.GetText()); } @@ -44,7 +44,7 @@ public void Should_BePossibleTo_AcceptPromptAlertWithText() { alertsForm.JsPromptButton.Click(); var text = "accept alert text"; - BrowserManager.Browser.HandleAlert(AlertAction.Accept, text); + AqualityServices.Browser.HandleAlert(AlertAction.Accept, text); Assert.AreEqual($"You entered: {text}", alertsForm.ResultLabel.GetText()); } @@ -52,20 +52,20 @@ public void Should_BePossibleTo_AcceptPromptAlertWithText() public void Should_BePossibleTo_DeclinePromptAlertWithText() { alertsForm.JsPromptButton.Click(); - BrowserManager.Browser.HandleAlert(AlertAction.Decline, "decline alert text"); + AqualityServices.Browser.HandleAlert(AlertAction.Decline, "decline alert text"); Assert.AreEqual("You entered: null", alertsForm.ResultLabel.GetText()); } [Test] public void Should_Throw_NoAlertPresentExceptionIfNoAlertPresent() { - Assert.Throws(() => BrowserManager.Browser.HandleAlert(AlertAction.Decline)); + Assert.Throws(() => AqualityServices.Browser.HandleAlert(AlertAction.Decline)); } [Test] public void Should_Throw_NoAlertPresentExceptionIfNoPromptAlertPresent() { - Assert.Throws(() => BrowserManager.Browser.HandleAlert(AlertAction.Decline, "Hello")); + Assert.Throws(() => AqualityServices.Browser.HandleAlert(AlertAction.Decline, "Hello")); } } } diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/BrowserTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/BrowserTests.cs index 4f989b41..f8596363 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/BrowserTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/BrowserTests.cs @@ -19,7 +19,7 @@ internal class BrowserTests : UITest public void Should_BePossibleTo_StartBrowserAndNavigate() { var url = new WelcomeForm().Url; - var browser = BrowserManager.Browser; + var browser = AqualityServices.Browser; browser.GoTo(url); Assert.AreEqual(browser.CurrentUrl, url); } @@ -28,7 +28,7 @@ public void Should_BePossibleTo_StartBrowserAndNavigate() public void Should_BePossibleTo_GetWebDriverInstance() { var url = new WelcomeForm().Url; - var browser = BrowserManager.Browser; + var browser = AqualityServices.Browser; browser.Driver.Navigate().GoToUrl(url); Assert.AreEqual(browser.Driver.Url, url); } @@ -39,7 +39,7 @@ public void Should_BePossibleTo_NavigateBackAndForward() var firstNavigationUrl = new WelcomeForm().Url; var secondNavigationUrl = new CheckBoxesForm().Url; - var browser = BrowserManager.Browser; + var browser = AqualityServices.Browser; browser.GoTo(firstNavigationUrl); Assert.AreEqual(browser.CurrentUrl, firstNavigationUrl); @@ -58,9 +58,9 @@ public void Should_BePossibleTo_OpenNewBrowserAfterQuit() { var welcomeForm = new WelcomeForm(); welcomeForm.Open(); - BrowserManager.Browser.Quit(); + AqualityServices.Browser.Quit(); - Assert.AreNotEqual(welcomeForm.Url, BrowserManager.Browser.CurrentUrl); + Assert.AreNotEqual(welcomeForm.Url, AqualityServices.Browser.CurrentUrl); } [Test] @@ -70,7 +70,7 @@ public void Should_BePossibleTo_RefreshPage() dynamicContentForm.Open(); var firstItem = dynamicContentForm.GetContentItem(1).GetText(); - var browser = BrowserManager.Browser; + var browser = AqualityServices.Browser; browser.Refresh(); browser.WaitForPageToLoad(); @@ -81,7 +81,7 @@ public void Should_BePossibleTo_RefreshPage() [Test] public void Should_BePossibleTo_SetPageLoadTimeout() { - var browser = BrowserManager.Browser; + var browser = AqualityServices.Browser; browser.SetPageLoadTimeout(TimeSpan.FromSeconds(1)); Assert.Throws(() => browser.GoTo("https://github.com/aquality-automation")); } @@ -90,7 +90,7 @@ public void Should_BePossibleTo_SetPageLoadTimeout() public void Should_BePossibleTo_TakeScreenshot() { new DynamicContentForm().Open(); - Assert.IsTrue(BrowserManager.Browser.GetScreenshot().Length > 0); + Assert.IsTrue(AqualityServices.Browser.GetScreenshot().Length > 0); } [Test] @@ -98,7 +98,7 @@ public void Should_BePossibleTo_ExecuteJavaScript() { var dynamicContentForm = new DynamicContentForm(); dynamicContentForm.Open(); - var currentUrl = BrowserManager.Browser.ExecuteScript("return window.location.href"); + var currentUrl = AqualityServices.Browser.ExecuteScript("return window.location.href"); Assert.AreEqual(dynamicContentForm.Url, currentUrl); } @@ -112,7 +112,7 @@ public void Should_BePossibleTo_ExecuteAsyncJavaScript() var stopwatch = new Stopwatch(); stopwatch.Start(); - BrowserManager.Browser.ExecuteAsyncScript(GetAsyncTimeoutJavaScript(expectedDurationInSeconds)); + AqualityServices.Browser.ExecuteAsyncScript(GetAsyncTimeoutJavaScript(expectedDurationInSeconds)); stopwatch.Stop(); var durationSeconds = stopwatch.Elapsed.TotalSeconds; @@ -127,8 +127,8 @@ public void Should_BePossibleTo_ExecuteAsyncJavaScript() public void Should_BePossibleTo_ExecuteAsyncJavaScript_WithScriptTimeoutException() { new DynamicContentForm().Open(); - var expectedDurationInSeconds = BrowserManager.GetRequiredService().Script.TotalSeconds + 1; - Assert.Throws(() => BrowserManager.Browser.ExecuteAsyncScript(GetAsyncTimeoutJavaScript(expectedDurationInSeconds))); + var expectedDurationInSeconds = AqualityServices.Get().Script.TotalSeconds + 1; + Assert.Throws(() => AqualityServices.Browser.ExecuteAsyncScript(GetAsyncTimeoutJavaScript(expectedDurationInSeconds))); } private string GetAsyncTimeoutJavaScript(double expectedDurationInSeconds) @@ -141,7 +141,7 @@ public void Should_BePossibleTo_ExecuteJavaScriptFromFile() { var dynamicContentForm = new DynamicContentForm(); dynamicContentForm.Open(); - var currentUrl = BrowserManager.Browser.ExecuteScriptFromFile("Resources.GetCurrentUrl.js"); + var currentUrl = AqualityServices.Browser.ExecuteScriptFromFile("Resources.GetCurrentUrl.js"); Assert.AreEqual(dynamicContentForm.Url, currentUrl); } @@ -151,7 +151,7 @@ public void Should_BePossibleTo_ExecuteJavaScriptFromPredefinedFile() var valueToSet = "username"; var authForm = new TheInternetAuthenticationForm(); authForm.Open(); - BrowserManager.Browser.ExecuteScript(JavaScript.SetValue, authForm.UserNameTextBox.GetElement(), valueToSet); + AqualityServices.Browser.ExecuteScript(JavaScript.SetValue, authForm.UserNameTextBox.GetElement(), valueToSet); Assert.AreEqual(valueToSet, authForm.UserNameTextBox.Value); } @@ -159,7 +159,7 @@ public void Should_BePossibleTo_ExecuteJavaScriptFromPredefinedFile() public void Should_BePossibleTo_SetWindowSize() { var defaultSize = new Size(1024, 768); - var browser = BrowserManager.Browser; + var browser = AqualityServices.Browser; var initialSize = browser.Driver.Manage().Window.Size; var testSize = new Size(600, 600); @@ -189,7 +189,7 @@ public void Should_BePossibleTo_SetWindowSize() [Test] public void Should_BePossibleTo_ScrollWindowBy() { - var browser = BrowserManager.Browser; + var browser = AqualityServices.Browser; browser.GoTo(Constants.UrlAutomationPractice); var sliderForm = new SliderForm(); var initialY = sliderForm.FormPointInViewPort.Y; @@ -205,13 +205,13 @@ public void Should_BePossibleTo_GetBrowserName() var settingsProfile = profileNameFromEnvironment == null ? "settings.json" : $"settings.{profileNameFromEnvironment}.json"; var settingsFile = new JsonSettingsFile(settingsProfile); var browserName = (BrowserName)Enum.Parse(typeof(BrowserName), settingsFile.GetValue(".browserName"), ignoreCase: true); - Assert.AreEqual(browserName, BrowserManager.Browser.BrowserName); + Assert.AreEqual(browserName, AqualityServices.Browser.BrowserName); } [Test] public void Should_BePossibleTo_SetImplicitWait() { - var browser = BrowserManager.Browser; + var browser = AqualityServices.Browser; new WelcomeForm().Open(); var waitTime = TimeSpan.FromSeconds(5); browser.SetImplicitWaitTimeout(waitTime); @@ -237,7 +237,7 @@ public void Should_BePossibleTo_SetImplicitWait() [Test] public void Should_BePossibleTo_GetDownloadDir() { - var downloadDir = BrowserManager.Browser.DownloadDirectory; + var downloadDir = AqualityServices.Browser.DownloadDirectory; Assert.IsTrue(downloadDir.ToLower().Contains("downloads", StringComparison.InvariantCultureIgnoreCase)); } } diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Elements/ComboBoxTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Elements/ComboBoxTests.cs index 2d299c12..12ae492d 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Elements/ComboBoxTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Elements/ComboBoxTests.cs @@ -1,5 +1,4 @@ using Aquality.Selenium.Browsers; -using Aquality.Selenium.Core.Waitings; using Aquality.Selenium.Tests.Integration.TestApp.TheInternet.Forms; using NUnit.Framework; @@ -33,7 +32,7 @@ public void Should_BePossibleTo_SelectByText() var comboBox = dropdownForm.ComboBox; var selectedText = comboBox.SelectedText; comboBox.SelectByText(Option2); - BrowserManager.GetRequiredService().WaitFor(() => !selectedText.Equals(comboBox.SelectedText)); + AqualityServices.ConditionalWait.WaitFor(() => !selectedText.Equals(comboBox.SelectedText)); Assert.AreEqual(comboBox.Texts[2], comboBox.JsActions.GetSelectedText()); } @@ -43,7 +42,7 @@ public void Should_BePossibleTo_SelectByValue() var comboBox = dropdownForm.ComboBox; var selectedText = comboBox.SelectedText; comboBox.SelectByValue("2"); - BrowserManager.GetRequiredService().WaitFor(() => !selectedText.Equals(comboBox.SelectedText)); + AqualityServices.ConditionalWait.WaitFor(() => !selectedText.Equals(comboBox.SelectedText)); Assert.AreEqual(comboBox.Texts[2], comboBox.JsActions.GetSelectedText()); } diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Elements/LinkTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Elements/LinkTests.cs index 425caca9..93e92f10 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Elements/LinkTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Elements/LinkTests.cs @@ -1,5 +1,4 @@ using Aquality.Selenium.Browsers; -using Aquality.Selenium.Core.Waitings; using Aquality.Selenium.Tests.Integration.TestApp.TheInternet.Forms; using NUnit.Framework; using System; @@ -22,21 +21,21 @@ public void Should_BePossibleTo_Click() var link = redirectorForm.RedirectLink; link.Click(); WaitForRedirect(); - Assert.AreEqual(new StatusCodesForm().Url.ToLower(), BrowserManager.Browser.CurrentUrl.ToLower()); + Assert.AreEqual(new StatusCodesForm().Url.ToLower(), AqualityServices.Browser.CurrentUrl.ToLower()); } [Test] public void Should_BePossibleTo_GetHref() { var link = redirectorForm.RedirectLink; - BrowserManager.Browser.GoTo(link.Href); + AqualityServices.Browser.GoTo(link.Href); WaitForRedirect(); - Assert.AreEqual(new StatusCodesForm().Url.ToLower(), BrowserManager.Browser.CurrentUrl.ToLower()); + Assert.AreEqual(new StatusCodesForm().Url.ToLower(), AqualityServices.Browser.CurrentUrl.ToLower()); } private void WaitForRedirect() { - BrowserManager.GetRequiredService().WaitFor(() => BrowserManager.Browser.CurrentUrl.Equals(new StatusCodesForm().Url, StringComparison.OrdinalIgnoreCase)); + AqualityServices.ConditionalWait.WaitFor(() => AqualityServices.Browser.CurrentUrl.Equals(new StatusCodesForm().Url, StringComparison.OrdinalIgnoreCase)); } } } diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Elements/TextBoxTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Elements/TextBoxTests.cs index e48b14ca..07357c36 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Elements/TextBoxTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Elements/TextBoxTests.cs @@ -1,5 +1,4 @@ using Aquality.Selenium.Browsers; -using Aquality.Selenium.Core.Waitings; using Aquality.Selenium.Elements; using Aquality.Selenium.Tests.Integration.TestApp.TheInternet.Forms; using NUnit.Framework; @@ -51,7 +50,7 @@ public void Should_BePossibleTo_Submit() { var passwordTxb = authForm.PasswordTextBox; passwordTxb.Submit(); - Assert.IsTrue(BrowserManager.GetRequiredService().WaitFor(() => passwordTxb.Value.Equals("", StringComparison.OrdinalIgnoreCase))); + Assert.IsTrue(AqualityServices.ConditionalWait.WaitFor(() => passwordTxb.Value.Equals("", StringComparison.OrdinalIgnoreCase))); } [Test] diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/HiddenElementsTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/HiddenElementsTests.cs index 95e75224..c9a30b30 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/HiddenElementsTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/HiddenElementsTests.cs @@ -15,7 +15,7 @@ internal class HiddenElementsTests : UITest [SetUp] public void BeforeTest() { - BrowserManager.Browser.GoTo(Constants.UrlAutomationPractice); + AqualityServices.Browser.GoTo(Constants.UrlAutomationPractice); } [Test] diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/AutomationPractice/Forms/ProductListForm.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/AutomationPractice/Forms/ProductListForm.cs index 1868aa93..cfd376c5 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/AutomationPractice/Forms/ProductListForm.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/AutomationPractice/Forms/ProductListForm.cs @@ -26,7 +26,7 @@ public ProductListForm() : base(By.XPath(FormLocator), "Product list") public void NavigateToLastProduct() { - BrowserManager.Browser.GoTo(GetLastProduct().Href); + AqualityServices.Browser.GoTo(GetLastProduct().Href); } public ILink GetLastProduct() @@ -43,7 +43,7 @@ public void AddRandomProductToCart() { var products = ProductContainerLabels; var productToAdd = products[random.Next(products.Count)]; - BrowserManager.Browser.ExecuteScript(JavaScript.ScrollToElement, productToAdd.GetElement()); + AqualityServices.Browser.ExecuteScript(JavaScript.ScrollToElement, productToAdd.GetElement()); productToAdd.MouseActions.MoveToElement(); GetAddCardButton(productToAdd).JsActions.Click(); } diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheDemoSite/Forms/TheDemoSiteForm.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheDemoSite/Forms/TheDemoSiteForm.cs index cf1988bd..db280957 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheDemoSite/Forms/TheDemoSiteForm.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheDemoSite/Forms/TheDemoSiteForm.cs @@ -18,8 +18,8 @@ protected TheDemoSiteForm(By locator, string name) : base(locator, name) public void Open() { - BrowserManager.Browser.GoTo(Url); - BrowserManager.Browser.WaitForPageToLoad(); + AqualityServices.Browser.GoTo(Url); + AqualityServices.Browser.WaitForPageToLoad(); } } } diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/InfiniteScrollForm.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/InfiniteScrollForm.cs index a595f828..b791e501 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/InfiniteScrollForm.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/InfiniteScrollForm.cs @@ -2,7 +2,6 @@ using System.Linq; using Aquality.Selenium.Browsers; using Aquality.Selenium.Configurations; -using Aquality.Selenium.Core.Waitings; using Aquality.Selenium.Elements.Interfaces; using OpenQA.Selenium; @@ -25,7 +24,7 @@ public InfiniteScrollForm() : base(By.XPath("//div[@id='content' and .//h3[conta public void WaitForPageToLoad() { var examplesCount = ExampleLabels.Count; - BrowserManager.GetRequiredService().WaitFor(() => examplesCount != ExampleLabels.Count, BrowserManager.GetRequiredService().Script); + AqualityServices.ConditionalWait.WaitFor(() => examplesCount != ExampleLabels.Count, AqualityServices.Get().Script); } } } diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/TheInternetForm.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/TheInternetForm.cs index 06c4d573..376ea707 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/TheInternetForm.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheInternet/Forms/TheInternetForm.cs @@ -18,8 +18,8 @@ protected TheInternetForm(By locator, string name) : base(locator, name) public void Open() { - BrowserManager.Browser.GoTo(Url); - BrowserManager.Browser.WaitForPageToLoad(); + AqualityServices.Browser.GoTo(Url); + AqualityServices.Browser.WaitForPageToLoad(); } } } diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/UITest.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/UITest.cs index d4d5788a..8faffede 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/UITest.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/UITest.cs @@ -11,7 +11,7 @@ internal class UITest [TearDown] public void CleanUp() { - BrowserManager.Browser.Quit(); + AqualityServices.Browser.Quit(); } } } diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/BrowserConcurrencyTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/BrowserConcurrencyTests.cs index e736cda5..8d0c43a1 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/BrowserConcurrencyTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/BrowserConcurrencyTests.cs @@ -14,15 +14,15 @@ public void Should_BePossibleTo_CreateDifferentBrowsersInDifferentThreads() { var checkBoxesForm = new CheckBoxesForm(); checkBoxesForm.Open(); - Assert.AreEqual(checkBoxesForm.Url, BrowserManager.Browser.CurrentUrl); - BrowserManager.Browser.Quit(); + Assert.AreEqual(checkBoxesForm.Url, AqualityServices.Browser.CurrentUrl); + AqualityServices.Browser.Quit(); }); var thread02 = new Thread(() => { var authForm = new AuthenticationForm(); authForm.Open(); - Assert.AreEqual(authForm.Url, BrowserManager.Browser.CurrentUrl); - BrowserManager.Browser.Quit(); + Assert.AreEqual(authForm.Url, AqualityServices.Browser.CurrentUrl); + AqualityServices.Browser.Quit(); }); thread01.Start(); diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/CustomBrowserFactoryTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/CustomBrowserFactoryTests.cs index 23350f6e..6d046b80 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/CustomBrowserFactoryTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/CustomBrowserFactoryTests.cs @@ -23,32 +23,32 @@ internal class CustomBrowserFactoryTests public void Should_BePossibleToUse_BrowserFromCustomFactory() { var browserFactory = new CustomLocalBrowserFactory(); - BrowserManager.Browser = browserFactory.Browser; - BrowserManager.Browser.GoTo(url); - Assert.AreEqual(url, BrowserManager.Browser.CurrentUrl); + AqualityServices.Browser = browserFactory.Browser; + AqualityServices.Browser.GoTo(url); + Assert.AreEqual(url, AqualityServices.Browser.CurrentUrl); } [Test] public void Should_BePossibleToUse_CustomFactory() { var browserFactory = new CustomLocalBrowserFactory(); - BrowserManager.BrowserFactory = browserFactory; - BrowserManager.Browser.GoTo(url); - Assert.AreEqual(url, BrowserManager.Browser.CurrentUrl); + AqualityServices.BrowserFactory = browserFactory; + AqualityServices.Browser.GoTo(url); + Assert.AreEqual(url, AqualityServices.Browser.CurrentUrl); } [TearDown] public void TearDown() { - BrowserManager.Browser.Quit(); - BrowserManager.SetDefaultFactory(); + AqualityServices.Browser.Quit(); + AqualityServices.SetDefaultFactory(); } public class CustomLocalBrowserFactory : BrowserFactory { private static readonly object WebDriverDownloadingLock = new object(); - public CustomLocalBrowserFactory() : base(BrowserManager.ServiceProvider) + public CustomLocalBrowserFactory() : base() { } @@ -56,11 +56,11 @@ public CustomLocalBrowserFactory() : base(BrowserManager.ServiceProvider) private Browser CreateBrowser() { - var browserProfile = ServiceProvider.GetRequiredService(); + var browserProfile = AqualityServices.Get(); var driverSettings = browserProfile.DriverSettings; SetUpDriver(new ChromeConfig(), driverSettings); var driver = new ChromeDriver((ChromeOptions)driverSettings.DriverOptions); - return new Browser(driver, ServiceProvider); + return new Browser(driver); } private static void SetUpDriver(IDriverConfig driverConfig, IDriverSettings driverSettings) diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/ElementExistsButNotDisplayedTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/ElementExistsButNotDisplayedTests.cs index 9ab266dd..625cba6e 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/ElementExistsButNotDisplayedTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/ElementExistsButNotDisplayedTests.cs @@ -1,6 +1,5 @@ using Aquality.Selenium.Browsers; using Aquality.Selenium.Core.Elements; -using Aquality.Selenium.Core.Waitings; using Aquality.Selenium.Elements.Interfaces; using Aquality.Selenium.Tests.Integration.TestApp; using Aquality.Selenium.Tests.Integration.TestApp.AutomationPractice.Forms; @@ -19,14 +18,14 @@ internal class ElementExistsButNotDisplayedTests : UITest [SetUp] public void BeforeTest() { - BrowserManager.Browser.GoTo(Constants.UrlAutomationPractice); + AqualityServices.Browser.GoTo(Constants.UrlAutomationPractice); } [Test] public void Should_BePossibleTo_WaitForElement_WhichExistsButNotDisplayed() { var button = new SliderForm().GetAddToCartBtn(ElementState.ExistsInAnyState); - Assert.IsTrue(BrowserManager.GetRequiredService().WaitFor(() => button.State.IsExist && !button.State.IsDisplayed)); + Assert.IsTrue(AqualityServices.ConditionalWait.WaitFor(() => button.State.IsExist && !button.State.IsDisplayed)); } [Test] @@ -38,14 +37,14 @@ public void Should_ThrowWebDriverTimeoutException_WhenElementNotInDesiredState() [Test] public void Should_ThrowNoSuchElementException_WhenElementNotFound_ButExpectedToBeDisplayed() { - var elementFactory = BrowserManager.GetRequiredService(); + var elementFactory = AqualityServices.Get(); Assert.Throws(() => elementFactory.GetButton(fakeElement, "Fake", ElementState.Displayed).GetElement(smallTimeout)); } [Test] public void Should_ThrowNoSuchElementException_WhenElementNotFound_ButExpectedToExist() { - var elementFactory = BrowserManager.GetRequiredService(); + var elementFactory = AqualityServices.Get(); Assert.Throws(() => elementFactory.GetButton(fakeElement, "Fake", ElementState.ExistsInAnyState).GetElement(smallTimeout)); } } diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/FileDownloadHelper.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/FileDownloadHelper.cs index 9728656a..3e3ae65d 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/FileDownloadHelper.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/FileDownloadHelper.cs @@ -13,19 +13,19 @@ public static bool IsFileDownloaded(string filePath, ILabel lblFileContent) { try { - BrowserManager.Browser.GoTo($"file://{filePath}"); + AqualityServices.Browser.GoTo($"file://{filePath}"); return lblFileContent.State.IsDisplayed; } catch (WebDriverException exception) { - BrowserManager.GetRequiredService().Warn(exception.Message); + AqualityServices.Get().Warn(exception.Message); return false; } } public static void CreateDownloadDirectoryIfNotExist() { - var browserProfile = BrowserManager.GetRequiredService(); + var browserProfile = AqualityServices.Get(); var downloadDir = browserProfile.DriverSettings.DownloadDir; if (!Directory.Exists(downloadDir) && !browserProfile.IsRemote) { @@ -36,7 +36,7 @@ public static void CreateDownloadDirectoryIfNotExist() public static void DeleteFileIfExist(string filePath) { var file = new FileInfo(filePath); - if (file.Exists && !BrowserManager.GetRequiredService().IsRemote) + if (file.Exists && !AqualityServices.Get().IsRemote) { file.Delete(); } @@ -44,7 +44,7 @@ public static void DeleteFileIfExist(string filePath) public static string GetTargetFilePath(string fileName) { - var downloadDirectory = BrowserManager.Browser.DownloadDirectory; + var downloadDirectory = AqualityServices.Browser.DownloadDirectory; // below is workaround for case when local FS is different from remote (e.g. local machine runs on Windows but remote runs on Linux) if (downloadDirectory.Contains("/") && !downloadDirectory.EndsWith("/")) diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/FileDownloadingTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/FileDownloadingTests.cs index cfb1dfb6..ceaf7d95 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/FileDownloadingTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/FileDownloadingTests.cs @@ -1,5 +1,4 @@ using Aquality.Selenium.Browsers; -using Aquality.Selenium.Core.Waitings; using Aquality.Selenium.Elements.Interfaces; using Aquality.Selenium.Tests.Integration.TestApp.TheInternet.Forms; using NUnit.Framework; @@ -14,7 +13,7 @@ internal class FileDownloadingTests : UITest [Test] public void Should_BePossibleTo_DownloadTextFile() { - var browser = BrowserManager.Browser; + var browser = AqualityServices.Browser; var downloaderForm = new FileDownloaderForm(); var fileName = downloaderForm.FileName; var filePath = FileDownloadHelper.GetTargetFilePath(fileName); @@ -22,11 +21,11 @@ public void Should_BePossibleTo_DownloadTextFile() FileDownloadHelper.CreateDownloadDirectoryIfNotExist(); FileDownloadHelper.DeleteFileIfExist(filePath); - var lblFileContent = BrowserManager.GetRequiredService().GetLabel(By.XPath("//pre"), "text file content"); + var lblFileContent = AqualityServices.Get().GetLabel(By.XPath("//pre"), "text file content"); Assert.False(FileDownloadHelper.IsFileDownloaded(filePath, lblFileContent), $"file {filePath} should not exist before downloading"); browser.ExecuteScriptFromFile("Resources.OpenUrlInNewWindow.js", downloaderForm.Url); - var tabs = new List(BrowserManager.Browser.Driver.WindowHandles); + var tabs = new List(AqualityServices.Browser.Driver.WindowHandles); browser.Driver.SwitchTo().Window(tabs[1]); downloaderForm.Open(); @@ -36,14 +35,14 @@ public void Should_BePossibleTo_DownloadTextFile() var message = $"file {filePath} was not downloaded"; try { - BrowserManager.GetRequiredService().WaitForTrue(condition, message: message); + AqualityServices.ConditionalWait.WaitForTrue(condition, message: message); } catch (TimeoutException) { if(browser.BrowserName == BrowserName.Safari) { browser.Quit(); - BrowserManager.GetRequiredService().WaitForTrue(condition, message: message); + AqualityServices.ConditionalWait.WaitForTrue(condition, message: message); } else { diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/ShoppingCartTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/ShoppingCartTests.cs index 30ee0060..c542d208 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/ShoppingCartTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/ShoppingCartTests.cs @@ -22,8 +22,8 @@ internal class ShoppingCartTests : UITest [SetUp] public void BeforeTest() { - BrowserManager.Browser.GoTo(Constants.UrlAutomationPractice); - BrowserManager.Browser.Maximize(); + AqualityServices.Browser.GoTo(Constants.UrlAutomationPractice); + AqualityServices.Browser.Maximize(); } [Test] diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/AqualityServicesTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/AqualityServicesTests.cs new file mode 100644 index 00000000..3fd46b5c --- /dev/null +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/AqualityServicesTests.cs @@ -0,0 +1,85 @@ +using Aquality.Selenium.Browsers; +using Aquality.Selenium.Configurations; +using NUnit.Framework; +using System; + +namespace Aquality.Selenium.Tests.Unit +{ + [TestFixture] + [Parallelizable(ParallelScope.All)] + internal class AqualityServicesTests + { + [Test] + public void Should_BeAbleGetBrowser() + { + Assert.DoesNotThrow(() => AqualityServices.Browser.WaitForPageToLoad()); + } + + [Test] + public void Should_BeAbleCheck_IsBrowserNotStarted() + { + Assert.IsFalse(AqualityServices.IsBrowserStarted, "Browser is not started"); + } + + [Test] + public void Should_BeAbleCheck_IsBrowserStarted() + { + AqualityServices.Browser.WaitForPageToLoad(); + Assert.IsTrue(AqualityServices.IsBrowserStarted, "Browser is started"); + } + + [Test] + public void Should_BeAbleToGet_Logger() + { + Assert.DoesNotThrow(() => AqualityServices.Logger.Info("message"), "Logger should not be null"); + } + + [Test] + public void Should_BeAbleToGet_ConditionalWait() + { + Assert.DoesNotThrow(() => AqualityServices.ConditionalWait.WaitForTrue(() => true), "ConditionalWait should not be null"); + } + + [Test] + public void Should_BeAbleToGet_LocalizedLogger() + { + Assert.DoesNotThrow(() => AqualityServices.LocalizedLogger.Info("test"), "LocalizedLogger should not be null"); + } + + [Test] + public void Should_BeAbleToGet_ServiceProvider() + { + Assert.DoesNotThrow(() => AqualityServices.Get(), "ServiceProvider should not be null"); + } + + [TestCase(null)] + [TestCase("--headless, --disable-infobars")] + [TestCase("a")] + public void Should_BeAbleGetBrowser_WithStartArguments(string startArguments) + { + var currentBrowser = AqualityServices.Get().BrowserName; + Environment.SetEnvironmentVariable("isRemote", "false"); + Environment.SetEnvironmentVariable($"driverSettings.{currentBrowser.ToString().ToLowerInvariant()}.startArguments", startArguments); + Assert.DoesNotThrow(() => AqualityServices.Browser.WaitForPageToLoad()); + } + + [Ignore("Not all browsers are supported in Azure CICD pipeline")] + [TestCase(BrowserName.IExplorer)] + [TestCase(BrowserName.Firefox)] + [TestCase(BrowserName.Chrome)] + [TestCase(BrowserName.Edge)] + public void Should_BeAbleToCreateLocalBrowser(BrowserName browserName) + { + Environment.SetEnvironmentVariable("browserName", browserName.ToString()); + Environment.SetEnvironmentVariable("isRemote", "false"); + Assert.DoesNotThrow(() => AqualityServices.Browser.WaitForPageToLoad()); + Assert.AreEqual(AqualityServices.Browser.BrowserName, browserName); + } + + [TearDown] + public void CleanUp() + { + AqualityServices.Browser.Quit(); + } + } +} diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/BrowserManagerTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/BrowserManagerTests.cs deleted file mode 100644 index 79dabb52..00000000 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/BrowserManagerTests.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Aquality.Selenium.Browsers; -using Aquality.Selenium.Configurations; -using NUnit.Framework; -using System; - -namespace Aquality.Selenium.Tests.Unit -{ - [TestFixture] - [Parallelizable(ParallelScope.All)] - internal class BrowserManagerTests - { - [Test] - public void Should_BeAbleGetBrowser() - { - Assert.DoesNotThrow(() => BrowserManager.Browser.WaitForPageToLoad()); - } - - [TestCase(null)] - [TestCase("--headless, --disable-infobars")] - [TestCase("a")] - public void Should_BeAbleGetBrowser_WithStartArguments(string startArguments) - { - var currentBrowser = BrowserManager.GetRequiredService().BrowserName; - Environment.SetEnvironmentVariable("isRemote", "false"); - Environment.SetEnvironmentVariable($"driverSettings.{currentBrowser.ToString().ToLowerInvariant()}.startArguments", startArguments); - Assert.DoesNotThrow(() => BrowserManager.Browser.WaitForPageToLoad()); - } - - [Ignore("Not all browsers are supported in Azure CICD pipeline")] - [TestCase(BrowserName.IExplorer)] - [TestCase(BrowserName.Firefox)] - [TestCase(BrowserName.Chrome)] - [TestCase(BrowserName.Edge)] - public void Should_BeAbleToCreateLocalBrowser(BrowserName browserName) - { - Environment.SetEnvironmentVariable("browserName", browserName.ToString()); - Environment.SetEnvironmentVariable("isRemote", "false"); - Assert.DoesNotThrow(() => BrowserManager.Browser.WaitForPageToLoad()); - Assert.AreEqual(BrowserManager.Browser.BrowserName, browserName); - } - - [TearDown] - public void CleanUp() - { - BrowserManager.Browser.Quit(); - } - } -} diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/Configuration/CustomConfigurationTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/Configuration/CustomConfigurationTests.cs index 6272f361..c09c732d 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/Configuration/CustomConfigurationTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/Configuration/CustomConfigurationTests.cs @@ -18,31 +18,31 @@ internal class CustomConfigurationTests [SetUp] public static void Before() { - BrowserManager.SetStartup(new CustomStartup()); + AqualityServices.SetStartup(new CustomStartup()); } [Test] public void Should_BeAbleOverrideDependencies_AndGetCustomService() { - Assert.AreEqual(SpecialLoggerLanguage, BrowserManager.GetRequiredService().Language, "Configuration value should be overriden."); + Assert.AreEqual(SpecialLoggerLanguage, AqualityServices.Get().Language, "Configuration value should be overriden."); } [Test] public void Should_BeAbleAdd_CustomService() { - Assert.AreEqual(SpecialCustomValue, BrowserManager.GetRequiredService().CustomValue, "Custom service should have value"); + Assert.AreEqual(SpecialCustomValue, AqualityServices.Get().CustomValue, "Custom service should have value"); } [Test] public void Should_BeAbleGet_DefaultService() { - Assert.AreEqual(DefaultCommandTimeout, BrowserManager.GetRequiredService().Command, "Default service value should have default value"); + Assert.AreEqual(DefaultCommandTimeout, AqualityServices.Get().Command, "Default service value should have default value"); } [TearDown] public static void After() { - BrowserManager.SetStartup(new BrowserStartup()); + AqualityServices.SetStartup(new BrowserStartup()); } private class CustomLoggerConfiguration : ILoggerConfiguration diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/LocalizationManagerTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/LocalizationManagerTests.cs index d761de90..d19dcde8 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/LocalizationManagerTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/LocalizationManagerTests.cs @@ -15,15 +15,15 @@ internal class LocalizationManagerTests private const string LogPath = "../../../Log/log.log"; private const string TestUrl = "test"; private const string NavigationKey = "loc.browser.navigate"; - private static ILocalizedLogger LocalizedLogger => BrowserManager.GetRequiredService(); - private static ILocalizationManager LocalizationManager => BrowserManager.GetRequiredService(); + private static ILocalizedLogger LocalizedLogger => AqualityServices.LocalizedLogger; + private static ILocalizationManager LocalizationManager => AqualityServices.Get(); + [Parallelizable(ParallelScope.None)] [TestCase(LogLevel.Info)] [TestCase(LogLevel.Debug)] [TestCase(LogLevel.Error)] [TestCase(LogLevel.Fatal)] [TestCase(LogLevel.Warn)] - [Parallelizable(ParallelScope.None)] public void Should_BeAble_LogLocalizedMessage(LogLevel logLevel) { switch (logLevel)