Skip to content
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 @@ -9,9 +9,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Selenium.Support" Version="3.141.0" />
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
<PackageReference Include="SpecFlow" Version="3.7.13" />
<PackageReference Include="Selenium.Support" Version="4.1.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.1.0" />
<PackageReference Include="SpecFlow" Version="3.9.40" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="SpecFlow" Version="3.7.13" />
<PackageReference Include="SpecFlow.NUnit" Version="3.7.13" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.7.13" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="SpecFlow" Version="3.9.40" />
<PackageReference Include="SpecFlow.NUnit" Version="3.9.40" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.9.40" />
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Moq" Version="4.14.5" />
<PackageReference Include="nunit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="nunit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
20 changes: 10 additions & 10 deletions src/Behavioral.Automation/Behavioral.Automation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ The whole automation code is divided into the following parts:
<ItemGroup>
<PackageReference Include="ExcelDataReader" Version="3.6.0" />
<PackageReference Include="ExcelDataReader.DataSet" Version="3.6.0" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="JetBrains.Annotations" Version="2020.3.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="NUnit" Version="3.13.1" />
<PackageReference Include="Selenium.Support" Version="3.141.0" />
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
<PackageReference Include="SpecFlow" Version="3.7.13" />
<PackageReference Include="FluentAssertions" Version="6.2.0" />
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="Selenium.Support" Version="4.1.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.1.0" />
<PackageReference Include="SpecFlow" Version="3.9.40" />
</ItemGroup>

</Project>
7 changes: 0 additions & 7 deletions src/Behavioral.Automation/Bindings/ListBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Behavioral.Automation/FluentAssertions/Assert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/Behavioral.Automation/Services/BrowserRunner.cs
Original file line number Diff line number Diff line change
@@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why renamed? We can use not only ChromiumDriver.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, we can use an interface here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to IWebDriver since RemoteWebDriver cannot be cast into ChromeDriver

public void OpenBrowser([NotNull] RemoteWebDriver driver)
public IWebDriver Driver;

public void OpenBrowser([NotNull] IWebDriver driver)
{
Driver = driver;
}
Expand Down Expand Up @@ -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);
}

Expand Down
19 changes: 13 additions & 6 deletions src/Behavioral.Automation/Services/DriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -80,13 +80,19 @@ public ReadOnlyCollection<IWebElement> 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();
Expand Down Expand Up @@ -130,8 +136,8 @@ private Uri GetUriFromRelativePath(string url)
}

public void RemoveFocusFromActiveElement()
{
Driver.ExecuteScript("document.activeElement.blur()");
{
ExecuteScript("document.activeElement.blur()");
}

public void DebugDumpPage()
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/Behavioral.Automation/Services/IDriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Behavioral.Automation.Services
{
public interface IDriverService
{
RemoteWebDriver Driver { get; }
IWebDriver Driver { get; }

string CurrentUrl { [NotNull] get; }

Expand All @@ -26,6 +26,8 @@ public interface IDriverService

ReadOnlyCollection<IWebElement> FindElementsByXpath([NotNull] string path);

object ExecuteScript(string script, params object[] args);

public void Refresh();

void Navigate([NotNull] string url);
Expand Down