Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Element Send Keys according to spec #33

Merged
merged 21 commits into from
May 8, 2024
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,14 @@ There is an interpretation to use the WebDriver specification to drive native au
| tag name | Control type in Windows |
| attribute | [UI automation element property](https://learn.microsoft.com/en-us/windows/win32/winauto/uiauto-automation-element-propids) in Windows |

### Deviations from W3C WebDriver Spec

https://www.w3.org/TR/webdriver2/#element-send-keys says:

> Set the text insertion caret using set selection range using current text length for both the start and end parameters.

This is impossible using UIA, as there is no API to set the caret position: text instead gets inserted at the beginning of a text box. This is also WinAppDriver's behavior.

### Element Attributes

Attributes are mapped to UI automation element properties. Attributes without a period (`.`) are mapped to [Automation Element Properties](https://learn.microsoft.com/en-us/windows/win32/winauto/uiauto-automation-element-propids). For example to read the `UIA_ClassNamePropertyId` using Selenium WebDriver:
Expand Down
50 changes: 47 additions & 3 deletions src/FlaUI.WebDriver.UITests/ElementTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using FlaUI.WebDriver.UITests.TestUtil;
using System.Threading;
using FlaUI.WebDriver.UITests.TestUtil;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Remote;
using System;

namespace FlaUI.WebDriver.UITests
{
Expand Down Expand Up @@ -134,7 +134,51 @@ public void SendKeys_Default_IsSupported()

element.SendKeys("Hello World!");

Assert.That(element.Text, Is.EqualTo("Hello World!"));
Assert.That(element.Text, Is.EqualTo("Hello World!Test TextBox"));
}

[Test]
public void SendKeys_ShiftedCharacter_ShiftIsReleased()
{
var driverOptions = FlaUIDriverOptions.TestApp();
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
var element = driver.FindElement(ExtendedBy.AccessibilityId("TextBox"));

element.SendKeys("!");
element.SendKeys("1");

Assert.That(element.Text, Is.EqualTo("!1Test TextBox"));
}

[Test]
public void SendKeys_DownArrow_IsSupported()
{
var driverOptions = FlaUIDriverOptions.TestApp();
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
var element = driver.FindElement(ExtendedBy.AccessibilityId("NonEditableCombo"));

element.SendKeys(Keys.Down);

Assert.That(element.Text, Is.EqualTo("Item 2"));
}

[Test, Ignore("Alt key combinations currently fail due to https://github.com/FlaUI/FlaUI/issues/320")]
public void SendKeys_AltDownArrowEscape_IsSupported()
{
var driverOptions = FlaUIDriverOptions.TestApp();
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
var element = driver.FindElement(ExtendedBy.AccessibilityId("NonEditableCombo"));
var expandCollapseState = element.GetDomAttribute("ExpandCollapse.ExpandCollapseState");

Assert.That(expandCollapseState, Is.EqualTo("Collapsed"));

element.SendKeys(Keys.Alt + Keys.Down);

Assert.That(expandCollapseState, Is.EqualTo("Expanded"));

element.SendKeys(Keys.Escape);

Assert.That(expandCollapseState, Is.EqualTo("Collapsed"));
}

[Test]
Expand Down
3 changes: 3 additions & 0 deletions src/FlaUI.WebDriver/Action.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class Action
{
public Action(ActionSequence actionSequence, ActionItem actionItem)
{
Id = actionSequence.Id;
Type = actionSequence.Type;
SubType = actionItem.Type;
Button = actionItem.Button;
Expand All @@ -29,6 +30,7 @@ public Action(ActionSequence actionSequence, ActionItem actionItem)

public Action(Action action)
{
Id = action.Id;
Type = action.Type;
SubType = action.SubType;
Button = action.Button;
Expand All @@ -50,6 +52,7 @@ public Action(Action action)
Value = action.Value;
}

public string Id { get; set; }
public string Type { get; set; }
public string SubType { get; set; }
public int? Button { get; set; }
Expand Down
Loading
Loading