diff --git a/Behavioral.Automation.DemoBindings/Behavioral.Automation.DemoBindings.csproj b/Behavioral.Automation.DemoBindings/Behavioral.Automation.DemoBindings.csproj index 50ad947d..de05ae0b 100644 --- a/Behavioral.Automation.DemoBindings/Behavioral.Automation.DemoBindings.csproj +++ b/Behavioral.Automation.DemoBindings/Behavioral.Automation.DemoBindings.csproj @@ -9,9 +9,9 @@ - - - + + + diff --git a/Behavioral.Automation.DemoScenarios/Behavioral.Automation.DemoScenarios.csproj b/Behavioral.Automation.DemoScenarios/Behavioral.Automation.DemoScenarios.csproj index acf72b0e..a5480234 100644 --- a/Behavioral.Automation.DemoScenarios/Behavioral.Automation.DemoScenarios.csproj +++ b/Behavioral.Automation.DemoScenarios/Behavioral.Automation.DemoScenarios.csproj @@ -9,11 +9,11 @@ - - - - - + + + + + diff --git a/src/Behavioral.Automation.UnitTests/Behavioral.Automation.UnitTests.csproj b/src/Behavioral.Automation.UnitTests/Behavioral.Automation.UnitTests.csproj index 0f970749..2569eb12 100644 --- a/src/Behavioral.Automation.UnitTests/Behavioral.Automation.UnitTests.csproj +++ b/src/Behavioral.Automation.UnitTests/Behavioral.Automation.UnitTests.csproj @@ -7,10 +7,10 @@ - - - - + + + + diff --git a/src/Behavioral.Automation/Behavioral.Automation.csproj b/src/Behavioral.Automation/Behavioral.Automation.csproj index b5be82ef..e4ff3f22 100644 --- a/src/Behavioral.Automation/Behavioral.Automation.csproj +++ b/src/Behavioral.Automation/Behavioral.Automation.csproj @@ -22,16 +22,16 @@ The whole automation code is divided into the following parts: - - - - - - - - - - + + + + + + + + + + diff --git a/src/Behavioral.Automation/Bindings/ListBinding.cs b/src/Behavioral.Automation/Bindings/ListBinding.cs index f8b24502..7c1e209f 100644 --- a/src/Behavioral.Automation/Bindings/ListBinding.cs +++ b/src/Behavioral.Automation/Bindings/ListBinding.cs @@ -11,13 +11,6 @@ namespace Behavioral.Automation.Bindings [Binding] public class ListBinding { - private readonly IDriverService _driverService; - - public ListBinding([NotNull] IDriverService driverService) - { - _driverService = driverService; - } - [Given("(.+?) (has|does not have) the following items:")] [Then("(.+?) should (have|not have) the following items:")] public void CheckListHaveItems(IListWrapper list, string behavior, Table table) diff --git a/src/Behavioral.Automation/FluentAssertions/Assert.cs b/src/Behavioral.Automation/FluentAssertions/Assert.cs index ae03ca81..5aaec4c2 100644 --- a/src/Behavioral.Automation/FluentAssertions/Assert.cs +++ b/src/Behavioral.Automation/FluentAssertions/Assert.cs @@ -89,7 +89,7 @@ public static void True(bool condition, string message) if (!condition) { TestContext.WriteLine($"\nActual:\n{message}"); - NUnit.Framework.Assert.Fail(); + NUnit.Framework.Assert.Fail($"Test execution failed: \n{message}"); } } diff --git a/src/Behavioral.Automation/Services/BrowserRunner.cs b/src/Behavioral.Automation/Services/BrowserRunner.cs index 792812fb..30f22fec 100644 --- a/src/Behavioral.Automation/Services/BrowserRunner.cs +++ b/src/Behavioral.Automation/Services/BrowserRunner.cs @@ -1,16 +1,18 @@ using System; using System.Collections.Generic; using JetBrains.Annotations; +using OpenQA.Selenium; using OpenQA.Selenium.Chrome; +using OpenQA.Selenium.Chromium; using OpenQA.Selenium.Remote; namespace Behavioral.Automation.Services { public class BrowserRunner { - public RemoteWebDriver Driver; - - public void OpenBrowser([NotNull] RemoteWebDriver driver) + public IWebDriver Driver; + + public void OpenBrowser([NotNull] IWebDriver driver) { Driver = driver; } @@ -51,7 +53,7 @@ public void OpenChrome(ChromeOptions options = null) {"behavior", "allow"}, {"downloadPath", downloadPath} }; - driver.ExecuteChromeCommand("Page.setDownloadBehavior", param); + driver.ExecuteCdpCommand("Page.setDownloadBehavior", param); OpenBrowser(driver); } diff --git a/src/Behavioral.Automation/Services/DriverService.cs b/src/Behavioral.Automation/Services/DriverService.cs index 4eb27d94..32564c2d 100644 --- a/src/Behavioral.Automation/Services/DriverService.cs +++ b/src/Behavioral.Automation/Services/DriverService.cs @@ -26,7 +26,7 @@ public DriverService([NotNull] IScopeContextManager scopeContextManager, Browser _browserRunner = browserRunner; } - public RemoteWebDriver Driver => _browserRunner.Driver; + public IWebDriver Driver => _browserRunner.Driver; private readonly string SearchAttribute = ConfigServiceBase.SearchAttribute; @@ -80,13 +80,19 @@ public ReadOnlyCollection FindElementsByXpath(string path) return Driver.FindElements(By.XPath(path)); } + public object ExecuteScript(string script, params object[] args) + { + IJavaScriptExecutor js = (IJavaScriptExecutor)Driver; + return js.ExecuteScript(script, args); + } + public void ScrollTo(IWebElement element) { var scrollElementIntoMiddle = "var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);" + "var elementTop = arguments[0].getBoundingClientRect().top;" + "window.scrollBy(0, elementTop-(viewPortHeight/2));"; - Driver.ExecuteScript(scrollElementIntoMiddle, element); + ExecuteScript(scrollElementIntoMiddle, element); Actions actions = new Actions(Driver); actions.MoveToElement(element); actions.Perform(); @@ -130,8 +136,8 @@ private Uri GetUriFromRelativePath(string url) } public void RemoveFocusFromActiveElement() - { - Driver.ExecuteScript("document.activeElement.blur()"); + { + ExecuteScript("document.activeElement.blur()"); } public void DebugDumpPage() @@ -165,13 +171,14 @@ public void ResizeWindow(int Height, int Width) public string MakeScreenShot() { var fileName = Regex.Replace(TestContext.CurrentContext.Test.Name, @"(\\|\"")", string.Empty) + ".png"; - Driver.GetScreenshot().SaveAsFile(fileName, ScreenshotImageFormat.Png); + Screenshot screenshot = ((ITakesScreenshot)Driver).GetScreenshot(); + screenshot.SaveAsFile(fileName, ScreenshotImageFormat.Png); return fileName; } public void ScrollElementTo(IWebElement element, int offset) { - Driver.ExecuteScript(@" + ExecuteScript(@" var element = arguments[0]; var offset = arguments[1]; element.scrollTo({top: offset, behavior: 'smooth'});", element, offset); diff --git a/src/Behavioral.Automation/Services/IDriverService.cs b/src/Behavioral.Automation/Services/IDriverService.cs index b280374d..9ef2b21c 100644 --- a/src/Behavioral.Automation/Services/IDriverService.cs +++ b/src/Behavioral.Automation/Services/IDriverService.cs @@ -7,7 +7,7 @@ namespace Behavioral.Automation.Services { public interface IDriverService { - RemoteWebDriver Driver { get; } + IWebDriver Driver { get; } string CurrentUrl { [NotNull] get; } @@ -26,6 +26,8 @@ public interface IDriverService ReadOnlyCollection FindElementsByXpath([NotNull] string path); + object ExecuteScript(string script, params object[] args); + public void Refresh(); void Navigate([NotNull] string url);