Skip to content

Commit

Permalink
Implement native scroll actions +semver: feature (#258)
Browse files Browse the repository at this point in the history
- cover with tests
- add localization values for scrolling actions
  • Loading branch information
mialeska authored Jul 22, 2024
1 parent a69263a commit 77f9255
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 6 deletions.
32 changes: 32 additions & 0 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 @@ -319,9 +321,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
Expand Up @@ -93,7 +93,7 @@ public void ScrollIntoView()
/// <param name="y">Vertical coordinate</param>
public void ScrollBy(int x, int y)
{
LogElementAction("loc.scrolling.js");
LogElementAction("loc.scrolling.by.js", x, y);
ExecuteScript(JavaScript.ScrollBy, x, y);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Aquality.Selenium.Core.Utilities;
using Aquality.Selenium.Core.Localization;
using Aquality.Selenium.Configurations;
using static OpenQA.Selenium.Interactions.WheelInputDevice;

namespace Aquality.Selenium.Elements.Actions
{
Expand Down Expand Up @@ -57,6 +58,39 @@ public void RightClick()
elementActionsRetrier.DoWithRetry(() => PerformAction(element => MoveToElement(element).ContextClick(element)));
}

/// <summary>
/// Scrolling page to the element.
/// </summary>
public void ScrollToElement()
{
LogElementAction("loc.scrolling");
elementActionsRetrier.DoWithRetry(() => PerformAction(element => new SeleniumActions(AqualityServices.Browser.Driver).ScrollToElement(element)));
}

/// <summary>
/// Scrolling page from an element.
/// </summary>
public void ScrollFromOrigin(int x, int y, int? xOffset = null, int? yOffset = null)
{
LogElementAction("loc.scrolling.by", x, y);
elementActionsRetrier.DoWithRetry(() =>
{
var scrollOrigin = new ScrollOrigin
{
Element = element.GetElement()
};
if (xOffset != null)
{
scrollOrigin.XOffset = xOffset.Value;
}
if (yOffset != null)
{
scrollOrigin.YOffset = yOffset.Value;
}
AqualityServices.Browser.ScrollFromOrigin(scrollOrigin, x, y);
});
}

/// <summary>
/// Moves mouse to the element.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions Aquality.Selenium/src/Aquality.Selenium/Forms/Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ protected Form(By locator, string name)
/// <param name="x">horizontal coordinate</param>
/// <param name="y">vertical coordinate</param>
public void ScrollBy(int x, int y)
{
FormElement.MouseActions.ScrollFromOrigin(x, y);
}

/// <summary>
/// Scroll form via JavaScript without scrolling entire page
/// </summary>
/// <param name="x">horizontal coordinate</param>
/// <param name="y">vertical coordinate</param>
public void ScrollByJs(int x, int y)
{
FormElement.JsActions.ScrollBy(x, y);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
"loc.movingFrom": "Адводзім курсор мышы ад элемента",
"loc.radio": "Радыёкнопка",
"loc.scrolling.center.js": "Пракручваем старонку да цэнтра элемента праз JavaScript",
"loc.scrolling.js": "Пракручваем старонку праз JavaScript",
"loc.scrolling.js": "Пракручваем старонку да элемента праз JavaScript",
"loc.scrolling": "Пракручваем старонку да элемента",
"loc.scrolling.by": "Пракручваем на ({0},{1})",
"loc.scrolling.by.js": "Пракручваем на ({0},{1}) праз JavaScript",
"loc.selecting.value": "Выбіраем значэнне - '{0}'",
"loc.deselecting.value": "Адмяняем выбар значэння - '{0}'",
"loc.send.text": "Задаем тэкст - '{0}'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
"loc.movingFrom": "Moving mouse from element",
"loc.radio": "RadioButton",
"loc.scrolling.center.js": "Scrolling to the center via JavaScript",
"loc.scrolling.js": "Scrolling via JavaScript",
"loc.scrolling.js": "Scrolling to element via JavaScript",
"loc.scrolling": "Scrolling to element",
"loc.scrolling.by": "Scrolling by ({0},{1})",
"loc.scrolling.by.js": "Scrolling by ({0},{1}) via JavaScript",
"loc.selecting.value": "Selecting value - '{0}'",
"loc.deselecting.value": "Deselecting value - '{0}'",
"loc.send.text": "Setting text - '{0}'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
"loc.movingFrom": "Przesuwanie myszy z elementu",
"loc.radio": "RadioButton",
"loc.scrolling.center.js": "Przewijanie do centrum przez JavaScript",
"loc.scrolling.js": "Przewijanie przez JavaScript",
"loc.scrolling.js": "Przewijanie do elementu przez JavaScript",
"loc.scrolling": "Przewijanie do elementu",
"loc.scrolling.by": "Przewijanie o ({0},{1})",
"loc.scrolling.by.js": "Przewijanie o ({0},{1}) przez JavaScript",
"loc.selecting.value": "Wybieranie wartości - '{0}'",
"loc.deselecting.value": "Anulowanie wybierania wartości - '{0}'",
"loc.send.text": "Ustawianie tekstu - '{0}'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
"loc.movingFrom": "Сдвиг курсора с элемента",
"loc.radio": "Радиокнопка",
"loc.scrolling.center.js": "Скроллинг в центр посредством JavaScript",
"loc.scrolling.js": "Скроллинг с помощью JavaScript",
"loc.scrolling.js": "Скроллинг к элементу с помощью JavaScript",
"loc.scrolling": "Скроллинг к элементу",
"loc.scrolling.by": "Скроллинг на ({0},{1})",
"loc.scrolling.by.js": "Скроллинг на ({0},{1}) с помощью JavaScript",
"loc.selecting.value": "Выбор значения - '{0}'",
"loc.deselecting.value": "Отмена выбора значения - '{0}'",
"loc.send.text": "Ввод текста - '{0}'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
"loc.movingFrom": "Переміщення миші від елемента",
"loc.radio": "Радіокнопка",
"loc.scrolling.center.js": "Прокрутка до центру за допомогою JavaScript",
"loc.scrolling.js": "Прокрутка за допомогою JavaScript",
"loc.scrolling.js": "Прокрутка до елемента за допомогою JavaScript",
"loc.scrolling": "Прокрутка до елемента",
"loc.scrolling.by": "Прокрутка на ({0},{1})",
"loc.scrolling.by.js": "Прокрутка на ({0},{1}) за допомогою JavaScript",
"loc.selecting.value": "Вибір значення - '{0}'",
"loc.deselecting.value": "Скасування выбору значення - '{0}'",
"loc.send.text": "Встановлення тексту - '{0}'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,38 @@ public void Should_BePossibleTo_MoveToElement()
JQueryMenuForm.EnabledButton.MouseActions.MoveToElement();
Assert.That(JQueryMenuForm.IsEnabledButtonFocused, "Element should be focused after move mouse");
}

[Test]
public void Should_BePossibleTo_ScrollToElement()
{
var infiniteScrollForm = new InfiniteScrollForm();
infiniteScrollForm.Open();
infiniteScrollForm.WaitForPageToLoad();
var size = infiniteScrollForm.LastExampleLabel.Visual.Size;
AqualityServices.Browser.SetWindowSize(size.Width, size.Height);
var defaultCount = infiniteScrollForm.ExampleLabels.Count;
Assert.DoesNotThrow(
() => AqualityServices.ConditionalWait.WaitForTrue(() =>
{
infiniteScrollForm.LastExampleLabel.MouseActions.ScrollToElement();
return infiniteScrollForm.ExampleLabels.Count > defaultCount;
}), "Some examples should be added after scroll");
}

[Test]
public void Should_BePossibleTo_ScrollFromOrigin()
{
var infiniteScrollForm = new InfiniteScrollForm();
infiniteScrollForm.Open();
infiniteScrollForm.WaitForPageToLoad();
var defaultCount = infiniteScrollForm.ExampleLabels.Count;
Assert.DoesNotThrow(
() => AqualityServices.ConditionalWait.WaitForTrue(() =>
{
var formHeight = infiniteScrollForm.Size.Height;
infiniteScrollForm.LastExampleLabel.MouseActions.ScrollFromOrigin(0, formHeight);
return infiniteScrollForm.ExampleLabels.Count > defaultCount;
}), "Some examples should be added after scroll");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,22 @@ public void Should_BePossibleTo_ScrollWindowBy()
}), "Some examples should be added after scroll");
}

[Test]
public void Should_BePossibleTo_ScrollWindowBy_ViaJs()
{
var infiniteScrollForm = new InfiniteScrollForm();
infiniteScrollForm.Open();
infiniteScrollForm.WaitForPageToLoad();
var defaultCount = infiniteScrollForm.ExampleLabels.Count;
Assert.DoesNotThrow(
() => AqualityServices.ConditionalWait.WaitForTrue(() =>
{
var formHeight = infiniteScrollForm.Size.Height;
AqualityServices.Browser.ScrollWindowByViaJs(0, formHeight);
return infiniteScrollForm.ExampleLabels.Count > defaultCount;
}), "Some examples should be added after scroll");
}

[Test]
public void Should_BePossibleTo_GetBrowserName()
{
Expand Down

0 comments on commit 77f9255

Please sign in to comment.