Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ity-selenium-dotnet into #262-add-drivercontext
  • Loading branch information
dmitry.bogatko committed Sep 17, 2024
2 parents 2717222 + f9669bb commit 1af433f
Show file tree
Hide file tree
Showing 31 changed files with 366 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aquality.Selenium.Core" Version="3.0.10" />
<PackageReference Include="Aquality.Selenium.Core" Version="3.1.1" />
<PackageReference Include="OpenCvSharp4.runtime.osx_arm64" Version="4.8.1-rc" />
<PackageReference Include="WebDriverManager" Version="2.17.4" />
<PackageReference Include="OpenCvSharp4" Version="4.10.0.20240616" />
Expand Down
83 changes: 76 additions & 7 deletions Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.xml

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

25 changes: 25 additions & 0 deletions Aquality.Selenium/src/Aquality.Selenium/Browsers/Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using System.Collections.ObjectModel;

using IDevTools = OpenQA.Selenium.DevTools.IDevTools;
using OpenQA.Selenium.Interactions;
using static OpenQA.Selenium.Interactions.WheelInputDevice;

namespace Aquality.Selenium.Browsers
{
Expand Down Expand Up @@ -322,9 +324,32 @@ public ReadOnlyCollection<LogEntry> GetLogs(string logKind)
/// <param name="y">Vertical coordinate.</param>
public void ScrollWindowBy(int x, int y)
{
Logger.Info("loc.scrolling.by", x, y);
new Actions(Driver).ScrollByAmount(x, y).Perform();
}

/// <summary>
/// Scrolls window by coordinates using JavaScript.
/// </summary>
/// <param name="x">Horizontal coordinate.</param>
/// <param name="y">Vertical coordinate.</param>
public void ScrollWindowByViaJs(int x, int y)
{
Logger.Info("loc.scrolling.by.js", x, y);
ExecuteScript(JavaScript.ScrollWindowBy, x, y);
}

/// <summary>
/// Scrolls portion of screen from specified origin
/// </summary>
/// <param name="scrollOrigin">Origination point (either viewport or element, with possible offset).</param>
/// <param name="x">Horizontal coordinate.</param>
/// <param name="y">Vertical coordinate.</param>
public void ScrollFromOrigin(ScrollOrigin scrollOrigin, int x, int y)
{
new Actions(Driver).ScrollFromOrigin(scrollOrigin, x, y).Perform();
}

/// <summary>
/// Executes JS script from embedded resource file (*.js).
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Aquality.Selenium.Core.Localization;
using OpenQA.Selenium;
using System;
using System.Threading.Tasks;

namespace Aquality.Selenium.Browsers
{
Expand Down Expand Up @@ -28,6 +29,16 @@ public void Back()
driver.Navigate().Back();
}

/// <summary>
/// Move back a single entry in the browser's history as an asynchronous task.
/// </summary>
/// <returns>A task object representing the asynchronous operation.</returns>
public Task BackAsync()
{
Logger.Info("loc.browser.back");
return driver.Navigate().BackAsync();
}

/// <summary>
/// Navigates forward.
/// </summary>
Expand All @@ -37,6 +48,16 @@ public void Forward()
driver.Navigate().Forward();
}

/// <summary>
/// Move a single "item" forward in the browser's history as an asynchronous task.
/// </summary>
/// <returns>A task object representing the asynchronous operation.</returns>
public Task ForwardAsync()
{
Logger.Info("loc.browser.forward");
return driver.Navigate().ForwardAsync();
}

/// <summary>
/// Navigates to desired url.
/// </summary>
Expand Down Expand Up @@ -77,6 +98,28 @@ public void GoToUrl(Uri url)
}
}

/// <summary>
/// Navigate to a url as an asynchronous task.
/// </summary>
/// <param name="url">String representation of where you want the browser to go.</param>
/// <returns>A task object representing the asynchronous operation.</returns>
public Task GoToUrlAsync(string url)
{
InfoLocNavigate(url);
return driver.Navigate().GoToUrlAsync(url);
}

/// <summary>
/// Navigate to a url as an asynchronous task.
/// </summary>
/// <param name="url">Uri object of where you want the browser to go.</param>
/// <returns>A task object representing the asynchronous operation.</returns>
public Task GoToUrlAsync(Uri url)
{
InfoLocNavigate(url.ToString());
return driver.Navigate().GoToUrlAsync(url);
}

/// <summary>
/// Refreshes current page.
/// </summary>
Expand All @@ -86,6 +129,16 @@ public void Refresh()
driver.Navigate().Refresh();
}

/// <summary>
/// Reload the current page as an asynchronous task.
/// </summary>
/// <returns>A task object representing the asynchronous operation.</returns>
public Task RefreshAsync()
{
Logger.Info("loc.browser.refresh");
return driver.Navigate().RefreshAsync();
}

private void InfoLocNavigate(string url)
{
Logger.Info("loc.browser.navigate", url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Aquality.Selenium.Browsers
{
Expand Down
Loading

0 comments on commit 1af433f

Please sign in to comment.